Completed
Push — master ( 631a65...02b665 )
by wiese
291:31 queued 226:28
created

FieldValueValidityIndicator.update   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 4
dl 0
loc 17
rs 8.8571
nop 1
1
'use strict';
2
3
var objectAssign = require( 'object-assign' ),
4
5
	/**
6
	 * View Handler for displaying a field value validity indicator
7
	 * @class
8
	 */
9
	FieldValueValidityIndicator = {
10
		element: {},
11
12
		update: function ( validationState ) {
13
			// @fixme look why the 2nd condition was added and fix it differently.
14
			// @fixme Element values should come from the store, not from the elements themselves
15
			if ( validationState.isValid === true && this.element.val() !== "" ) {
16
				this.element.addClass( 'valid' ).removeClass( 'invalid' )
17
					.next( 'span' ).addClass( 'icon-ok' ).removeClass( 'icon-bug icon-placeholder' );
18
        this.element.parent().addClass('valid').removeClass('invalid');
19
			} else if ( validationState.isValid === false ) {
20
				this.element.addClass( 'invalid' ).removeClass( 'valid' )
21
					.next( 'span' ).addClass( 'icon-bug' ).removeClass( 'icon-ok icon-placeholder' );
22
        this.element.parent().addClass('invalid').removeClass('valid');
23
			} else if ( validationState.isValid === null ) {
24
				this.element.removeClass( 'valid invalid' )
25
					.next( 'span' ).addClass( 'icon-placeholder' ).removeClass( 'icon-ok icon-bug' );
26
        this.element.parent().removeClass('invalid valid');
27
			}
28
		}
29
	};
30
31
module.exports = {
32
	/**
33
	 * @param {jQuery} element
34
	 * @return {FieldValueValidityIndicator}
35
	 */
36
	createFieldValueValidityIndicator: function ( element ) {
37
		return objectAssign( Object.create( FieldValueValidityIndicator ), { element: element } );
38
	},
39
40
	FieldValueValidityIndicator: FieldValueValidityIndicator
41
};
42