diff options
author | Endi S. Dewata <edewata@redhat.com> | 2011-09-28 15:56:25 -0500 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2011-09-29 16:57:19 +0000 |
commit | f99ab781ea33f0d7ca6df26090cd99f9315454ac (patch) | |
tree | 548558b589a656503eeb50aa090eed3a45b6f8e4 /install/ui/dialog.js | |
parent | ecb58275e30f215143c57bdf96094103c8fda7ba (diff) | |
download | freeipa-f99ab781ea33f0d7ca6df26090cd99f9315454ac.tar.gz freeipa-f99ab781ea33f0d7ca6df26090cd99f9315454ac.tar.xz freeipa-f99ab781ea33f0d7ca6df26090cd99f9315454ac.zip |
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
Diffstat (limited to 'install/ui/dialog.js')
-rw-r--r-- | install/ui/dialog.js | 137 |
1 files changed, 119 insertions, 18 deletions
diff --git a/install/ui/dialog.js b/install/ui/dialog.js index 50bb194b3..d291120ea 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<that.buttons.values.length; i++) { + var button = that.buttons.values[i]; + dialog_buttons[button.label] = button.click; + } + that.container.dialog({ title: that.title, modal: true, @@ -180,11 +226,20 @@ IPA.dialog = function(spec) { minWidth: that.width, height: that.height, minHeight: that.height, - buttons: that.buttons, + buttons: dialog_buttons, close: function(event, ui) { that.close(); } }); + + // find button elements + var parent = that.container.parent(); + var buttons = $('.ui-dialog-buttonpane .ui-dialog-buttonset button', parent); + + buttons.each(function(index) { + var button = that.buttons.values[index]; + button.element = $(this); + }); }; that.option = function(name, value) { @@ -231,6 +286,7 @@ IPA.adder_dialog = function(spec) { spec = spec || {}; var that = IPA.dialog(spec); + that.external = spec.external; that.width = spec.width || 600; that.height = spec.height || 360; @@ -373,21 +429,23 @@ IPA.adder_dialog = function(spec) { }).appendTo(container); var p = $('<p/>').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 = $('<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(); + } } }); |