summaryrefslogtreecommitdiffstats
path: root/install/ui
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-04-30 15:02:41 +0200
committerPetr Vobornik <pvoborni@redhat.com>2012-05-11 18:30:48 +0200
commit719b09fb4edf990beb07ab72bcd4d5e102975637 (patch)
tree733e69a319cf0ec8233f25debfb0eba5074b113d /install/ui
parent2c11dcda258cdbbc0949185f4c7ca5c2854c8352 (diff)
downloadfreeipa-719b09fb4edf990beb07ab72bcd4d5e102975637.tar.gz
freeipa-719b09fb4edf990beb07ab72bcd4d5e102975637.tar.xz
freeipa-719b09fb4edf990beb07ab72bcd4d5e102975637.zip
General details facet actions
This patch adds common action button actions for enabling/disabling/deleting object. https://fedorahosted.org/freeipa/ticket/2707
Diffstat (limited to 'install/ui')
-rw-r--r--install/ui/details.js150
-rw-r--r--install/ui/ipa.css17
-rw-r--r--install/ui/test/data/ipa_init.json2
3 files changed, 169 insertions, 0 deletions
diff --git a/install/ui/details.js b/install/ui/details.js
index 89d198864..f1f13f0b4 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -871,3 +871,153 @@ IPA.command_builder = function() {
return that;
}();
+
+IPA.boolean_state_evaluator = function(spec) {
+
+ spec = spec || {};
+
+ var that = IPA.state_evaluator(spec);
+
+ 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.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;
+ };
+
+ return that;
+};
+
+IPA.enable_state_evaluator = function(spec) {
+
+ spec = spec || {};
+ 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);
+
+ return that;
+};
+
+IPA.object_action = function(spec) {
+
+ spec = spec || {};
+
+ var that = IPA.action(spec);
+
+ that.method = spec.method;
+ that.confirm_msg = spec.confirm_msg || IPA.messages.actions.confirm;
+
+ that.execute = function(facet, on_success, on_error) {
+
+ var entity_name = facet.entity.name;
+ var pkey = IPA.nav.get_state(entity_name+'-pkey');
+
+ if (that.needs_confirm && !that.confirm_object(pkey)) return;
+
+ IPA.command({
+ entity: entity_name,
+ method: that.method,
+ args: [pkey],
+ on_success: that.get_on_success(facet, on_success),
+ on_error: that.get_on_error(facet, on_error)
+ }).execute();
+ };
+
+ that.on_success = function(facet, data, text_status, xhr) {
+ facet.on_update.notify();
+ };
+
+ that.on_error = function(facet, xhr, text_status, error_thrown) {
+ };
+
+ that.get_on_success = function(facet, on_success) {
+ return function(data, text_status, xhr) {
+ that.on_success(facet, data, text_status, xhr);
+ if (on_success) on_success.call(this, data, text_status, xhr);
+ };
+ };
+
+ that.get_on_error = function(facet, on_error) {
+ return function(xhr, text_status, error_thrown) {
+ that.on_error(facet, xhr, text_status, error_thrown);
+ if (on_error) on_error.call(this, xhr, text_status, error_thrown);
+ };
+ };
+
+ that.confirm_object = function(obj_name) {
+ var msg = that.confirm_msg.replace('${object}', obj_name);
+ return IPA.confirm(msg);
+ };
+
+ return that;
+};
+
+IPA.enable_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'enable';
+ spec.method = spec.method || 'enable';
+ spec.confirm_msg = spec.confirm_msg || IPA.messages.actions.enable_confirm;
+ spec.label = spec.label || IPA.messages.buttons.enable;
+ spec.disable_cond = spec.disable_cond || ['enabled'];
+
+ var that = IPA.object_action(spec);
+
+ return that;
+};
+
+IPA.disable_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'disable';
+ spec.method = spec.method || 'disable';
+ spec.confirm_msg = spec.confirm_msg || IPA.messages.actions.disable_confirm;
+ spec.label = spec.label || IPA.messages.buttons.disable;
+ spec.enable_cond = spec.enable_cond || ['enabled'];
+
+ var that = IPA.object_action(spec);
+
+ return that;
+};
+
+IPA.delete_action = function(spec) {
+
+ spec = spec || {};
+ spec.name = spec.name || 'delete';
+ spec.method = spec.method || 'del';
+ spec.confirm_msg = spec.confirm_msg || IPA.messages.actions.delete_confirm;
+ spec.label = spec.label || IPA.messages.buttons.remove;
+
+ var that = IPA.object_action(spec);
+
+ that.on_success = function(facet, data, text_status, xhr) {
+ facet.on_update.notify();
+ facet.redirect();
+ };
+
+ return that;
+};
diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index d83c7e148..97cfca0e8 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -1692,3 +1692,20 @@ form#login {
width: 17px;
height: 17px;
}
+
+.facet-title.enabled .header-icon {
+ background-image: url(images/ui-icons_222222_256x240.png);
+ background-position: -64px -144px;
+ display: inline-block;
+}
+
+.facet-title.disabled .header-icon {
+ background-image: url(images/ui-icons_bbbbbb_256x240.png);
+ background-position: -64px -128px;
+ display: inline-block;
+}
+
+.facet-title.disabled h3,
+.facet-title.disabled h3 .facet-pkey{
+ color: gray;
+} \ No newline at end of file
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 333cb19a3..8257d27c7 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -55,7 +55,9 @@
"back": "Back",
"cancel": "Cancel",
"close": "Close",
+ "disable": "Disable",
"edit": "Edit",
+ "enable": "Enable",
"find": "Find",
"get": "Get",
"issue": "Issue",