storage.js: Add method on to StorageAwareSet

This commit is contained in:
Johannes Meyer 2019-07-03 15:56:08 +02:00
parent ffec2ebd4c
commit 3b7a1a5ab4
2 changed files with 24 additions and 3 deletions

View File

@ -22,12 +22,12 @@
this.defaultVisibleRows = 2; this.defaultVisibleRows = 2;
this.defaultVisibleHeight = 36; this.defaultVisibleHeight = 36;
$(window).on('StorageAwareSetAdd', { self: this }, this.onExternalExpansion);
$(window).on('StorageAwareSetDelete', { self: this }, this.onExternalCollapse);
this.state = new Icinga.Storage.StorageAwareSet.withStorage( this.state = new Icinga.Storage.StorageAwareSet.withStorage(
new Icinga.BehaviorStorage('collapsible'), new Icinga.BehaviorStorage('collapsible'),
'expanded' 'expanded'
); )
.on('add', { self: this }, this.onExternalExpansion)
.on('delete', { self: this }, this.onExternalCollapse);
}; };
Collapsible.prototype = new Icinga.EventListener(); Collapsible.prototype = new Icinga.EventListener();

View File

@ -250,6 +250,27 @@
}, this); }, this);
}, },
/**
* Register an event handler to handle storage updates
*
* Available events are: add, delete
*
* @param {string} event
* @param {object} data
* @param {function} handler
*
* @returns {this}
*/
on: function(event, data, handler) {
$(window).on(
'StorageAwareSet' + event.charAt(0).toUpperCase() + event.slice(1),
data,
handler
);
return this;
},
/** /**
* Return the number of (unique) elements in the set * Return the number of (unique) elements in the set
* *