diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2012-04-25 14:28:17 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2012-05-11 18:30:48 +0200 |
commit | eeac88238ab6bca8098b1792532d8f40373b5ea5 (patch) | |
tree | 76d5e6009b822c49b8b7de913a4c2c41c493f238 /install/ui/facet.js | |
parent | 29059cd45d84b61c3b5799124ec93cee4b8ac63b (diff) | |
download | freeipa-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
Diffstat (limited to 'install/ui/facet.js')
-rw-r--r-- | install/ui/facet.js | 113 |
1 files changed, 71 insertions, 42 deletions
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() { |