Skip to content

Commit

Permalink
Merge branch 'master' into FLUID-5213, resolve conflicts and renamed …
Browse files Browse the repository at this point in the history
…"validationFunc" in the aux builder to "optionRequired".

Conflicts:
	src/framework/preferences/js/AuxBuilder.js
  • Loading branch information
cindyli committed Nov 25, 2013
2 parents 6d177e8 + 8890b03 commit 8455a1e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 44 deletions.
12 changes: 5 additions & 7 deletions src/framework/preferences/js/AuxBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ var fluid_1_5 = fluid_1_5 || {};
var canAdd = true;

// Execute the validation function to decide if this common option should be added
if (option.validationFunc) {
canAdd = fluid.invokeGlobalFunction(option.validationFunc, [root, path, commonOptions, templateValues]);
if (option.optionRequired) {
canAdd = fluid.invokeGlobalFunction(option.optionRequired, [root, path, commonOptions, templateValues]);
value = option.value;
}
if (option.mergeFunc) {
Expand Down Expand Up @@ -328,9 +328,9 @@ var fluid_1_5 = fluid_1_5 || {};
return auxSchema;
};

fluid.prefs.expandSchema = function (schemaToExpand, defaultNamespace, indexes, topCommonOptions, elementCommonOptions, mappedDefaults) {
fluid.prefs.expandSchema = function (schemaToExpand, indexes, topCommonOptions, elementCommonOptions, mappedDefaults) {
var auxSchema = fluid.prefs.expandSchemaImpl(schemaToExpand);
auxSchema.namespace = auxSchema.namespace || defaultNamespace;
auxSchema.namespace = auxSchema.namespace || "fluid.prefs.created_" + fluid.allocateGuid();

var compositePanelList = fluid.get(auxSchema, "groups");
if (compositePanelList) {
Expand Down Expand Up @@ -389,7 +389,6 @@ var fluid_1_5 = fluid_1_5 || {};

fluid.defaults("fluid.prefs.auxBuilder", {
gradeNames: ["fluid.prefs.auxSchema", "autoInit"],
defaultNamespace: "fluid.prefs.create",
mergePolicy: {
elementCommonOptions: "noexpand"
},
Expand Down Expand Up @@ -438,7 +437,7 @@ var fluid_1_5 = fluid_1_5 || {};
// Conditional handling. Add value to the path only if the execution of func returns true.
"container": {
"value": "{uiEnhancer}.container",
"validationFunc": "fluid.prefs.containerNeeded"
"optionRequired": "fluid.prefs.containerNeeded"
}
}
},
Expand Down Expand Up @@ -468,7 +467,6 @@ var fluid_1_5 = fluid_1_5 || {};
func: "fluid.prefs.expandSchema",
args: [
"{that}.options.auxiliarySchema",
"{that}.options.defaultNamespace",
"{that}.options.indexes",
"{that}.options.topCommonOptions",
"{that}.options.elementCommonOptions",
Expand Down
9 changes: 9 additions & 0 deletions src/framework/preferences/js/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@ var fluid_1_5 = fluid_1_5 || {};
return auxTypes;
};

/*
* A one-stop-shop function to build and instantiate a prefsEditor from a schema.
*/
fluid.prefs.create = function (container, options) {
options = options || {};
var builder = fluid.prefs.builder(options.build);
return fluid.invokeGlobalFunction(builder.options.assembledPrefsEditorGrade, [container, options.prefsEditor]);
};

})(jQuery, fluid_1_5);
2 changes: 2 additions & 0 deletions src/tests/framework-tests/preferences/html/Builder-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ <h2 id="qunit-userAgent"></h2>

<div class="flc-toc-tocContainer"></div>
<div id="flc-prefsEditor"></div>
<div class="prefs_defaultNamespace"></div>
<div class="prefs_customNamespace"></div>
</body>
</html>
47 changes: 26 additions & 21 deletions src/tests/framework-tests/preferences/js/AuxBuilderTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
*******************************************************************************/

fluid.tests.schema = {
"namespace": "fluid.tests.prefsEditor",
"textFont": {
"type": "fluid.prefs.textFont",
"classes": {
Expand Down Expand Up @@ -112,6 +113,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
};

fluid.tests.expectedSchema = {
"namespace": "fluid.tests.prefsEditor",
"textFont": {
"type": "fluid.prefs.textFont",
"classes": {
Expand Down Expand Up @@ -462,12 +464,18 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt

fluid.registerNamespace("fluid.tests.auxSchema");

fluid.tests.testEmpty = function (expandedAuxSchema) {
var namespace = fluid.get(expandedAuxSchema, "namespace");

jqUnit.assertTrue("The prefsEditor grade should use the custom namespace", namespace.indexOf("fluid.prefs.created_") === 0);
jqUnit.assertEquals("Only namespace is in the expanded aux schema", 1, fluid.keys(expandedAuxSchema).length);
};

fluid.tests.testAuxBuilder = function (expandedSchema, expectedExpandedSchema) {
jqUnit.assertDeepEq("The schema was expanded correctly", expectedExpandedSchema, expandedSchema);
};

fluid.tests.auxSchema.defaultNamespace = fluid.defaults("fluid.prefs.auxBuilder").defaultNamespace;
fluid.tests.auxSchema.newNamespace = "fluid.prefs.constructedPrefsEditor";
fluid.tests.auxSchema.customizedNamespace = "fluid.prefs.constructedPrefsEditor";

fluid.tests.auxSchema.panels = {
"textSize": {
Expand Down Expand Up @@ -557,7 +565,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
};

fluid.tests.auxSchema.namespace = {
"namespace": fluid.tests.auxSchema.newNamespace
"namespace": fluid.tests.auxSchema.customizedNamespace
};

fluid.tests.auxSchema.template = {
Expand Down Expand Up @@ -595,7 +603,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
};

fluid.tests.auxSchema.expectedEnactors = {
"namespace": fluid.tests.auxSchema.newNamespace,
"namespace": fluid.tests.auxSchema.customizedNamespace,
"textSize": {
"type": "fluid.prefs.textSize",
"enactor": {
Expand Down Expand Up @@ -640,7 +648,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
};

fluid.tests.auxSchema.expectedPanels = {
"namespace": fluid.tests.auxSchema.defaultNamespace,
"namespace": fluid.tests.auxSchema.customizedNamespace,
"textSize": {
"type": "fluid.prefs.textSize",
"panel": {
Expand Down Expand Up @@ -723,23 +731,23 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
auxbuilderOnlyPanel: {
type: "fluid.prefs.auxBuilder",
options: {
auxiliarySchema: fluid.tests.auxSchema.panels,
auxiliarySchema: $.extend(true, {}, fluid.tests.auxSchema.panels, fluid.tests.auxSchema.namespace),
elementCommonOptions: fluid.tests.elementCommonOptions,
mappedDefaults: fluid.tests.auxSchema.mappedDefaults
}
},
auxbuilderManyPanelsOnePref: {
type: "fluid.prefs.auxBuilder",
options: {
auxiliarySchema: fluid.tests.auxSchema.manyPanelsOnePref,
auxiliarySchema: $.extend(true, {}, fluid.tests.auxSchema.manyPanelsOnePref, fluid.tests.auxSchema.namespace),
elementCommonOptions: fluid.tests.elementCommonOptions,
mappedDefaults: fluid.tests.auxSchema.mappedDefaults
}
},
auxbuilderManyPrefsOnePanel: {
type: "fluid.prefs.auxBuilder",
options: {
auxiliarySchema: fluid.tests.auxSchema.manyPrefsOnePanel,
auxiliarySchema: $.extend(true, {}, fluid.tests.auxSchema.manyPrefsOnePanel, fluid.tests.auxSchema.namespace),
elementCommonOptions: fluid.tests.elementCommonOptions,
mappedDefaults: fluid.tests.auxSchema.mappedDefaults
}
Expand All @@ -761,13 +769,10 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
fluid.defaults("fluid.tests.auxBuilderTester", {
gradeNames: ["fluid.test.testCaseHolder", "autoInit"],
testOptions: {
expectedPrefs: {
"namespace": fluid.tests.auxSchema.defaultNamespace
},
expectedPanels: fluid.tests.auxSchema.expectedPanels,
expectedEnactors: fluid.tests.auxSchema.expectedEnactors,
expectedManyPanelsOnePref: {
"namespace": fluid.tests.auxSchema.defaultNamespace,
"namespace": fluid.tests.auxSchema.customizedNamespace,
"textSize": {
"type": "fluid.prefs.textSize",
"panel": {
Expand Down Expand Up @@ -861,7 +866,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
}
},
expectedManyPrefsOnePanel: {
"namespace": fluid.tests.auxSchema.defaultNamespace,
"namespace": fluid.tests.auxSchema.customizedNamespace,
"emphasizeLinks": {
"type": "fluid.prefs.emphasizeLinks",
"panel": {
Expand Down Expand Up @@ -927,7 +932,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
}
},
expectedAll: {
"namespace": fluid.tests.auxSchema.newNamespace,
"namespace": fluid.tests.auxSchema.customizedNamespace,
"textSize": {
"type": "fluid.prefs.textSize",
"panel": {
Expand Down Expand Up @@ -1023,11 +1028,11 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
modules: [{
name: "Test auxBuilder",
tests: [{
expect: 1,
expect: 2,
name: "expandedAuxSchema - empty",
type: "test",
func: "fluid.tests.testAuxBuilder",
args: ["{auxbuilderEmpty}.options.expandedAuxSchema", "{that}.options.testOptions.expectedPrefs"]
func: "fluid.tests.testEmpty",
args: ["{auxbuilderEmpty}.options.expandedAuxSchema"]
}, {
expect: 1,
name: "expandedAuxSchema - onlyPanel",
Expand Down Expand Up @@ -1159,7 +1164,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
};

fluid.tests.auxSchema.compositePanelSchema = {
"namespace": fluid.tests.auxSchema.newNamespace, // The author of the auxiliary schema will provide this and will be the component to call to initialize the constructed UIO.
"namespace": fluid.tests.auxSchema.customizedNamespace, // The author of the auxiliary schema will provide this and will be the component to call to initialize the constructed UIO.
"templatePrefix": "../html/", // The common path to settings panel templates. The template defined in "panels" element will take precedence over this definition.
"template": "%prefix/prefs.html",
"messagePrefix": "../messages/", // The common path to settings panel templates. The template defined in "panels" element will take precedence over this definition.
Expand Down Expand Up @@ -1204,7 +1209,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
};

fluid.tests.auxSchema.expandedComposite = {
"namespace": fluid.tests.auxSchema.newNamespace, // The author of the auxiliary schema will provide this and will be the component to call to initialize the constructed UIO.
"namespace": fluid.tests.auxSchema.customizedNamespace, // The author of the auxiliary schema will provide this and will be the component to call to initialize the constructed UIO.
"templatePrefix": "../html/", // The common path to settings panel templates. The template defined in "panels" element will take precedence over this definition.
"template": "%prefix/prefs.html",
"messagePrefix": "../messages/", // The common path to settings panel templates. The template defined in "panels" element will take precedence over this definition.
Expand Down Expand Up @@ -1722,7 +1727,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
commonOptions: {
"subPath1": {
value: "subValue1",
validationFunc: "fluid.tests.returnTrue"
optionRequired: "fluid.tests.returnTrue"
}
},
templateValues: null,
Expand All @@ -1740,7 +1745,7 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
commonOptions: {
"subPath1": {
value: "subValue1",
validationFunc: "fluid.tests.returnFalse"
optionRequired: "fluid.tests.returnFalse"
}
},
templateValues: null,
Expand Down
33 changes: 33 additions & 0 deletions src/tests/framework-tests/preferences/js/BuilderTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,39 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
}]
});

var startsWith = function (str, subStr) {
return str.indexOf(subStr) === 0;
};

jqUnit.test("fluid.prefs.create", function () {
var pref_defaultNamespace = fluid.prefs.create(".prefs_defaultNamespace", {
build: {
gradeNames: ["fluid.prefs.auxSchema.starter"],
auxiliarySchema: {
"namespace": "",
"templatePrefix": "../../../framework/preferences/html/",
"messagePrefix": "../../../framework/preferences/messages/"
}
}
});
jqUnit.assertTrue("The prefs editor should have been returned", fluid.hasGrade(pref_defaultNamespace.options, "fluid.prefs.assembler.prefsEd"));
jqUnit.assertTrue("The prefsEditor grade should use the custom namespace", startsWith(pref_defaultNamespace.typeName, "fluid.prefs.created_"));

var namespace = "fluid.test.namespace";
var pref_customNamespace = fluid.prefs.create(".prefs_customNamespace", {
build: {
gradeNames: ["fluid.prefs.auxSchema.starter"],
auxiliarySchema: {
"namespace": namespace,
"templatePrefix": "../../../framework/preferences/html/",
"messagePrefix": "../../../framework/preferences/messages/"
}
}
});
jqUnit.assertTrue("The prefs editor should have been returned", fluid.hasGrade(pref_customNamespace.options, "fluid.prefs.assembler.prefsEd"));
jqUnit.assertTrue("The prefsEditor grade should use the custom namespace", startsWith(pref_customNamespace.typeName, namespace));
});

/***********************
* Test Initialization *
***********************/
Expand Down
23 changes: 13 additions & 10 deletions src/tests/manual-tests/js/prefsEditorFullPageSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
var demo = demo || {};
(function ($, fluid) {

demo.initWithSchema = function (container, compOpts, prefsEditorType, template) {
var builder = fluid.prefs.builder({
var generateBuildOpts = function (template) {
return {
gradeNames: ["fluid.prefs.auxSchema.starter"],
auxiliarySchema: {
"template": template,
Expand All @@ -29,20 +29,23 @@ var demo = demo || {};
}
}
}
});
var baseOpts = {
prefsEditorType: prefsEditorType
};
$.extend(true, baseOpts, compOpts);
return fluid.invokeGlobalFunction(builder.options.assembledPrefsEditorGrade, [container, baseOpts]);
}
};

demo.initFullWithPreview = function (container, options) {
return demo.initWithSchema(container, options, "fluid.prefs.fullPreview", "%prefix/FullPreviewPrefsEditor.html");
var prefsEditorOpts = $.extend(true, {prefsEditorType: "fluid.prefs.fullPreview"}, options);
return fluid.prefs.create(container, {
build: generateBuildOpts("%prefix/FullPreviewPrefsEditor.html"),
prefsEditor: prefsEditorOpts
});
};

demo.initFullNoPreview = function (container, options) {
return demo.initWithSchema(container, options, "fluid.prefs.fullNoPreview", "%prefix/FullNoPreviewPrefsEditor.html");
var prefsEditorOpts = $.extend(true, {prefsEditorType: "fluid.prefs.fullNoPreview"}, options);
return fluid.prefs.create(container, {
build: generateBuildOpts("%prefix/FullNoPreviewPrefsEditor.html"),
prefsEditor: prefsEditorOpts
});
};

})(jQuery, fluid);
13 changes: 7 additions & 6 deletions src/tests/manual-tests/js/prefsEditorSeparatedPanelSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ var demo = demo || {};
* Makes use of a schema to configure Preferences Editor
*/
demo.initPrefsEditor = function (container) {
var builder = fluid.prefs.builder({
gradeNames: ["fluid.prefs.auxSchema.starter"],
auxiliarySchema: {
"templatePrefix": "../../../framework/preferences/html/",
"messagePrefix": "../../../framework/preferences/messages/"
return fluid.prefs.create(container, {
build: {
gradeNames: ["fluid.prefs.auxSchema.starter"],
auxiliarySchema: {
"templatePrefix": "../../../framework/preferences/html/",
"messagePrefix": "../../../framework/preferences/messages/"
}
}
});
return fluid.invokeGlobalFunction(builder.options.assembledPrefsEditorGrade, [container]);
};

})(jQuery, fluid);

0 comments on commit 8455a1e

Please sign in to comment.