From e100ba7e2b14b74ed548ee0dd6ba1093b17dd795 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 16 Apr 2013 12:59:38 +0200 Subject: Replace build logic in widget and field builder by new builder https://fedorahosted.org/freeipa/ticket/3235 --- install/ui/src/freeipa/widget.js | 84 +++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 49 deletions(-) (limited to 'install/ui/src/freeipa/widget.js') diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index c8d0388a..42f67d3b 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -23,6 +23,7 @@ define(['dojo/_base/array', + 'dojo/_base/lang', './builder', './ipa', './jquery', @@ -30,7 +31,7 @@ define(['dojo/_base/array', './reg', './text' ], - function(array, builder, IPA, $, phases, reg, text) { + function(array, lang, builder, IPA, $, phases, reg, text) { var exp = {}; @@ -3459,7 +3460,6 @@ IPA.widget_container = function(spec) { spec.new_container_for_child : true; that.widgets = $.ordered_map(); - that.widget_builder = spec.widget_builder || IPA.widget_builder(); that.add_widget = function(widget) { that.widgets.put(widget.name, widget); @@ -3533,61 +3533,20 @@ IPA.widget_builder = function(spec) { var that = IPA.object(); - that.default_factory = spec.default_factory || IPA.text_widget; that.container = spec.container; - that.widget_options = spec.widget_options || {}; - - that.get_widget_factory = function(spec) { - - var factory; - if (spec.$factory) { - factory = spec.$factory; - } else if(spec.type) { - factory = reg.widget.get(spec.type); - factory = factory ? factory.factory : undefined; - } - - if (!factory) { - factory = that.default_factory; - } - - return factory; - }; + that.widget_options = spec.widget_options; that.build_widget = function(spec, container) { - container = container || that.container; - - if(!(spec instanceof Object)) { - spec = { name: spec }; - } - - if(that.widget_options) { - $.extend(spec, that.widget_options); - } - - var factory = that.get_widget_factory(spec); - - var widget = factory(spec); - - if(container) { - container.add_widget(widget); - } - - if(spec.widgets) { - that.build_widgets(spec.widgets, widget.widgets); - } - + var context = lang.mixin({}, that.widget_options); + context.container = container || that.container; + var widget = builder.build('widget', spec, context); return widget; }; that.build_widgets = function(specs, container) { - container = container || that.container; - - for(var i=0; i