summaryrefslogtreecommitdiffstats
path: root/install/ui/details.js
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-05-21 13:46:14 +0200
committerPetr Vobornik <pvoborni@redhat.com>2012-06-04 10:45:07 +0200
commit306f380258354bae4d40758aec42f9f1c34ae2e7 (patch)
treec9d90794f469c37d1b962599fcdaa294981332a6 /install/ui/details.js
parentc799f6a0bf28280b3b9c473c3888367d5bdbde58 (diff)
downloadfreeipa-306f380258354bae4d40758aec42f9f1c34ae2e7.tar.gz
freeipa-306f380258354bae4d40758aec42f9f1c34ae2e7.tar.xz
freeipa-306f380258354bae4d40758aec42f9f1c34ae2e7.zip
Refactored action list and control buttons to use shared list of actions
This is a first step for implementing action panels which will also use the shared list of actions. This effor changes the way how action list and control buttons are defined. First all actions are defined on facet level - attribute 'actions' in spec file. Implementation of action list widget is not specified on facet level. It is left in facet header. A list of action names used in action list can be now specified in facet spec in 'header_actions' attribute. Control buttons use similar concept. Facet by default is using control_buttons_widget. Details and search facet are defining their own default actions (refresh/add/remove/update/reset). Additional buttons can be defined as array of action names on facet level in control_buttons attribute. state_evaluators and state_listeners were united. They are called state_evaluators but they uses state_listener concept, they are attached to an event. For former state_evaluator the event is post_load. They are defined in spec in state attribute. State object purpose is to aggregate states from all state evaluators. It offers changed event to which can other objects subscribe. It also has summary evaluator which evaluation conditions. Summary evaluator creates summary status with human readable description. It can be used by facet header. https://fedorahosted.org/freeipa/ticket/2248
Diffstat (limited to 'install/ui/details.js')
-rw-r--r--install/ui/details.js163
1 files changed, 114 insertions, 49 deletions
diff --git a/install/ui/details.js b/install/ui/details.js
index f1f13f0b4..1282912d5 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -231,57 +231,34 @@ IPA.details_facet = function(spec, no_init) {
spec = spec || {};
spec.name = spec.name || 'details';
- spec.control_buttons = spec.control_buttons || {};
- var cb = spec.control_buttons;
- cb.factory = cb.factory || IPA.control_buttons_widget;
- cb.buttons = cb.buttons || [];
- cb.state_listeners = cb.state_listeners || [];
- cb.buttons.unshift(
+ spec.actions = spec.actions || [];
+ spec.actions.unshift(
+ IPA.refresh_action,
+ IPA.reset_action,
+ IPA.update_action);
+
+ spec.control_buttons = spec.control_buttons || [];
+ spec.control_buttons.unshift(
{
name: 'refresh',
label: IPA.messages.buttons.refresh,
- icon: 'reset-icon',
- action: {
- handler: function(facet) {
- facet.refresh();
- }
- }
+ icon: 'reset-icon'
},
{
name: 'reset',
label: IPA.messages.buttons.reset,
- icon: 'reset-icon',
- needs_confirm: true,
- action: {
- enable_cond: ['dirty'],
- handler: function(facet) {
- facet.reset();
- }
- }
+ icon: 'reset-icon'
},
{
name: 'update',
label: IPA.messages.buttons.update,
- icon: 'update-icon',
- action: {
- enable_cond: ['dirty'],
- handler: function(facet) {
- if (!facet.validate()) {
- facet.show_validation_error();
- return;
- }
+ icon: 'update-icon'
+ });
- facet.update();
- }
- }
- }
- );
- cb.state_listeners.push(
- {
- factory: IPA.dirty_state_listener
- }
- );
+ spec.state = spec.state || {};
+ spec.state.evaluators = spec.state.evaluators || [];
+ spec.state.evaluators.push(IPA.dirty_state_evaluator);
var that = IPA.facet(spec, true);
@@ -476,7 +453,7 @@ IPA.details_facet = function(spec, no_init) {
field.load(data.result.result);
}
that.policies.post_load(data);
- that.post_load.notify();
+ that.post_load.notify([data], that);
that.clear_expired_flag();
};
@@ -719,7 +696,8 @@ IPA.details_facet = function(spec, no_init) {
var widget_builder = IPA.widget_builder({
widget_options: {
- entity: that.entity
+ entity: that.entity,
+ facet: that
}
});
var field_builder = IPA.field_builder({
@@ -872,38 +850,107 @@ IPA.command_builder = function() {
return that;
}();
+IPA.select_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'select_action';
+ spec.label = spec.label || '-- select action --';
+
+ var that = IPA.action(spec);
+
+ that.execute_action = function(facet) {
+ };
+
+ return that;
+};
+
+IPA.refresh_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'refresh';
+ spec.label = spec.label || IPA.messages.buttons.refresh;
+
+ var that = IPA.action(spec);
+
+ that.execute_action = function(facet) {
+ facet.refresh();
+ };
+
+ return that;
+};
+
+IPA.reset_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'reset';
+ spec.label = spec.label || IPA.messages.buttons.reset;
+ spec.enable_cond = spec.enable_cond || ['dirty'];
+
+ var that = IPA.action(spec);
+
+ that.execute_action = function(facet) {
+ facet.reset();
+ };
+
+ return that;
+};
+
+IPA.update_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'update';
+ spec.label = spec.label || IPA.messages.buttons.update;
+ spec.needs_confirm = spec.needs_confirm !== undefined ? spec.needs_confirm : true;
+ spec.enable_cond = spec.enable_cond || ['dirty'];
+
+ var that = IPA.action(spec);
+
+ that.execute_action = function(facet) {
+
+ if (!facet.validate()) {
+ facet.show_validation_error();
+ return;
+ }
+
+ facet.update();
+ };
+
+ return that;
+};
+
IPA.boolean_state_evaluator = function(spec) {
spec = spec || {};
+ spec.event = spec.event || 'post_load';
+
var that = IPA.state_evaluator(spec);
+ that.name = spec.name || 'boolean_state_evaluator';
that.field = spec.field;
that.true_state = spec.true_state || that.field_name + '-true';
that.false_state = spec.false_state || that.field_name + '-false';
- that.true_desc = spec.true_desc || IPA.messages['true'];
- that.false_desc = spec.false_desc || IPA.messages['false'];
that.invert_value = spec.invert_value;
that.parser = IPA.build({
factory: spec.parser || IPA.boolean_formatter,
invert_value: that.invert_value
});
- that.evaluate = function(record) {
+ that.on_event = function(data) {
+ var old_state = that.state;
+ var record = data.result.result;
that.state = [];
var value = that.parser.parse(record[that.field]);
if (value === true) {
that.state.push(that.true_state);
- that.description = that.true_desc;
} else {
that.state.push(that.false_state);
- that.description = that.false_desc;
}
- return that.state;
+ that.notify_on_change(old_state);
};
return that;
@@ -912,10 +959,9 @@ IPA.boolean_state_evaluator = function(spec) {
IPA.enable_state_evaluator = function(spec) {
spec = spec || {};
+ spec.name = spec.name || 'enable_state_evaluator';
spec.true_state = spec.true_state || 'enabled';
spec.false_state = spec.false_state || 'disabled';
- spec.true_desc = spec.true_desc || IPA.messages.status.enabled;
- spec.false_desc = spec.false_desc || IPA.messages.status.disabled;
var that = IPA.boolean_state_evaluator(spec);
@@ -931,7 +977,7 @@ IPA.object_action = function(spec) {
that.method = spec.method;
that.confirm_msg = spec.confirm_msg || IPA.messages.actions.confirm;
- that.execute = function(facet, on_success, on_error) {
+ that.execute_action = function(facet, on_success, on_error) {
var entity_name = facet.entity.name;
var pkey = IPA.nav.get_state(entity_name+'-pkey');
@@ -1021,3 +1067,22 @@ IPA.delete_action = function(spec) {
return that;
};
+
+
+IPA.enabled_summary_cond = function() {
+ return {
+ pos: ['enabled'],
+ neg: [],
+ description: IPA.messages.status.enabled,
+ state: ['enabled']
+ };
+};
+
+IPA.disabled_summary_cond = function() {
+ return {
+ pos: [],
+ neg: ['enabled'],
+ description: IPA.messages.status.disabled,
+ state: ['disabled']
+ };
+};