diff --git a/public/js/icinga/behavior/collapsible.js b/public/js/icinga/behavior/collapsible.js index 642f3f89c..7f24f54f1 100644 --- a/public/js/icinga/behavior/collapsible.js +++ b/public/js/icinga/behavior/collapsible.js @@ -23,7 +23,7 @@ this.defaultVisibleHeight = 36; this.state = new Icinga.Storage.StorageAwareSet.withStorage( - new Icinga.BehaviorStorage('collapsible'), + Icinga.Storage.BehaviorStorage('collapsible'), 'expanded' ) .on('add', { self: this }, this.onExternalExpansion) diff --git a/public/js/icinga/storage.js b/public/js/icinga/storage.js index d30a9d1e2..939733c9c 100644 --- a/public/js/icinga/storage.js +++ b/public/js/icinga/storage.js @@ -8,15 +8,17 @@ * Icinga.Storage * * localStorage access + * + * @param {string} prefix */ - Icinga.Storage = function() { + Icinga.Storage = function(prefix) { /** - * Namespace separator being used + * Prefix to use for keys * * @type {string} */ - this.keySeparator = '.'; + this.prefix = prefix; /** * Callbacks for storage events on particular keys @@ -28,17 +30,30 @@ this.setup(); }; + /** + * Create a new storage with `behavior.` as prefix + * + * @param {string} name + * + * @returns {Icinga.Storage} + */ + Icinga.Storage.BehaviorStorage = function(name) { + return new Icinga.Storage('behavior.' + name); + }; + Icinga.Storage.prototype = { /** * Prefix the given key * - * Base implementation, noop. - * * @param {string} key * @returns {string} */ prefixKey: function(key) { + if (typeof this.prefix !== 'undefined') { + return this.prefix + '.' + key; + } + return key; }, @@ -118,36 +133,6 @@ } }; - /** - * Icinga.BehaviorStorage - * - * @param {string} behaviorName - * @constructor - */ - Icinga.BehaviorStorage = function(behaviorName) { - - /** - * The behavior's name - * - * @type {string} - */ - this.behaviorName = behaviorName; - - Icinga.Storage.call(this); - }; - Icinga.BehaviorStorage.prototype = Object.create(Icinga.Storage.prototype); - - /** - * Prefix the given key with `behavior..` - * - * @param {string} key - * - * @returns {string} - */ - Icinga.BehaviorStorage.prototype.prefixKey = function(key) { - return 'behavior' + this.keySeparator + this.behaviorName + this.keySeparator + key; - }; - /** * Icinga.Storage.StorageAwareSet *