From 0da0fc4322bd2be03f3889312dd3f9d256f493a3 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Tue, 17 Sep 2013 10:48:24 +0200 Subject: Added empty value meaning to boolean formatter Boolean object properties can have different default meaning for not defined value. This patch allows to defined this meaning to `boolean_formatter` by introduction of `emty_value` property. `boolean_state_evaluator` was modified to leverage it as well. --- install/ui/src/freeipa/details.js | 10 +++++++--- install/ui/src/freeipa/widget.js | 14 +++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'install/ui/src') diff --git a/install/ui/src/freeipa/details.js b/install/ui/src/freeipa/details.js index 00134a23d..907eae47c 100644 --- a/install/ui/src/freeipa/details.js +++ b/install/ui/src/freeipa/details.js @@ -1490,17 +1490,21 @@ exp.boolean_state_evaluator = IPA.boolean_state_evaluator = function(spec) { that.false_state = spec.false_state || that.field_name + '-false'; /** - * Inverted logic + * Inverts evaluation logic + * + * NOTE: is ignored when custom parser is set + * * @property {boolean} */ that.invert_value = spec.invert_value; /** * Value parser + * * @property {IPA.boolean_formatter} */ - that.parser = IPA.build({ - $factory: spec.parser || IPA.boolean_formatter, + that.parser = IPA.build(spec.parser || { + $factory: IPA.boolean_formatter, invert_value: that.invert_value }); diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index 9ea5ea0e0..b3ea3a838 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -1838,14 +1838,26 @@ IPA.boolean_formatter = function(spec) { that.show_false = spec.show_false; /** Parse return inverted value */ that.invert_value = spec.invert_value; + /** + * Result of parse of `undefined` or `null` value will be `empty_value` + * if set. + * @property {boolean|undefined} + */ + that.empty_value = spec.empty_value; /** * Convert string boolean value into real boolean value, or keep * the original value + * + * @param {Mixed} value Value to parse + * @return {boolean|""} */ that.parse = function(value) { - if (value === undefined || value === null) return ''; + if (value === undefined || value === null) { + if (that.empty_value !== undefined) value = that.empty_value; + else return ''; + } if (value instanceof Array) { value = value[0]; -- cgit