From eeac88238ab6bca8098b1792532d8f40373b5ea5 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Wed, 25 Apr 2012 14:28:17 +0200 Subject: 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 --- install/ui/facet.js | 113 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 42 deletions(-) (limited to 'install/ui/facet.js') diff --git a/install/ui/facet.js b/install/ui/facet.js index 1c220d03..64d4f5d2 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 -1) { - return false; - } + var i, cond; + + if (disable_cond) { + for (i=0; i -1) { + return false; } } + } - if (action.enable_cond) { - for (i=0; i -1) { - return false; - } - } - } - - if (action.enable_cond) { - for (i=0; i