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.

Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
This commit is contained in:
Petr Vobornik
2013-09-17 10:48:24 +02:00
committed by Petr Viktorin
parent d6a7923f71
commit 9e6cc48be6
2 changed files with 20 additions and 4 deletions

View File

@@ -1490,17 +1490,21 @@ exp.boolean_state_evaluator = IPA.boolean_state_evaluator = function(spec) {
that.false_state = spec.false_state || that.field_name + '-false'; 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} * @property {boolean}
*/ */
that.invert_value = spec.invert_value; that.invert_value = spec.invert_value;
/** /**
* Value parser * Value parser
*
* @property {IPA.boolean_formatter} * @property {IPA.boolean_formatter}
*/ */
that.parser = IPA.build({ that.parser = IPA.build(spec.parser || {
$factory: spec.parser || IPA.boolean_formatter, $factory: IPA.boolean_formatter,
invert_value: that.invert_value invert_value: that.invert_value
}); });

View File

@@ -1838,14 +1838,26 @@ IPA.boolean_formatter = function(spec) {
that.show_false = spec.show_false; that.show_false = spec.show_false;
/** Parse return inverted value */ /** Parse return inverted value */
that.invert_value = spec.invert_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 * Convert string boolean value into real boolean value, or keep
* the original value * the original value
*
* @param {Mixed} value Value to parse
* @return {boolean|""}
*/ */
that.parse = function(value) { 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) { if (value instanceof Array) {
value = value[0]; value = value[0];