From 2ca280c56dc14710572d77dfc858b9382d1c14bb Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Wed, 17 Jul 2013 21:13:42 +0200 Subject: Honor 'enabled' option for widgets. https://fedorahosted.org/freeipa/ticket/3793 --- install/ui/src/freeipa/association.js | 1 - install/ui/src/freeipa/dns.js | 3 +- install/ui/src/freeipa/facet.js | 2 +- install/ui/src/freeipa/rule.js | 2 - install/ui/src/freeipa/widget.js | 142 ++++++++++++++++++++++------------ 5 files changed, 93 insertions(+), 57 deletions(-) (limited to 'install') diff --git a/install/ui/src/freeipa/association.js b/install/ui/src/freeipa/association.js index c60c7b8a..ad427d66 100644 --- a/install/ui/src/freeipa/association.js +++ b/install/ui/src/freeipa/association.js @@ -530,7 +530,6 @@ IPA.association_table_widget = function (spec) { $('.action-button', that.table).addClass('action-button-disabled'); that.unselect_all(); } - that.enabled = enabled; }; that.select_changed = function() { diff --git a/install/ui/src/freeipa/dns.js b/install/ui/src/freeipa/dns.js index b4085fea..0a0fd3f8 100644 --- a/install/ui/src/freeipa/dns.js +++ b/install/ui/src/freeipa/dns.js @@ -603,7 +603,7 @@ IPA.dnszone_adder_dialog = function(spec) { var zone = zone_w.save()[0] || ''; var ns = ns_w.save()[0] || ''; - var zone_is_reverse = !zone_w.is_enabled() || + var zone_is_reverse = !zone_w.enabled || ends_with(zone, '.in-addr.arpa.') || ends_with(zone, '.ip6.arpa.'); var relative_ns = true; @@ -1767,7 +1767,6 @@ IPA.dns.record_type_table_widget = function(spec) { $('.action-button', that.table).addClass('action-button-disabled'); that.unselect_all(); } - that.enabled = enabled; }; that.select_changed = function() { diff --git a/install/ui/src/freeipa/facet.js b/install/ui/src/freeipa/facet.js index 37106e22..b01452dd 100644 --- a/install/ui/src/freeipa/facet.js +++ b/install/ui/src/freeipa/facet.js @@ -1940,7 +1940,7 @@ exp.action_button_widget = IPA.action_button_widget = function(spec) { }; that.set_enabled = function(enabled) { - that.enabled = enabled; + that.widget_set_enabled(enabled); if (that.button_element) { if (enabled) { diff --git a/install/ui/src/freeipa/rule.js b/install/ui/src/freeipa/rule.js index f573b56d..332342bf 100644 --- a/install/ui/src/freeipa/rule.js +++ b/install/ui/src/freeipa/rule.js @@ -112,8 +112,6 @@ IPA.rule_association_table_widget = function(spec) { that.external = spec.external; - that.enabled = spec.enabled !== undefined ? spec.enabled : true; - that.setup_column = function(column, div, record) { var suppress_link = false; if (that.external) { diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index 06fcef56..d66468ae 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -51,6 +51,7 @@ IPA.widget = function(spec) { that.measurement_unit = spec.measurement_unit; that.entity = IPA.get_entity(spec.entity); //some old widgets still need it that.facet = spec.facet; + that.enabled = spec.enabled === undefined ? true : spec.enabled; that.create = function(container) { container.addClass('widget'); @@ -60,6 +61,10 @@ IPA.widget = function(spec) { that.clear = function() { }; + that.set_enabled = function(value) { + that.enabled = value; + }; + that.set_visible = function(visible) { if (visible) { @@ -81,6 +86,7 @@ IPA.widget = function(spec) { }; that.widget_create = that.create; + that.widget_set_enabled = that.set_enabled; return that; }; @@ -200,6 +206,14 @@ IPA.input_widget = function(spec) { } }; + that.set_enabled = function(value) { + that.widget_set_enabled(value); + + if (that.input) { + that.input.prop('disabled', !value); + } + }; + that.on_value_changed = function() { var value = that.save(); that.value_changed.notify([value], that); @@ -257,7 +271,6 @@ IPA.text_widget = function(spec) { that.input = $('', { type: that.input_type, name: that.name, - disabled: that.disabled, size: that.size, title: that.tooltip, keyup: function() { @@ -274,6 +287,7 @@ IPA.text_widget = function(spec) { } that.create_error_link(container); + that.set_enabled(that.enabled); }; that.update = function(values) { @@ -303,15 +317,6 @@ IPA.text_widget = function(spec) { } }; - that.is_enabled = function(value) { - return !that.input.prop('disabled'); - }; - - that.set_enabled = function(value) { - - that.input.prop('disabled', !value); - }; - that.clear = function() { that.input.val(''); that.display_control.text(''); @@ -474,7 +479,8 @@ IPA.multivalued_widget = function(spec) { name: that.name+'-'+row_index, undo: that.undo || row.is_new, read_only: that.read_only, - writable: that.writable + writable: that.writable, + enabled: that.enabled }); row.widget.create(row.container); @@ -756,6 +762,8 @@ IPA.option_widget_base = function(spec, that) { that._child_widgets.push(option.widget); } } + + option.enabled = spec.enabled === undefined ? true : spec.enabled; option.label = text.get(option.label); option.combine_values = option.combine_values === undefined ? true : !!option.combine_values; @@ -794,11 +802,13 @@ IPA.option_widget_base = function(spec, that) { that._create_option = function(option, container) { var input_name = that.get_input_name(); var id = that._option_next_id + input_name; + var enabled = that.enabled && option.enabled; $('', { id: id, type: that.input_type, name: input_name, + disabled: !enabled, value: option.value, title: option.tooltip || that.tooltip, change: that.on_input_change @@ -900,7 +910,7 @@ IPA.option_widget_base = function(spec, that) { var parents_selected = []; - $(that._selector+':checked', that.container).each(function() { + $(that._selector+':checked', that.$node).each(function() { var value = $(this).val(); var option = that.get_option(value); if (option && option.nested) { @@ -914,7 +924,7 @@ IPA.option_widget_base = function(spec, that) { if (option.nested) { var selected = parents_selected.indexOf(option.value) > -1; - option.widget.set_enabled(selected, true); + option.widget.update_enabled(selected, true); } } } @@ -927,7 +937,7 @@ IPA.option_widget_base = function(spec, that) { if (that.$node) { - $(that._selector+':checked', that.container).each(function() { + $(that._selector+':checked', that.$node).each(function() { var value = $(this).val(); var child_values = []; var option = that.get_option(value); @@ -958,9 +968,9 @@ IPA.option_widget_base = function(spec, that) { // uncheck all inputs check(that._selector, true /*uncheck*/); - var writable = !that.read_only && !!that.writable; + var writable = !that.read_only && !!that.writable && that.enabled; if (!that.nested) { - that.set_enabled(writable); + that.update_enabled(writable); } if (values && values.length > 0) { @@ -986,7 +996,7 @@ IPA.option_widget_base = function(spec, that) { check(that._selector+'[value="'+ option.value +'"]'); } if (option.widget) { - option.widget.set_enabled(writable && has_opt, false); + option.widget.update_enabled(writable && has_opt, false); } } } else { @@ -1003,6 +1013,7 @@ IPA.option_widget_base = function(spec, that) { var widget = that._child_widgets[j]; widget.writable = that.writable; widget.read_only = that.read_only; + widget.enabled = that.enabled; widget.update(values); } } @@ -1010,12 +1021,22 @@ IPA.option_widget_base = function(spec, that) { that.updated.notify([], that); }; - that.set_enabled = function(enabled, clear) { + that.set_enabled = function(enabled) { + + that.enabled = enabled; + that.update_enabled(enabled); + }; + + that.update_enabled = function(enabled, clear) { + + if (!that.$node) return; + + $(that._selector, that.$node).prop('disabled', !enabled); - $(that._selector, that.container).prop('disabled', !enabled); if (!enabled && clear) that.clear(); + for (var i=0; i', { 'class': 'certificate', - readonly: that.read_only + readonly: that.read_only, + disabled: !that.enabled }).appendTo(dialog.container); var key = that.key.key || ''; @@ -3868,7 +3908,7 @@ IPA.action_panel = function(spec) { if (!action.visible) return; classes = ['action']; - state = action.enabled ? 'enabled' : 'disabled'; + state = action.enabled && that.enabled ? 'enabled' : 'disabled'; classes.push(state); li = $('
  • '); @@ -3908,7 +3948,7 @@ IPA.action_panel = function(spec) { that.action_clicked = function(action) { - if (!action.enabled || !action.visible) return; + if (!that.enabled || !action.enabled || !action.visible) return; action.execute(that.facet); }; -- cgit