From ab2c0cfa9f62b9b226269ac3ab0f64995bd17ccb Mon Sep 17 00:00:00 2001 From: FrissDieGurke Date: Sat, 10 May 2014 19:49:50 +0200 Subject: [PATCH 1/2] added number-type to settings framework. persist expanded object on server-side sync if changed --- public/src/modules/settings.js | 1 + public/src/modules/settings/number.js | 14 ++++++++++++++ src/settings.js | 12 +++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 public/src/modules/settings/number.js diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js index fa9ac0ac3d..2cb33163bb 100644 --- a/public/src/modules/settings.js +++ b/public/src/modules/settings.js @@ -2,6 +2,7 @@ define(function () { const DEFAULT_PLUGINS = [ 'settings/checkbox', + 'settings/number', 'settings/textarea', 'settings/select', 'settings/array', diff --git a/public/src/modules/settings/number.js b/public/src/modules/settings/number.js new file mode 100644 index 0000000000..5c98a86abc --- /dev/null +++ b/public/src/modules/settings/number.js @@ -0,0 +1,14 @@ +define(function () { + + return { + types: ['number'], + get: function (element, trim, empty) { + var value = element.val(); + if (!empty) { + return value ? +value : void 0; + } + return value ? +value : 0; + } + }; + +}); diff --git a/src/settings.js b/src/settings.js index 2286f26b1d..dfb65aaf9d 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1,16 +1,20 @@ var meta = require('./meta'); function expandObjBy(obj1, obj2) { - var key, val1, val2; + var key, val1, val2, changed = false; for (key in obj2) { val2 = obj2[key]; val1 = obj1[key]; if (!obj1.hasOwnProperty(key) || typeof val2 !== typeof val1) { obj1[key] = val2; + changed = true; } else if (typeof val2 === 'object') { - expandObjBy(val1, val2); + if (expandObjBy(val1, val2)) { + changed = true; + } } } + return changed; } function trim(obj1, obj2) { @@ -76,7 +80,9 @@ Settings.prototype.sync = function (callback) { } } catch (_error) {} _this.cfg = settings; - if (typeof callback === 'function') { + if (expandObjBy(_this.cfg._, _this.defCfg)) { + _this.persist(callback); + } else if (typeof callback === 'function') { callback.apply(_this, err); } }); From f618a9405e679b6d5a5e60cec90d56623182c446 Mon Sep 17 00:00:00 2001 From: FrissDieGurke Date: Sun, 11 May 2014 18:58:01 +0200 Subject: [PATCH 2/2] added settings number-field to docs --- docs/plugins/settings.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/plugins/settings.rst b/docs/plugins/settings.rst index f761f8115d..7ab7febb53 100644 --- a/docs/plugins/settings.rst +++ b/docs/plugins/settings.rst @@ -151,7 +151,7 @@ Additionally the following plugins are registered by default: Uses ``data-new`` to define the value of new created elements. * key (types: key) A field to input keyboard-combinations. - * checkbox, select, textarea + * checkbox, number, select, textarea Handle appropriate fields. A full list of all attributes that may influence the behavior of the default Framework: @@ -303,4 +303,4 @@ For further impression take a look at the You should also take a look at the helper-functions within `Settings `_ in order to create -your own plugins. There are a few methods that take response to call the methods of other plugins when fittingly. \ No newline at end of file +your own plugins. There are a few methods that take response to call the methods of other plugins when fittingly.