From ad593a5c06d447006f14446cbdfbf5b437a0d111 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Thu, 10 Jul 2014 12:02:51 +0200 Subject: webui: fix disabled state of service's PAC type Nested options (MS-PAC and PAD) of service's PAC type should be disabled if no value is supplied (default value is "Inherited from server configuration"). That was not the case - regression. This patch fixes it and along with it simplifies the update method of option_widget_base to be more comprehensible. Reviewed-By: Endi Sukma Dewata --- install/ui/src/freeipa/widget.js | 78 ++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index 79f814552..92abcb179 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -1316,7 +1316,17 @@ IPA.option_widget_base = function(spec, that) { that.tooltip = spec.tooltip; that.sort = spec.sort === undefined ? false : spec.sort; that.value_changed = that.value_changed || IPA.observer(); + + /** + * Value which should be check when no value supplied + * @type {string|null} + */ that.default_value = spec.default_value || null; + + /** + * Consider empty string as non-value -> enable setting default value in such case + * @type {string} + */ that.default_on_empty = spec.default_on_empty === undefined ? true : spec.default_on_empty; /** @@ -1625,6 +1635,8 @@ IPA.option_widget_base = function(spec, that) { that.update = function(values) { + var i; + var check = function(selector, uncheck) { $(selector, that.$node).prop('checked', !uncheck); }; @@ -1634,49 +1646,48 @@ IPA.option_widget_base = function(spec, that) { // uncheck all inputs check(that._selector, true /*uncheck*/); + // enable/disable the inputs and their children + // they might be disabled later if not checked var writable = !that.read_only && !!that.writable && that.enabled; if (!that.nested) { that.update_enabled(writable); } - if (values && values.length > 0) { - - if (that.default_on_empty && that.default_value !== null) { - for (var i=0; i 0 && that.default_on_empty && + that.default_value !== null) { + for (i=0; i -1; - }); - - if (has_opt) { - check(that._selector+'[value="'+ option.value +'"]'); - } - if (option.widget) { - option.widget.update_enabled(writable && has_opt, false); - } + // check the option if it or some of its children should be checked + for (i=0; i -1; + }); + + if (has_opt) { + check(that._selector+'[value="'+ option.value +'"]'); } - } else { - // select default if none specified - if (that.default_value !== null) { - check(that._selector+'[value="'+that.default_value+'"]'); - // default was selected instead of supplied value, hence notify - util.emit_delayed(that, 'value-change', { source: that }); - } else { - // otherwise select empty - check(that._selector+'[value=""]'); + + // disable options without value + if (option.widget && !has_opt) { + option.widget.update_enabled(false); } } + // update nested for (var j=0; j