mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-09-03 20:52:56 -05:00
Replace old builder by new implementation
https://fedorahosted.org/freeipa/ticket/3235
This commit is contained in:
@@ -28,6 +28,7 @@ define([
|
||||
'dojo/on',
|
||||
'dojo/Stateful',
|
||||
'dojo/Evented',
|
||||
'./_base/Builder',
|
||||
'./ipa',
|
||||
'./jquery',
|
||||
'./navigation',
|
||||
@@ -36,7 +37,7 @@ define([
|
||||
'./field',
|
||||
'./widget'
|
||||
], function(declare, lang, construct, on, Stateful, Evented,
|
||||
IPA, $, navigation, text) {
|
||||
Builder, IPA, $, navigation, text) {
|
||||
|
||||
/**
|
||||
* Facet represents the content of currently displayed page.
|
||||
@@ -102,8 +103,6 @@ exp.facet_spec = {};
|
||||
exp.facet = IPA.facet = function(spec, no_init) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.state = spec.state || {};
|
||||
$.extend(spec.state, { factory: IPA.state });
|
||||
|
||||
var that = new Evented();
|
||||
|
||||
@@ -119,8 +118,8 @@ exp.facet = IPA.facet = function(spec, no_init) {
|
||||
that.disable_breadcrumb = spec.disable_breadcrumb;
|
||||
that.disable_facet_tabs = spec.disable_facet_tabs;
|
||||
|
||||
that.action_state = IPA.build(spec.state);
|
||||
that.actions = IPA.build({ actions: spec.actions }, IPA.action_holder_builder);
|
||||
that.action_state = IPA.build(spec.state, {}, { factory: exp.state });
|
||||
that.actions = exp.action_holder_builder.build({ actions: spec.actions });
|
||||
|
||||
that.header_actions = spec.header_actions;
|
||||
that.header = spec.header || IPA.facet_header({ facet: that });
|
||||
@@ -1716,15 +1715,6 @@ exp.action = IPA.action = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
exp.action_builder = IPA.action_builder = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.factory = spec.factory || IPA.action;
|
||||
var that = IPA.builder(spec);
|
||||
return that;
|
||||
};
|
||||
|
||||
|
||||
exp.action_holder = IPA.action_holder = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
@@ -1738,7 +1728,7 @@ exp.action_holder = IPA.action_holder = function(spec) {
|
||||
var i, action, actions;
|
||||
|
||||
that.facet = facet;
|
||||
actions = IPA.build(spec.actions, IPA.action_builder) || [];
|
||||
actions = exp.action_builder.build(spec.actions);
|
||||
|
||||
for (i=0; i<actions.length; i++) {
|
||||
action = actions[i];
|
||||
@@ -1782,19 +1772,9 @@ exp.action_holder = IPA.action_holder = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
exp.action_holder_builder = IPA.action_holder_builder = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.factory = spec.factory || IPA.action_holder;
|
||||
var that = IPA.builder(spec);
|
||||
return that;
|
||||
};
|
||||
|
||||
|
||||
exp.state = IPA.state = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.summary_evaluator = spec.summary_evaluator || IPA.summary_evaluator;
|
||||
|
||||
var that = {};
|
||||
|
||||
@@ -1803,8 +1783,8 @@ exp.state = IPA.state = function(spec) {
|
||||
//when state changes. Params: state, Context: this
|
||||
that.changed = IPA.observer();
|
||||
|
||||
that.evaluators = IPA.build(spec.evaluators, IPA.state_evaluator_builder) || [];
|
||||
that.summary_evaluator = IPA.build(spec.summary_evaluator);
|
||||
that.evaluators = exp.state_evaluator_builder.build(spec.evaluators);
|
||||
that.summary_evaluator = IPA.build(spec.summary_evaluator || IPA.summary_evaluator);
|
||||
|
||||
that.summary_conditions = spec.summary_conditions || [];
|
||||
|
||||
@@ -1931,14 +1911,6 @@ exp.state_evaluator = IPA.state_evaluator = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
exp.state_evaluator_builder = IPA.state_evaluator_builder = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.factory = spec.factory || IPA.state_evaluator;
|
||||
var that = IPA.builder(spec);
|
||||
return that;
|
||||
};
|
||||
|
||||
exp.dirty_state_evaluator = IPA.dirty_state_evaluator = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
@@ -2148,21 +2120,13 @@ exp.action_button_widget = IPA.action_button_widget = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
exp.action_button_widget_builder = IPA.action_button_widget_builder = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
spec.factory = spec.factory || IPA.action_button_widget;
|
||||
var that = IPA.builder(spec);
|
||||
return that;
|
||||
};
|
||||
|
||||
exp.control_buttons_widget = IPA.control_buttons_widget = function(spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
var that = IPA.widget(spec);
|
||||
|
||||
that.buttons = IPA.build(spec.buttons, IPA.action_button_widget_builder) || [];
|
||||
that.buttons = IPA.action_button_widget_builder.build(spec.buttons);
|
||||
|
||||
that.init = function(facet) {
|
||||
|
||||
@@ -2458,5 +2422,25 @@ var FacetState = exp.FacetState = declare([Stateful, Evented], {
|
||||
}
|
||||
});
|
||||
|
||||
exp.action_builder = IPA.action_builder = new Builder({
|
||||
factory: exp.action
|
||||
});
|
||||
|
||||
exp.action_holder_builder = new Builder({
|
||||
factory: exp.action_holder
|
||||
});
|
||||
|
||||
exp.state_builder = IPA.state_builder = new Builder({
|
||||
factory: exp.state
|
||||
});
|
||||
|
||||
exp.state_evaluator_builder = IPA.state_evaluator_builder = new Builder({
|
||||
factory: exp.state
|
||||
});
|
||||
|
||||
exp.action_button_widget_builder = IPA.action_button_widget_builder = new Builder({
|
||||
factory: exp.action_button_widget
|
||||
});
|
||||
|
||||
return exp;
|
||||
});
|
||||
|
||||
@@ -22,8 +22,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
define(['./jquery', './json2','./_base/i18n', './_base/metadata_provider', './text'],
|
||||
function($, JSON, i18n, metadata_provider, text) {
|
||||
define(['./jquery',
|
||||
'./json2',
|
||||
'./_base/Builder',
|
||||
'./_base/i18n',
|
||||
'./_base/metadata_provider',
|
||||
'./text'],
|
||||
function($, JSON, Builder, i18n, metadata_provider, text) {
|
||||
|
||||
var IPA = function() {
|
||||
|
||||
@@ -1144,88 +1149,11 @@ IPA.concurrent_command = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.builder = function(spec) {
|
||||
IPA.builder = new Builder();
|
||||
|
||||
spec = spec || {};
|
||||
IPA.build = function(spec, context, overrides) {
|
||||
|
||||
var that = {};
|
||||
|
||||
that.factory = spec.factory || IPA.default_factory;
|
||||
|
||||
that.build = function(spec) {
|
||||
|
||||
var factory = spec.factory || that.factory;
|
||||
|
||||
//when spec is a factory function
|
||||
if (!spec.factory && typeof spec === 'function') {
|
||||
factory = spec;
|
||||
spec = {};
|
||||
}
|
||||
|
||||
var obj = factory(spec);
|
||||
return obj;
|
||||
};
|
||||
|
||||
that.build_objects = function(specs) {
|
||||
|
||||
var objects = [];
|
||||
|
||||
for (var i=0; i<specs.length; i++) {
|
||||
var spec = specs[i];
|
||||
var obj = that.build(spec);
|
||||
objects.push(obj);
|
||||
}
|
||||
|
||||
return objects;
|
||||
};
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.build = function(spec, builder_fac) {
|
||||
|
||||
if (!spec) return null;
|
||||
|
||||
if (!builder_fac) builder_fac = IPA.builder;
|
||||
|
||||
var builder = builder_fac();
|
||||
var product;
|
||||
|
||||
if ($.isArray(spec)) {
|
||||
product = builder.build_objects(spec);
|
||||
} else {
|
||||
product = builder.build(spec);
|
||||
}
|
||||
|
||||
return product;
|
||||
};
|
||||
|
||||
IPA.build_default = function(spec, def_spec) {
|
||||
|
||||
var builder, factory, default_object;
|
||||
|
||||
if (!spec && !def_spec) return null;
|
||||
|
||||
if (typeof def_spec === 'function') { //factory function
|
||||
factory = def_spec;
|
||||
} else if (typeof def_spec === 'object') {
|
||||
default_object = def_spec;
|
||||
}
|
||||
|
||||
builder = IPA.builder({
|
||||
factory: factory
|
||||
});
|
||||
|
||||
var product;
|
||||
spec = spec || default_object || {};
|
||||
|
||||
if ($.isArray(spec)) {
|
||||
product = builder.build_objects(spec);
|
||||
} else {
|
||||
product = builder.build(spec);
|
||||
}
|
||||
|
||||
return product;
|
||||
return IPA.builder.build(spec, context, overrides);
|
||||
};
|
||||
|
||||
IPA.default_factory = function(spec) {
|
||||
|
||||
@@ -74,7 +74,7 @@ IPA.widget = function(spec) {
|
||||
facet: that.facet
|
||||
});
|
||||
|
||||
var child = IPA.build(spec, factory);
|
||||
var child = IPA.build(spec,{}, factory);
|
||||
return child;
|
||||
};
|
||||
|
||||
@@ -3152,7 +3152,7 @@ IPA.details_table_section = function(spec) {
|
||||
spec = spec || {};
|
||||
|
||||
var that = IPA.details_section(spec);
|
||||
that.layout = IPA.build_default(spec.layout, IPA.table_layout);
|
||||
that.layout = IPA.build(spec.layout || IPA.table_layout);
|
||||
that.action_panel = that.build_child(spec.action_panel);
|
||||
|
||||
that.rows = $.ordered_map();
|
||||
@@ -3228,7 +3228,7 @@ IPA.multiple_choice_section = function(spec) {
|
||||
|
||||
var that = IPA.composite_widget(spec);
|
||||
that.choices = $.ordered_map().put_array(spec.choices, 'name');
|
||||
that.layout = IPA.build_default(spec.layout, IPA.table_layout);
|
||||
that.layout = IPA.build(spec.layout || IPA.table_layout);
|
||||
|
||||
that.create = function(container) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user