diff --git a/src/webapp/components/uiOptions/js/FatPanelUIOptions.js b/src/webapp/components/uiOptions/js/FatPanelUIOptions.js index ebbc9d4492..d2e812cbda 100644 --- a/src/webapp/components/uiOptions/js/FatPanelUIOptions.js +++ b/src/webapp/components/uiOptions/js/FatPanelUIOptions.js @@ -30,8 +30,6 @@ var fluid_1_5 = fluid_1_5 || {}; /***************************************** * Fat Panel UI Options Top Level Driver * *****************************************/ - - fluid.registerNamespace("fluid.uiOptions.fatPanel"); fluid.defaults("fluid.uiOptions.fatPanel", { gradeNames: ["fluid.uiOptions.inline", "autoInit"], @@ -42,7 +40,7 @@ var fluid_1_5 = fluid_1_5 || {}; listeners: { onReady: { listener: "fluid.uiOptions.fatPanel.bindEvents", - args: ["{fatPanel}.uiOptionsLoader.uiOptions", "{uiEnhancer}", "{iframeRenderer}.iframeEnhancer", "{fatPanel}"] + args: ["{fatPanel}.uiOptionsLoader.uiOptions", "{iframeRenderer}.iframeEnhancer", "{fatPanel}"] } }, selectors: { @@ -120,6 +118,7 @@ var fluid_1_5 = fluid_1_5 || {}; createOnEvent: "templatesAndIframeReady", container: "{iframeRenderer}.renderUIOContainer", options: { + gradeNames: ["fluid.uiOptions.uiEnhancerRelay"], // ensure that model and applier are available to users at top level model: "{fatPanel}.model", applier: "{fatPanel}.applier", @@ -197,24 +196,24 @@ var fluid_1_5 = fluid_1_5 || {}; that.iframe.appendTo(that.container); }; - fluid.uiOptions.fatPanel.updateView = function (uiOptions, uiEnhancer) { + fluid.uiOptions.fatPanel.updateView = function (uiOptions) { uiOptions.events.onSignificantDOMChange.fire(); }; - fluid.uiOptions.fatPanel.bindEvents = function (uiOptions, uiEnhancer, iframeEnhancer, fatPanel) { + fluid.uiOptions.fatPanel.bindEvents = function (uiOptions, iframeEnhancer, fatPanel) { // TODO: This binding should be done declaratively - needs ginger world in order to bind onto slidingPanel // which is a child of this component - and also uiOptionsLoader which is another child fatPanel.slidingPanel.events.afterPanelShow.addListener(function () { iframeEnhancer.events.onIframeVisible.fire(iframeEnhancer); - fluid.uiOptions.fatPanel.updateView(uiOptions, iframeEnhancer); + fluid.uiOptions.fatPanel.updateView(uiOptions); }); uiOptions.events.modelChanged.addListener(function (model) { - uiEnhancer.updateModel(model.selections); + iframeEnhancer.updateModel(model.selections); uiOptions.save(); }); uiOptions.events.onReset.addListener(function (uiOptions) { - fluid.uiOptions.fatPanel.updateView(uiOptions, iframeEnhancer); + fluid.uiOptions.fatPanel.updateView(uiOptions); }); uiOptions.events.onSignificantDOMChange.addListener(function () { var dokkument = uiOptions.container[0].ownerDocument; diff --git a/src/webapp/components/uiOptions/js/ModelRelay.js b/src/webapp/components/uiOptions/js/ModelRelay.js index 5f8ac4687b..b11447755c 100644 --- a/src/webapp/components/uiOptions/js/ModelRelay.js +++ b/src/webapp/components/uiOptions/js/ModelRelay.js @@ -32,24 +32,38 @@ var fluid_1_5 = fluid_1_5 || {}; mergePolicy: { sourceApplier: "nomerge" }, + listeners: { + onCreate: "{that}.addListeners", + onDestroy: "{that}.removeListeners" + }, + invokers: { + addListeners: { + funcName: "fluid.uiOptions.modelRelay.addListeners", + args: ["{that}.options.rules", "{that}.applier", "{that}.options.sourceApplier", "{that}.id"] + }, + removeListeners: { + funcName: "fluid.uiOptions.modelRelay.removeListeners", + args: ["{that}.options.rules", "{that}.options.sourceApplier", "{that}.id"] + } + }, sourceApplier: null, // must be supplied by implementors - rules: {}, // must be supplied by implementors, in format: "externalModelKey": "internalModelKey" - postInitFunction: "fluid.uiOptions.modelRelay.postInit" + rules: {} // must be supplied by implementors, in format: "externalModelKey": "internalModelKey" }); - - fluid.uiOptions.modelRelay.postInit = function (that) { - fluid.transform(that.options.rules, function (internalKey, sourceKey) { - that.applier.modelChanged.addListener(internalKey, function (newModel, oldModel) { - if (!that.applier.hasChangeSource(sourceKey)) { - fluid.fireSourcedChange(that.options.sourceApplier, sourceKey, fluid.get(newModel, internalKey), internalKey); - } - }); - - that.options.sourceApplier.modelChanged.addListener(sourceKey, function (newModel, oldModel) { - if (!that.options.sourceApplier.hasChangeSource(internalKey)) { - fluid.fireSourcedChange(that.applier, internalKey, fluid.get(newModel, sourceKey), sourceKey); - } + + fluid.uiOptions.modelRelay.removeListeners = function (rules, applier, namespace) { + fluid.each(rules, function () { + applier.removeListener(namespace); + }); + }; + + fluid.uiOptions.modelRelay.addListeners = function (rules, applier, sourceApplier, namespace) { + fluid.each(rules, function (internalKey, sourceKey) { + fluid.addSourceGuardedListener(applier, internalKey, sourceKey, function (newModel) { + fluid.fireSourcedChange(sourceApplier, sourceKey, fluid.get(newModel, internalKey), internalKey) }); + fluid.addSourceGuardedListener(sourceApplier, sourceKey, internalKey, function (newModel) { + fluid.fireSourcedChange(applier, internalKey, fluid.get(newModel, sourceKey), sourceKey); + }, undefined, namespace); }); }; diff --git a/src/webapp/components/uiOptions/js/SettingsPanels.js b/src/webapp/components/uiOptions/js/SettingsPanels.js index f52d517441..6414f5322b 100644 --- a/src/webapp/components/uiOptions/js/SettingsPanels.js +++ b/src/webapp/components/uiOptions/js/SettingsPanels.js @@ -323,7 +323,7 @@ var fluid_1_5 = fluid_1_5 || {}; "selections.textSize": "value" }, model: { - value: "{uiOptions}.defaultModel.textSize" + value: "{fluid.uiOptions.defaultModel}.defaultModel.textSize" }, resources: { template: "{templateLoader}.resources.textSizer" @@ -340,7 +340,7 @@ var fluid_1_5 = fluid_1_5 || {}; "selections.lineSpacing": "value" }, model: { - value: "{uiOptions}.defaultModel.lineSpacing" + value: "{fluid.uiOptions.defaultModel}.defaultModel.lineSpacing" }, resources: { template: "{templateLoader}.resources.lineSpacer" @@ -358,7 +358,7 @@ var fluid_1_5 = fluid_1_5 || {}; "selections.textFont": "value" }, model: { - value: "{uiOptions}.defaultModel.textFont" + value: "{fluid.uiOptions.defaultModel}.defaultModel.textFont" }, resources: { template: "{templateLoader}.resources.textFont" @@ -376,7 +376,7 @@ var fluid_1_5 = fluid_1_5 || {}; "selections.theme": "value" }, model: { - value: "{uiOptions}.defaultModel.theme" + value: "{fluid.uiOptions.defaultModel}.defaultModel.theme" }, resources: { template: "{templateLoader}.resources.contrast" @@ -394,8 +394,8 @@ var fluid_1_5 = fluid_1_5 || {}; "selections.layout": "layout" }, model: { - toc: "{uiOptions}.defaultModel.toc", - layout: "{uiOptions}.defaultModel.layout" + toc: "{fluid.uiOptions.defaultModel}.defaultModel.toc", + layout: "{fluid.uiOptions.defaultModel}.defaultModel.layout" }, resources: { template: "{templateLoader}.resources.layoutControls" @@ -413,8 +413,8 @@ var fluid_1_5 = fluid_1_5 || {}; "selections.inputsLarger": "inputsLarger" }, model: { - links: "{uiOptions}.defaultModel.links", - inputsLarger: "{uiOptions}.defaultModel.inputsLarger" + links: "{fluid.uiOptions.defaultModel}.defaultModel.links", + inputsLarger: "{fluid.uiOptions.defaultModel}.defaultModel.inputsLarger" }, resources: { template: "{templateLoader}.resources.linksControls" diff --git a/src/webapp/components/uiOptions/js/Store.js b/src/webapp/components/uiOptions/js/Store.js index ac8941a33b..ccd53453d5 100644 --- a/src/webapp/components/uiOptions/js/Store.js +++ b/src/webapp/components/uiOptions/js/Store.js @@ -139,4 +139,21 @@ var fluid_1_5 = fluid_1_5 || {}; applier.requestChange("", settings); }; + fluid.defaults("fluid.globalSettingsStore", { + gradeNames: ["autoInit", "fluid.littleComponent"], + components: { + settingsStore: { + type: "fluid.uiOptions.store" + } + } + }); + + fluid.globalSettingsStore.finalInit = function (that) { + fluid.staticEnvironment.settingsStore = that.settingsStore; + }; + + fluid.demands("fluid.uiOptions.store", ["fluid.globalSettingsStore"], { + funcName: "fluid.cookieStore" + }); + })(jQuery, fluid_1_5); \ No newline at end of file diff --git a/src/webapp/components/uiOptions/js/UIEnhancer.js b/src/webapp/components/uiOptions/js/UIEnhancer.js index f72537c46b..59adacf75c 100755 --- a/src/webapp/components/uiOptions/js/UIEnhancer.js +++ b/src/webapp/components/uiOptions/js/UIEnhancer.js @@ -114,7 +114,7 @@ var fluid_1_5 = fluid_1_5 || {}; "textSize": "value" }, model: { - value: "{uiOptions}.defaultModel.textSize" + value: "{fluid.uiOptions.defaultModel}.defaultModel.textSize" } } }, @@ -128,7 +128,7 @@ var fluid_1_5 = fluid_1_5 || {}; "textFont": "value" }, model: { - value: "{uiOptions}.defaultModel.textFont" + value: "{fluid.uiOptions.defaultModel}.defaultModel.textFont" } } }, @@ -142,7 +142,7 @@ var fluid_1_5 = fluid_1_5 || {}; "lineSpacing": "value" }, model: { - value: "{uiOptions}.defaultModel.lineSpacing" + value: "{fluid.uiOptions.defaultModel}.defaultModel.lineSpacing" } } }, @@ -156,7 +156,7 @@ var fluid_1_5 = fluid_1_5 || {}; "theme": "value" }, model: { - value: "{uiOptions}.defaultModel.theme" + value: "{fluid.uiOptions.defaultModel}.defaultModel.theme" } } }, @@ -170,7 +170,7 @@ var fluid_1_5 = fluid_1_5 || {}; "links": "value" }, model: { - links: "{uiOptions}.defaultModel.links" + links: "{fluid.uiOptions.defaultModel}.defaultModel.links" } } }, @@ -184,7 +184,7 @@ var fluid_1_5 = fluid_1_5 || {}; "inputsLarger": "value" }, model: { - inputsLarger: "{uiOptions}.defaultModel.inputsLarger" + inputsLarger: "{fluid.uiOptions.defaultModel}.defaultModel.inputsLarger" } } }, @@ -203,7 +203,7 @@ var fluid_1_5 = fluid_1_5 || {}; onLateRefreshRelay: "{uiEnhancer}.events.onAsyncEnactorReady" }, model: { - toc: "{uiOptions}.defaultModel.toc" + toc: "{fluid.uiOptions.defaultModel}.defaultModel.toc" } } }, @@ -216,7 +216,7 @@ var fluid_1_5 = fluid_1_5 || {}; "theme": "value" }, model: { - value: "{uiOptions}.defaultModel.theme" + value: "{fluid.uiOptions.defaultModel}.defaultModel.theme" } } } @@ -260,12 +260,13 @@ var fluid_1_5 = fluid_1_5 || {}; that.options.originalUserOptions = fluid.copy(uiEnhancerOptions); that.uiEnhancerOptions = uiEnhancerOptions; fluid.initDependents(that); + that.uiEnhancer.updateModel(that.getSettings()); fluid.staticEnvironment.uiEnhancer = that.uiEnhancer; return that; }; fluid.defaults("fluid.pageEnhancer", { - gradeNames: ["fluid.originalEnhancerOptions"], + gradeNames: ["fluid.originalEnhancerOptions", "fluid.uiOptions.defaultModel", "fluid.uiOptions.settingsGetter"], components: { uiEnhancer: { type: "fluid.uiEnhancer", diff --git a/src/webapp/components/uiOptions/js/UIOptions.js b/src/webapp/components/uiOptions/js/UIOptions.js index 7a2b9314ab..1dba511737 100644 --- a/src/webapp/components/uiOptions/js/UIOptions.js +++ b/src/webapp/components/uiOptions/js/UIOptions.js @@ -258,13 +258,10 @@ var fluid_1_5 = fluid_1_5 || {}; * @param {Object} options */ fluid.defaults("fluid.uiOptions", { - gradeNames: ["fluid.viewComponent", "autoInit"], + gradeNames: ["fluid.viewComponent", "fluid.uiOptions.settingsGetter", "fluid.uiOptions.settingsSetter", "autoInit"], components: { eventBinder: { type: "fluid.uiOptions.eventBinder" - }, - settingsStore: { - type: "fluid.uiOptions.store" } }, invokers: { @@ -304,6 +301,33 @@ var fluid_1_5 = fluid_1_5 || {}; autoSave: false }); + fluid.defaults("fluid.uiOptions.settingsGetter", { + gradeNames: ["fluid.littleComponent", "autoInit"], + members: { + getSettings: "{settingsStore}.get" + } + }); + + fluid.defaults("fluid.uiOptions.settingsSetter", { + gradeNames: ["fluid.littleComponent", "autoInit"], + invokers: { + setSettings: { + funcName: "fluid.uiOptions.settingsSetter.setSettings", + args: ["{fluid.uiOptions.defaultModel}", "{arguments}.0", "{settingsStore}.set"] + } + } + }); + + fluid.uiOptions.settingsSetter.setSettings = function (defaultModel, model, set) { + var userSettings = fluid.copy(model); + if (defaultModel) { + fluid.remove_if(userSettings, function (settingVal, settingKey) { + return settingVal === defaultModel[settingKey] + }); + } + set(userSettings); + }; + fluid.defaults("fluid.uiOptions.defaultModel", { gradeNames: ["fluid.littleComponent", "autoInit"], members: { @@ -322,6 +346,40 @@ var fluid_1_5 = fluid_1_5 || {}; } } }); + + fluid.defaults("fluid.uiOptions.uiEnhancerRelay", { + gradeNames: ["autoInit", "fluid.eventedComponent"], + listeners: { + onCreate: "{that}.addListener", + onDestroy: "{that}.removeListener" + }, + invokers: { + addListener: { + funcName: "fluid.uiOptions.uiEnhancerRelay.addListener", + args: ["{fluid.uiOptions}.events.modelChanged", "{that}.updateEnhancerModel"] + }, + removeListener: { + funcName: "fluid.uiOptions.uiEnhancerRelay.removeListener", + args: ["{fluid.uiOptions}.events.modelChanged", "{that}.updateEnhancerModel"] + }, + updateEnhancerModel: { + funcName: "fluid.uiOptions.uiEnhancerRelay.updateEnhancerModel", + args: ["{uiEnhancer}", "{arguments}.0"] + } + } + }); + + fluid.uiOptions.uiEnhancerRelay.addListener = function (modelChanged, listener) { + modelChanged.addListener(listener); + }; + + fluid.uiOptions.uiEnhancerRelay.removeListener = function (modelChanged, listener) { + modelChanged.removeListener(listener); + }; + + fluid.uiOptions.uiEnhancerRelay.updateEnhancerModel = function (uiEnhancer, newModel) { + uiEnhancer.updateModel(newModel.selections); + }; // called once markup is applied to the document containing tab component roots fluid.uiOptions.finishInit = function (that) { @@ -349,7 +407,7 @@ var fluid_1_5 = fluid_1_5 || {}; fluid.uiOptions.preInit = function (that) { that.fetch = function () { - var initialModel = that.settingsStore.get(); + var initialModel = that.getSettings(); initialModel = $.extend(true, {}, that.defaultModel, initialModel); that.updateModel(initialModel, "settingsStore"); that.events.onUIOptionsRefresh.fire(); @@ -362,7 +420,7 @@ var fluid_1_5 = fluid_1_5 || {}; that.events.onSave.fire(that.model.selections); var savedSelections = fluid.copy(that.model.selections); - that.settingsStore.set(savedSelections); + that.setSettings(savedSelections); }; that.saveAndApply = function () { @@ -393,12 +451,6 @@ var fluid_1_5 = fluid_1_5 || {}; that.events.onAutoSave.fire(); } }); - - fluid.addSourceGuardedListener(that.applier, "selections", "settingsStore", - function (newModel, oldModel, changeRequest) { - that.uiEnhancer.updateModel(fluid.get(that.model, changeRequest[0].path)) - } - ); }; fluid.uiOptions.finalInit = function (that) { @@ -442,7 +494,10 @@ var fluid_1_5 = fluid_1_5 || {}; enhancer: { type: "fluid.uiEnhancer", container: "{preview}.enhancerContainer", - createOnEvent: "onReady" + createOnEvent: "onReady", + options: { + gradeNames: ["fluid.uiOptions.uiEnhancerRelay"] + } }, eventBinder: { type: "fluid.uiOptions.preview.eventBinder", @@ -507,8 +562,4 @@ var fluid_1_5 = fluid_1_5 || {}; } }); - fluid.demands("fluid.uiOptions.store", ["fluid.uiOptions"], { - funcName: "fluid.cookieStore" - }); - })(jQuery, fluid_1_5); diff --git a/src/webapp/framework/core/js/DataBinding.js b/src/webapp/framework/core/js/DataBinding.js index 93841fe281..9bfe7d8514 100644 --- a/src/webapp/framework/core/js/DataBinding.js +++ b/src/webapp/framework/core/js/DataBinding.js @@ -420,16 +420,17 @@ var fluid_1_5 = fluid_1_5 || {}; * @param path The path specification to listen to * @param source The source value to exclude (direct equality used) * @param func The listener to be notified of a change - * @param [eventName] - optional - the event name to be listened to - defaults to "modelChanged" + * @param [eventName] - optional - the event name to be listened to - defaults to "modelChanged" + * @param [namespace] - optional - the event namespace */ - fluid.addSourceGuardedListener = function(applier, path, source, func, eventName) { + fluid.addSourceGuardedListener = function(applier, path, source, func, eventName, namespace) { eventName = eventName || "modelChanged"; applier[eventName].addListener(path, function() { if (!applier.hasChangeSource(source)) { func.apply(null, arguments); } - }); + }, namespace); }; /** Convenience method to fire a change event to a specified applier, including diff --git a/src/webapp/tests/component-tests/uiOptions/html/ModelRelay-test.html b/src/webapp/tests/component-tests/uiOptions/html/ModelRelay-test.html index 2b6212a63e..4546eb8b93 100644 --- a/src/webapp/tests/component-tests/uiOptions/html/ModelRelay-test.html +++ b/src/webapp/tests/component-tests/uiOptions/html/ModelRelay-test.html @@ -2,7 +2,7 @@
-