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.
--
Petr Vobornik
From 39283e12d8f820842e9f3a8233c32779a298bafb Mon Sep 17 00:00:00 2001
From: Petr Vobornik pvobo...@redhat.com
Date: Thu, 10 Jul 2014 12:02:51 +0200
Subject: [PATCH] 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.
---
install/ui/src/freeipa/widget.js | 76
1 file changed, 46 insertions(+), 30 deletions(-)
diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js
index 79f814552f450645681dfc35c2ad1fe00433d4d0..92abcb179fa5d76a427de3f54dcfab808c76e8fd 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; ivalues.length; i++) {
-if (values[i] === '') {
-values[i] = that.default_value;
-}
+// use default value if none supplied
+var def_used = false;
+if (values values.length 0 that.default_on_empty
+that.default_value !== null) {
+for (i=0; ivalues.length; i++) {
+if (values[i] === '') {
+values[i] = that.default_value;
+def_used = true;
}
}
+} else if (!values || !values.length) {
+var default_value = that.default_value || '';
+values = [default_value];
+def_used = true;
+}
-// check the option when option or some of its child should be
-// checked
-for (i=0; ithat.options.length; i++) {
-var option = that.options[i];
-var opt_vals = that.get_values(option);
-var has_opt = array.some(values, function(val) {
-return array.indexOf(opt_vals, val) -1;
-});
+// check the option if it or some of its children should be checked
+for (i=0; ithat.options.length; i++) {
+var option = that.options[i];
+var opt_vals = that.get_values(option);
+var has_opt = array.some(values, function(val) {
+return array.indexOf(opt_vals, val) -1;
+});
-if (has_opt) {
-check(that._selector+'[value='+ option.value +']');
-}
-if (option.widget) {
-option.widget.update_enabled(writable has_opt, false);
-}
+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+']');
-