/** * FIXME: Document this controller ! */ function StorageController() { /** * FIXME: Document this method ! * @param options * @returns {boolean} */ this.initController = function(options) { this._simpleStorage = window.localStorage; if (!this._simpleStorage) { return false; } if (options.contextId) { this._contextId = options.contextId; } this.setContextData({}); }; /** * FIXME: Document this method */ this.getContextData = function() { var contextData = this._simpleStorage.getItem(this._dbPrefix + this._contextId); return JSON.parse(contextData); }; /** * FIXME: document this method ! * @param contextDataValue */ this.setContextData = function(contextDataValue) { var contextDataKey = this._dbPrefix + this._contextId; this._simpleStorage.setItem(contextDataKey, JSON.stringify(contextDataValue)); }; /** * FIXME: Document this method ! */ this.deleteContextData = function() { this._simpleStorage.removeItem(this._dbPrefix + this._contextId); }; /** * FIXME: Document this method * @param key * @param value * @returns {boolean} */ this.setValue = function(key, value) { if (!key) return false; var contextData = this.getContextData(); contextData[key] = value; this.setContextData(contextData); }; /** * FIXME: Document this method ! * @param key * @returns {*} */ this.getValue = function(key) { if (!key) return false; var contextData = this.getContextData(); return (contextData[key]) ? contextData[key] : null; }; /** * Internal properties of controller * @type {null} * @private */ this._contextId = null; this._simpleStorage = null; // ss = "simple storage" this._dbPrefix = 'ss_'; }