summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-04-25 14:28:17 +0200
committerPetr Vobornik <pvoborni@redhat.com>2012-05-11 18:30:48 +0200
commiteeac88238ab6bca8098b1792532d8f40373b5ea5 (patch)
tree76d5e6009b822c49b8b7de913a4c2c41c493f238
parent29059cd45d84b61c3b5799124ec93cee4b8ac63b (diff)
downloadfreeipa-eeac88238ab6bca8098b1792532d8f40373b5ea5.tar.gz
freeipa-eeac88238ab6bca8098b1792532d8f40373b5ea5.tar.xz
freeipa-eeac88238ab6bca8098b1792532d8f40373b5ea5.zip
Hide search facet add/delete buttons in self-service
Adds hiding/showing capabilities to action_button_widget. This patch is fixing regression caused replacing old details facet buttons with control_buttons_widget. The problem was that some buttons were not hidden in self-service mode. https://fedorahosted.org/freeipa/ticket/2707
-rw-r--r--install/ui/details.js1
-rw-r--r--install/ui/facet.js113
-rw-r--r--install/ui/search.js8
3 files changed, 78 insertions, 44 deletions
diff --git a/install/ui/details.js b/install/ui/details.js
index 746379f86..89d198864 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -476,6 +476,7 @@ IPA.details_facet = function(spec, no_init) {
field.load(data.result.result);
}
that.policies.post_load(data);
+ that.post_load.notify();
that.clear_expired_flag();
};
diff --git a/install/ui/facet.js b/install/ui/facet.js
index 1c220d032..64d4f5d2a 100644
--- a/install/ui/facet.js
+++ b/install/ui/facet.js
@@ -50,6 +50,7 @@ IPA.facet = function(spec, no_init) {
that.last_updated = null;
that.expire_timeout = spec.expire_timeout || 600; //[seconds]
that.on_update = IPA.observer();
+ that.post_load = IPA.observer();
that.dialogs = $.ordered_map();
@@ -754,6 +755,7 @@ IPA.table_facet = function(spec, no_init) {
that.table.pagination_control.css('visibility', 'visible');
+ that.post_load.notify();
that.clear_expired_flag();
};
@@ -1317,6 +1319,29 @@ IPA.selected_state_listener = function(spec) {
return that;
};
+IPA.self_service_state_listener = function(spec) {
+
+ spec = spec || {};
+
+ spec.event = spec.event || 'post_load';
+
+ var that = IPA.state_listener(spec);
+
+ that.on_event = function() {
+ that.state = [];
+
+ var self_service = IPA.nav.name === 'self-service';
+
+ if (self_service) {
+ that.state.push('self-service');
+ }
+
+ that.state_changed.notify();
+ };
+
+ return that;
+};
+
IPA.action_button_widget = function(spec) {
spec = spec || {};
@@ -1335,6 +1360,10 @@ IPA.action_button_widget = function(spec) {
that.action = IPA.build(spec.action, IPA.action_builder);
that.enabled = spec.enabled !== undefined ? spec.enabled : true;
+ that.visible = spec.visible !== undefined ? spec.visible : true;
+
+ that.show_cond = spec.show_cond || [];
+ that.hide_cond = spec.hide_cond || [];
that.create = function(container) {
@@ -1352,6 +1381,7 @@ IPA.action_button_widget = function(spec) {
}).appendTo(container);
that.set_enabled(that.enabled);
+ that.set_visible(that.visible);
};
that.on_click = function() {
@@ -1400,6 +1430,19 @@ IPA.action_button_widget = function(spec) {
}
};
+ that.set_visible = function(visible) {
+
+ that.visible = visible;
+
+ if (that.button_element) {
+ if (visible) {
+ that.button_element.show();
+ } else {
+ that.button_element.hide();
+ }
+ }
+ };
+
return that;
};
@@ -1458,7 +1501,7 @@ IPA.control_buttons_widget = function(spec) {
that.on_state_change = function() {
that.get_state();
- that.reevaluate_enabled();
+ that.reevaluate();
};
that.get_state = function() {
@@ -1472,42 +1515,45 @@ IPA.control_buttons_widget = function(spec) {
}
};
- that.reevaluate_enabled = function() {
+ that.reevaluate = function() {
for (var i=0; i<that.buttons.length; i++) {
var button = that.buttons[i];
- var enabled = that.action_enabled(button.action);
+ var action = button.action;
+ var enabled = IPA.eval_cond(action.enable_cond, action.disable_cond, that.state);
+ var visible = IPA.eval_cond(button.show_cond, button.hide_cond, that.state);
button.set_enabled(enabled);
+ button.set_visible(visible);
}
};
- that.action_enabled = function(action) {
+ return that;
+};
- var i, cond;
+IPA.eval_cond = function(enable_cond, disable_cond, state) {
- if (action.disable_cond) {
- for (i=0; i<action.disable_cond.length; i++) {
- cond = action.disable_cond[i];
- if (that.state.indexOf(cond) > -1) {
- return false;
- }
+ var i, cond;
+
+ if (disable_cond) {
+ for (i=0; i<disable_cond.length; i++) {
+ cond = disable_cond[i];
+ if (state.indexOf(cond) > -1) {
+ return false;
}
}
+ }
- if (action.enable_cond) {
- for (i=0; i<action.enable_cond.length; i++) {
- cond = action.enable_cond[i];
- if (that.state.indexOf(cond) < 0) {
- return false;
- }
+ if (enable_cond) {
+ for (i=0; i<enable_cond.length; i++) {
+ cond = enable_cond[i];
+ if (state.indexOf(cond) < 0) {
+ return false;
}
}
+ }
- return true;
- };
-
- return that;
+ return true;
};
@@ -1632,27 +1678,10 @@ IPA.action_list_widget = function(spec) {
that.action_enabled = function(action) {
- var i, cond;
-
- if (action.disable_cond) {
- for (i=0; i<action.disable_cond.length; i++) {
- cond = action.disable_cond[i];
- if (that.state.indexOf(cond) > -1) {
- return false;
- }
- }
- }
-
- if (action.enable_cond) {
- for (i=0; i<action.enable_cond.length; i++) {
- cond = action.enable_cond[i];
- if (that.state.indexOf(cond) < 0) {
- return false;
- }
- }
- }
-
- return true;
+ var enabled = IPA.eval_cond(action.enable_cond,
+ action.disable_cond,
+ that.state);
+ return enabled;
};
that.select_first_enabled = function() {
diff --git a/install/ui/search.js b/install/ui/search.js
index 142e590db..50a5fa0ec 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -58,9 +58,10 @@ IPA.search_facet = function(spec, no_init) {
name: 'remove',
label: IPA.messages.buttons.remove,
icon: 'remove-icon',
+ needs_confirm: true,
+ hide_cond: ['self-service'],
action: {
enable_cond: ['item-selected'],
- disable_cond: ['self-service'],
handler: function(facet) {
facet.show_remove_dialog();
}
@@ -70,8 +71,8 @@ IPA.search_facet = function(spec, no_init) {
name: 'add',
label: IPA.messages.buttons.add,
icon: 'add-icon',
+ hide_cond: ['self-service'],
action: {
- disable_cond: ['self-service'],
handler: function(facet) {
facet.show_add_dialog();
}
@@ -81,6 +82,9 @@ IPA.search_facet = function(spec, no_init) {
cb.state_listeners.push(
{
factory: IPA.selected_state_listener
+ },
+ {
+ factory: IPA.self_service_state_listener
}
);