From f78cc8932626de667c6e3a4461141a10a5d9c2e6 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka Date: Thu, 11 Aug 2016 15:56:01 +0200 Subject: Make singleton from config module Also added general setter and getter for attributes of config. Part of: https://fedorahosted.org/freeipa/ticket/5742 Reviewed-By: Petr Vobornik --- install/ui/src/freeipa/config.js | 51 +++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/install/ui/src/freeipa/config.js b/install/ui/src/freeipa/config.js index 61922d454..3bf017bdc 100644 --- a/install/ui/src/freeipa/config.js +++ b/install/ui/src/freeipa/config.js @@ -20,14 +20,18 @@ -define([], function() { +define([ + 'dojo/_base/declare', + 'dojo/topic' + ], + function(declare, topic) { /** * Application configuration * @class config * @singleton */ - var config = { + var config = declare([], { /** * Selector for application container node @@ -82,8 +86,43 @@ define([], function() { * Hide sections without any visible widget * @property {boolean} */ - hide_empty_sections: true - }; + hide_empty_sections: true, - return config; -}); \ No newline at end of file + /** + * Number of lines in table on table_facets + * @property {Integer} + */ + table_page_size: 20, + + /** + * Genereal setter for config values. + * @param item_name {string} + * @param value + * @param store {Boolean} sets whether the value will be stored into + * local storage + */ + set: function(item_name, value, store) { + if (!item_name) return; + this[item_name] = value; + + if (store) { + window.localStorage.setItem(item_name, value); + } + }, + + /** + * Genereal setter for config values. + * @param item_name {string} + */ + get: function(item_name) { + return this[item_name]; + }, + + constructor: function() { + var user_limit = window.localStorage.getItem('table_page_size'); + if (user_limit) this.table_page_size = user_limit; + } + }); + + return new config(); +}); -- cgit