From f99ab781ea33f0d7ca6df26090cd99f9315454ac Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 28 Sep 2011 15:56:25 -0500 Subject: Disable enroll button if nothing selected. A new IPA.dialog_button class has been added to encapsulate the buttons in the dialog box so they can be managed more easily. The adder dialog has been modified to disable the enroll button if there is no entries selected. Ticket #1856 --- install/ui/dialog.js | 137 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 119 insertions(+), 18 deletions(-) (limited to 'install/ui/dialog.js') diff --git a/install/ui/dialog.js b/install/ui/dialog.js index 50bb194b..d291120e 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -21,6 +21,34 @@ /* REQUIRES: widget.js */ +IPA.dialog_button = function(spec) { + + spec = spec || {}; + + var that = {}; + + that.name = spec.name; + that.label = spec.label || spec.name; + that.click = spec.click || click; + + function click() { + } + + that.set_enabled = function(enabled) { + if (enabled) { + that.element.removeClass('ui-state-disabled'); + } else { + that.element.addClass('ui-state-disabled'); + } + }; + + that.is_enabled = function() { + return !that.element.hasClass('ui-state-disabled'); + }; + + return that; +}; + /** * This is a base class for dialog boxes. */ @@ -37,7 +65,7 @@ IPA.dialog = function(spec) { that.width = spec.width || 500; that.height = spec.height; - that.buttons = {}; + that.buttons = $.ordered_map(); that.sections = $.ordered_map(); @@ -57,8 +85,19 @@ IPA.dialog = function(spec) { section.add_fields(fields); }; - that.add_button = function(name, handler) { - that.buttons[name] = handler; + that.create_button = function(spec) { + var factory = spec.factory || IPA.dialog_button; + var button = factory(spec); + that.add_button(button); + return button; + }; + + that.add_button = function(button) { + that.buttons.put(button.name, button); + }; + + that.get_button = function(name) { + return that.buttons.get(name); }; that.get_field = function(name) { @@ -173,6 +212,13 @@ IPA.dialog = function(spec) { that.create(); that.reset(); + // create a map of button labels and handlers + var dialog_buttons = {}; + for (var i=0; i').appendTo(buttons_panel); - that.add_button = IPA.button({ + IPA.button({ name: 'add', label: '>>', click: function() { that.add(); + that.update_buttons(); return false; } }).appendTo(p); p = $('

').appendTo(buttons_panel); - that.remove_button = IPA.button({ + IPA.button({ name: 'remove', label: '<<', click: function() { that.remove(); + that.update_buttons(); return false; } }).appendTo(p); @@ -422,10 +480,26 @@ IPA.adder_dialog = function(spec) { that.open = function(container) { - that.buttons[IPA.messages.buttons.enroll] = that.execute; - that.buttons[IPA.messages.buttons.cancel] = that.close; + var add_button = that.create_button({ + name: 'add', + label: IPA.messages.buttons.enroll, + click: function() { + if (!add_button.is_enabled()) return; + that.execute(); + } + }); + + that.create_button({ + name: 'cancel', + label: IPA.messages.buttons.cancel, + click: function() { + that.close(); + } + }); that.dialog_open(container); + + that.update_buttons(); }; that.add = function() { @@ -438,12 +512,16 @@ IPA.adder_dialog = function(spec) { that.available_table.add_rows(rows); }; - that.get_filter = function() { - return that.filter_field.val(); + that.update_buttons = function() { + + var values = that.selected_table.save(); + + var button = that.get_button('add'); + button.set_enabled(values && values.length); }; - that.get_hide_checkbox = function() { - return that.hide_checkbox.checked; + that.get_filter = function() { + return that.filter_field.val(); }; that.clear_available_values = function() { @@ -462,6 +540,9 @@ IPA.adder_dialog = function(spec) { return that.selected_table.save(); }; + that.execute = function() { + }; + init(); that.adder_dialog_create = that.create; @@ -528,12 +609,28 @@ IPA.deleter_dialog = function (spec) { that.open = function(container) { - that.buttons[IPA.messages.buttons.remove] = that.execute; - that.buttons[IPA.messages.buttons.cancel] = that.close; + that.create_button({ + name: 'remove', + label: IPA.messages.buttons.remove, + click: function() { + that.execute(); + } + }); + + that.create_button({ + name: 'cancel', + label: IPA.messages.buttons.cancel, + click: function() { + that.close(); + } + }); that.dialog_open(container); }; + that.execute = function() { + }; + that.deleter_dialog_create = that.create; return that; @@ -555,10 +652,14 @@ IPA.message_dialog = function(spec) { }).appendTo(that.container); }; - that.add_button(IPA.messages.buttons.ok, function() { - that.close(); - if(that.on_ok) { - that.on_ok(); + that.create_button({ + name: 'ok', + label: IPA.messages.buttons.ok, + click: function() { + that.close(); + if(that.on_ok) { + that.on_ok(); + } } }); -- cgit