Passed
Branch php-cs-fixer (b9836a)
by Fabio
15:02
created

framework/Web/Javascripts/source/prado/validator/validation3.js   F

Complexity

Total Complexity 301
Complexity/F 2.92

Size

Lines of Code 2015
Function Count 103

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
c 0
b 0
f 0
nc 0
dl 0
loc 2015
rs 2.4
wmc 301
mnd 4
bc 167
fnc 103
bpm 1.6213
cpm 2.9223
noi 113

67 Functions

Rating   Name   Duplication   Size   Complexity  
A Prado.ValidationManager.addSummary 0 4 1
A jQuery.klass.reset 0 5 1
A Prado.WebUI.TValidationSummary.updateHTMLMessages 0 6 2
B Prado.ValidationManager.initialize 0 38 2
A jQuery.klass.evaluateIsValid 0 6 1
B jQuery.klass.updateControlCssClass 0 20 5
A Prado.WebUI.TValidationSummary.hideSummary 0 14 4
A Prado.ValidationManager.validatorsInGroup 0 16 2
C jQuery.klass.getListElements 0 27 11
B Prado.WebUI.TValidationSummary.initialize 0 29 2
A Prado.WebUI.TValidationSummary.formatSummary 0 14 2
C Prado.WebUI.TValidationSummary.updateSummary 0 38 12
A jQuery.extend.updateActiveCustomValidator 0 13 1
C jQuery.klass.getRawValidationValue 0 44 16
B jQuery.klass.crc32 0 44 2
A Prado.ValidationManager.isValid 0 10 3
A jQuery.extend.setErrorMessage 0 14 1
A jQuery.klass.onInit 0 11 3
A jQuery.klass.isCheckBoxType 0 9 3
D jQuery.klass.convert 0 28 10
A jQuery.extend.validateControl 0 11 2
A jQuery.extend.addValidator 0 8 2
A jQuery.klass.trim 0 4 2
D jQuery.klass.validate 0 28 9
A jQuery.klass.updateControl 0 9 1
A Prado.ValidationManager.validateControl 0 13 2
A Prado.ValidationManager.reset 0 8 2
A Prado.ValidationManager.getValidatorsWithError 0 7 1
A jQuery.klass.getErrorMessage 0 4 1
A Prado.ValidationManager.updateSummary 0 13 1
A Prado.WebUI.TValidationSummary.alertMessages 0 5 1
A Prado.ValidationManager.validatorsWithoutGroup 0 11 1
A jQuery.klass.getRequiredValues 0 7 3
A jQuery.extend.reset 0 6 2
A Prado.ValidationManager.removeValidator 0 19 3
C jQuery.klass.getValidationValue 0 26 12
A jQuery.klass.getFirstSelectedListValue 0 9 3
A jQuery.klass.hide 0 5 1
A Prado.ValidationManager.validate 0 14 3
A jQuery.extend.isValid 0 7 2
B jQuery.klass.initialize 0 71 4
A jQuery.klass.build 0 4 2
A jQuery.extend.validate 0 12 2
A jQuery.klass.observeListElements 0 11 2
A jQuery.klass.updateIsValid 0 9 2
B jQuery.klass.updateValidationDisplay 0 29 6
B jQuery.klass.refreshControlAndMessage 0 15 6
A Prado.ValidationManager.addValidator 0 14 4
A jQuery.extend.addSummary 0 8 2
A jQuery.klass.observeDatePickerChanges 0 7 1
B jQuery.klass.observeChanges 0 22 4
A jQuery.klass.responseChanged 0 7 2
B jQuery.klass.isValidList 0 22 5
A jQuery.klass.isListControlType 0 5 1
A jQuery.klass.callback 0 13 1
C jQuery.klass.compare 0 23 9
B Prado.WebUI.TValidationSummary.formats 0 15 6
A jQuery.klass.getRadioButtonGroupValue 0 11 1
A Prado.ValidationManager.validatorPartition 0 4 2
A Prado.WebUI.TValidationSummary.getMessages 0 11 1
A jQuery.klass.getSelectedValuesAndChecks 0 15 2
C Prado.WebUI.TValidationSummary.formatMessageBox 0 24 9
A jQuery.klass.callbackExpired 0 11 1
A jQuery.extend.getForm 0 7 2
A Prado.WebUI.TValidationSummary.showSummary 0 9 2
A Prado.ValidationManager.focusOnError 0 8 4
A validation3.js ➔ TReCaptcha2_onloadCallback 0 6 1

How to fix   Complexity   

Complexity

Complex classes like framework/Web/Javascripts/source/prado/validator/validation3.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/*! PRADO client-side javascript validation fascade | github.com/pradosoft/prado */
2
3
/**
4
 * <p>There are 4 basic classes: {@link Prado.Validation},
5
 * {@link Prado.ValidationManager}, {@link Prado.WebUI.TValidationSummary}
6
 * and {@link Prado.WebUI.TBaseValidator},
7
 * that interact together to perform validation.
8
 * The {@link Prado.Validation} class co-ordinates together the
9
 * validation scheme and is responsible for maintaining references
10
 * to ValidationManagers.</p>
11
 *
12
 * <p>The {@link Prado.ValidationManager} class is responsible for
13
 * maintaining refereneces
14
 * to individual validators, validation summaries and their associated
15
 * groupings.</p>
16
 *
17
 * <p>The {@link Prado.WebUI.TValidationSummary} takes care of displaying
18
 * the validator error messages
19
 * as html output or an alert output.</p>
20
 *
21
 * <p>The {@link Prado.WebUI.TBaseValidator} is the base class for all
22
 * validators and contains
23
 * methods to interact with the actual inputs, data type conversion.</p>
24
 *
25
 * <p>An instance of {@link Prado.ValidationManager} must be instantiated first for a
26
 * particular form before instantiating validators and summaries.</p>
27
 *
28
 * <p>Usage example: adding a required field to a text box input with
29
 * ID "input1" in a form with ID "form1".</p>
30
 * <pre>
31
 * &lt;script type="text/javascript" src="../prado.js"&gt;&lt;/script&gt;
32
 * &lt;script type="text/javascript" src="../validator.js"&gt;&lt;/script&gt;
33
 * &lt;form id="form1" action="..."&gt;
34
 * &lt;div&gt;
35
 * 	&lt;input type="text" id="input1" /&gt;
36
 *  &lt;span id="validator1" style="display:none; color:red"&gt;*&lt;/span&gt;
37
 *  &lt;input type="submit text="submit" /&gt;
38
 * &lt;script type="text/javascript"&gt;
39
 * new Prado.ValidationManager({FormID : 'form1'});
40
 * var options =
41
 * {
42
 *		ID :				'validator1',
43
 *		FormID :			'form1',
44
 *		ErrorMessage :		'*',
45
 *		ControlToValidate : 'input1'
46
 * }
47
 * new Prado.WebUI.TRequiredFieldValidator(options);
48
 * new Prado.WebUI.TValidationSummary({ID:'summary1',FormID:'form1'});
49
 *
50
 * //watch the form onsubmit event, check validators, stop if not valid.
51
 * Event.observe("form1", "submit" function(ev)
52
 * {
53
 * 	 if(Prado.WebUI.Validation.isValid("form1") == false)
54
 * 		Event.stop(ev);
55
 * });
56
 * &lt;/script&gt;
57
 * &lt;/div&gt;
58
 * &lt;/form&gt;
59
 * </pre>
60
 *
61
 * @module validation
62
 */
63
64
Prado.Validation =  jQuery.klass();
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
65
66
/**
67
 * Global Validation Object.
68
 *
69
 * <p>To validate the inputs of a particular form, call
70
 * <code>{@link Prado.Validation.validate}(formID, groupID)</code>
71
 * where <tt>formID</tt> is the HTML form ID, and the optional
72
 * <tt>groupID</tt> if present will only validate the validators
73
 * in a particular group.</p>
74
 * <p>Use <code>{@link Prado.Validation.validateControl}(controlClientID)</code>
75
 * to trigger validation for a single control.</p>
76
 *
77
 * @object {static} Prado.Validation
78
 */
79
jQuery.extend(Prado.Validation,
80
{
81
	/**
82
	 * Hash of registered validation managers
83
	 * @var managers
84
	 */
85
	managers : {},
86
87
	/**
88
	 * Validate the validators (those that <strong>DO NOT</strong>
89
	 * belong to a particular group) in the form specified by the
90
	 * <tt>formID</tt> parameter. If <tt>groupID</tt> is specified
91
	 * only validators belonging to that group will be validated.
92
	 * @function {boolean} ?
93
	 * @param {string} formID - ID of the form to validate
94
	 * @param {string} groupID - ID of the ValidationGroup to validate.
95
	 * @param {element} invoker - DOM element that calls for validation
96
	 * @returns true if validation succeeded
97
	 */
98
	validate : function(formID, groupID, invoker)
99
	{
100
		formID = formID || this.getForm();
101
		if(this.managers[formID])
102
		{
103
			return this.managers[formID].validate(groupID, invoker);
104
		}
105
		else
106
		{
107
			throw new Error("Form '"+formID+"' is not registered with Prado.Validation");
108
		}
109
	},
110
111
	/**
112
	 * Validate all validators of a specific control.
113
	 * @function {boolean} ?
114
	 * @param {string} id - ID of DOM element to validate
115
	 * @return true if all validators are valid or no validators present, false otherwise.
116
	 */
117
    validateControl : function(id)
118
    {
119
        var formId=this.getForm();
120
121
		if (this.managers[formId])
122
        {
123
            return this.managers[formId].validateControl(id);
124
        } else {
125
			throw new Error("A validation manager needs to be created first.");
126
        }
127
    },
128
129
	/**
130
	 * Return first registered form
131
	 * @function {string} ?
132
	 * @returns ID of first form.
133
	 */
134
	getForm : function()
135
	{
136
		var keys = jQuery.map(this.managers, function(value, key) {
137
			return key;
138
		});
139
		return keys.length>0 ? keys[0] : null;
140
	},
141
142
	/**
143
	 * Check if the validators are valid for a particular form (and group).
144
	 * The validators states will not be changed.
145
	 * The <tt>validate</tt> function should be called first.
146
	 * @function {boolean} ?
147
	 * @param {string} formID - ID of the form to validate
148
	 * @param {string} groupID - ID of the ValiationGroup to validate.
149
	 * @return true if form is valid
150
	 */
151
	isValid : function(formID, groupID)
152
	{
153
		formID = formID || this.getForm();
154
		if(this.managers[formID])
155
			return this.managers[formID].isValid(groupID);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
156
		return true;
157
	},
158
159
	/**
160
	 * Reset the validators for a given group.
161
	 * The group is searched in the first registered form.
162
	 * @function ?
163
	 * @param {string} groupID - ID of the ValidationGroup to reset.
164
	 */
165
	reset : function(groupID)
166
	{
167
		var formID = this.getForm();
168
		if(this.managers[formID])
169
			this.managers[formID].reset(groupID);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
170
	},
171
172
	/**
173
	 * Add a new validator to a particular form.
174
	 * @function {ValidationManager} ?
175
	 * @param {string} formID - ID of the form that the validator belongs to.
176
	 * @param {TBaseValidator} validator - Validator object
177
	 * @return ValidationManager for the form
178
	 */
179
	addValidator : function(formID, validator)
180
	{
181
		if(this.managers[formID])
182
			this.managers[formID].addValidator(validator);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
183
		else
184
			throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
185
		return this.managers[formID];
186
	},
187
188
	/**
189
	 * Add a new validation summary.
190
	 * @function {ValidationManager} ?
191
	 * @param {string} formID - ID of the form that the validation summary belongs to.
192
	 * @param {TValidationSummary} validator - TValidationSummary object
193
	 * @return ValidationManager for the form
194
	 */
195
	addSummary : function(formID, validator)
196
	{
197
		if(this.managers[formID])
198
			this.managers[formID].addSummary(validator);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
199
		else
200
			throw new Error("A validation manager for form '"+formID+"' needs to be created first.");
201
		return this.managers[formID];
202
	},
203
204
	setErrorMessage : function(validatorID, message)
205
	{
206
		jQuery.each(Prado.Validation.managers, function(idx, manager)
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
207
		{
208
			jQuery.each(manager.validators, function(idx, validator)
209
			{
210
				if(validator.options.ID == validatorID)
211
				{
212
					validator.options.ErrorMessage = message;
213
					jQuery("#" + validatorID).get(0).innerHTML = message;
214
				}
215
			});
216
		});
217
	},
218
219
	updateActiveCustomValidator : function(validatorID, isValid)
220
	{
221
		jQuery.each(Prado.Validation.managers, function(idx, manager)
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
222
		{
223
			jQuery.each(manager.validators, function(idx, validator)
224
			{
225
				if(validator.options.ID == validatorID)
226
				{
227
					validator.updateIsValid(isValid);
228
				}
229
			});
230
		});
231
	}
232
});
233
234
/**
235
 * Manages validators for a particular HTML form.
236
 *
237
 * <p>The manager contains references to all the validators
238
 * summaries, and their groupings for a particular form.
239
 * Generally, {@link Prado.Validation} methods should be called rather
240
 * than calling directly the ValidationManager.</p>
241
 *
242
 * @class Prado.ValidationManager
243
 */
244
Prado.ValidationManager = jQuery.klass();
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
245
Prado.ValidationManager.prototype =
246
{
247
	/**
248
	 * Hash of registered validators by control's clientID
249
	 * @var controls
250
	 */
251
    controls: {},
252
253
	/**
254
	 * Initialize ValidationManager.
255
	 * @constructor {protected} ?
256
	 * @param {object} options - Options for initialization
257
	 * @... {string} FormID - ID of form of this manager
258
	 */
259
	initialize : function(options)
260
	{
261
		if(!Prado.Validation.managers[options.FormID])
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
262
		{
263
			/**
264
			 * List of validators
265
			 * @var {TBaseValidator[]} validators
266
			 */
267
			this.validators = [];
268
			/**
269
			 * List of validation summaries
270
			 * @var {TValidationSummary[]} summaries
271
			 */
272
			this.summaries = [];
273
			/**
274
			 * List of ValidationGroups
275
			 * @var {string[]} groups
276
			 */
277
			this.groups = [];
278
			/**
279
			 * Options of this ValidationManager
280
			 * @var {object} options
281
			 */
282
			this.options = {};
283
284
			this.options = options;
285
286
			Prado.Validation.managers[options.FormID] = this;
287
		}
288
		else
289
		{
290
			var manager = Prado.Validation.managers[options.FormID];
291
			this.validators = manager.validators;
292
			this.summaries = manager.summaries;
293
			this.groups = manager.groups;
294
			this.options = manager.options;
295
		}
296
	},
297
298
	/**
299
	 * Reset all validators in the given group.
300
	 * If group is null, validators without a group are used.
301
	 * @function ?
302
	 * @param {string} group - ID of ValidationGroup
303
	 */
304
	reset : function(group)
305
	{
306
		var vals = this.validatorPartition(group)[0];
307
		for(var i = 0; i < vals.length; i++)
308
			vals[i].reset();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
309
310
		this.updateSummary(group, true);
311
	},
312
313
	/**
314
	 * Validate the validators managed by this validation manager.
315
	 * If group is set, only validate validators in that group.
316
	 * @function {boolean} ?
317
	 * @param {optional string} group - ID of ValidationGroup
318
	 * @param {element} source - DOM element that calls for validation
319
	 * @return true if all validators are valid, false otherwise.
320
	 */
321
	validate : function(group, source)
322
	{
323
		var partition = this.validatorPartition(group);
324
		var valid=true;
325
		for(var i = 0; i < partition[0].length; i++)
326
		{
327
			if(!partition[0][i].validate(source))
328
				valid=false;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
329
		}
330
		this.focusOnError(partition[0]);
331
		jQuery(partition[1]).hide();
332
		this.updateSummary(group, true);
333
		return valid;
334
	},
335
336
	/**
337
	 * Perform validation for all validators of a single control.
338
	 * @function {boolean} ?
339
	 * @param {string} id - ID of DOM element to validate
340
	 * @return true if all validators are valid or no validators present, false otherwise.
341
	 */
342
    validateControl : function (id)
343
    {
344
        var valid = true;
345
        if(this.controls[id])
346
        {
347
          jQuery.each(this.controls[id], function (idx, element) {
348
            if(!element.validate(null))
349
              valid = false;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
350
          });
351
        }
352
353
        return valid;
354
    },
355
356
	/**
357
	 * Focus on the first validator that is invalid and options.FocusOnError is true.
358
	 * @function ?
359
	 * @param {TBaseValidator[]} validators - Array of validator objects
360
	 */
361
	focusOnError : function(validators)
362
	{
363
		for(var i = 0; i < validators.length; i++)
364
		{
365
			if(!validators[i].isValid && validators[i].options.FocusOnError)
366
				return Prado.Element.focus(validators[i].options.FocusElementID);
2 ignored issues
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
367
		}
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
368
	},
369
370
	/**
371
	 * Get all validators in a group and all other validators.
372
	 * Returns an array with two arrays of validators. The first
373
	 * array contains all validators in the group if group is given,
374
	 * otherwhise all validators without a group. The second array
375
	 * contains all other validators.
376
	 * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
377
	 * @param {optional string} group - ID of ValidationGroup
378
	 * @return Array with two arrays of validators.
379
	 */
380
	validatorPartition : function(group)
381
	{
382
		return group ? this.validatorsInGroup(group) : this.validatorsWithoutGroup();
383
	},
384
385
	/**
386
	 * Get all validators in a group.
387
	 * Returns an array with two arrays of validators. The first
388
	 * array contains all validators in the group. The second array
389
	 * contains all other validators.
390
	 * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
391
	 * @param {optional string} groupID - ID of ValidationGroup
392
	 * @return Array with two arrays of validators.
393
	 */
394
	validatorsInGroup : function(groupID)
395
	{
396
		if(jQuery.inArray(groupID, this.groups)!=-1)
397
		{
398
			var trues = [], falses = [];
399
			jQuery.each(this.validators, function(idx, val) {
400
				if(val.group == groupID)
401
					trues.push(val);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
402
				else
403
					falses.push(val);
404
			});
405
			return [trues, falses];
406
		}
407
		else
408
			return [[],[]];
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
409
	},
410
411
	/**
412
	 * Get all validators without a group.
413
	 * Returns an array with two arrays of validators. The first
414
	 * array contains all validators without a group. The second
415
	 * array contains all other validators.
416
	 * @function {[ TBaseValidator[] , TBaseValidator[] ]} ?
417
	 * @return Array with two arrays of validators: Array[0] has all
418
	 * validators without a group, Array[1] all other validators.
419
	 */
420
	validatorsWithoutGroup : function()
421
	{
422
		var trues = [], falses = [];
423
		jQuery.each(this.validators, function(idx, val) {
424
			if(!val.group)
425
				trues.push(val);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
426
			else
427
				falses.push(val);
428
		});
429
		return [trues, falses];
430
	},
431
432
	/**
433
	 * Get the state of validators.
434
	 * If group is set, only validators in that group are checked.
435
	 * Otherwhise only validators without a group are checked.
436
	 * @function {booelan} ?
437
	 * @param {optional string} group - ID of ValidationGroup
438
	 * @return true if all validators (in a group, if supplied) are valid.
439
	 */
440
	isValid : function(group)
441
	{
442
		for(var i = 0; i < this.validatorPartition(group)[0].length; i++)
443
		{
444
			if(!this.validatorPartition(group)[0][i].isValid)
445
				return false;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
446
		}
447
448
		return true;
449
	},
450
451
	/**
452
	 * Add a validator to this manager.
453
	 * @function ?
454
	 * @param {TBaseValidator} validator - Validator object
455
	 */
456
	addValidator : function(validator)
457
	{
458
		// Remove previously registered validator with same ID
459
    // to prevent stale validators created by AJAX updates
460
    this.removeValidator(validator);
461
462
		this.validators.push(validator);
463
		if(validator.group && jQuery.inArray(validator.group, this.groups)==-1)
464
			this.groups.push(validator.group);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
465
466
    if(typeof this.controls[validator.control.id] === 'undefined')
467
      this.controls[validator.control.id] = Array();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
468
    this.controls[validator.control.id].push(validator);
469
	},
470
471
	/**
472
	 * Add a validation summary.
473
	 * @function ?
474
	 * @param {TValidationSummary} summary - Validation summary.
475
	 */
476
	addSummary : function(summary)
477
	{
478
		this.summaries.push(summary);
479
	},
480
481
	/**
482
	 * Remove a validator from this manager
483
	 * @function ?
484
	 * @param {TBaseValidator} validator - Validator object
485
	 */
486
  removeValidator : function(validator)
487
  {
488
    // Remove from list of validators
489
  	this.validators = jQuery.grep(this.validators, function(v)
490
  	{
491
  		return (v.options.ID!=validator.options.ID);
492
  	});
493
	  // Remove from global list of validators per control
494
    if (this.controls[validator.control.id])
495
    {
496
      this.controls[validator.control.id] = jQuery.grep(this.controls[validator.control.id], function(v)
497
      {
498
        return (v.options.ID!=validator.options.ID)
499
      });
500
      // Delete array if empty
501
      if(this.controls[validator.control.id].length == 0)
502
        delete this.controls[validator.control.id];
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
503
    }
504
  },
505
506
	/**
507
	 * Gets validators with errors.
508
	 * If group is set, only validators in that group are returned.
509
	 * Otherwhise only validators without a group are returned.
510
	 * @function {TBaseValidator[]} ?
511
	 * @param {optional string} group - ID of ValidationGroup
512
	 * @return array list of validators with error.
513
	 */
514
	getValidatorsWithError : function(group)
515
	{
516
		return jQuery.grep(this.validatorPartition(group)[0], function(validator)
517
		{
518
			return !validator.isValid;
519
		});
520
	},
521
522
	/**
523
	 * Update the summary of a particular group.
524
	 * If group is set, only the summary for validators in that
525
	 * group is updated. Otherwhise only the summary for validators
526
	 * without a group is updated.
527
	 * @function ?
528
	 * @param {optional string} group - ID of ValidationGroup
529
	 * @param {boolean} refresh - Wether the summary should be refreshed
530
	 */
531
	updateSummary : function(group, refresh)
532
	{
533
		var validators = this.getValidatorsWithError(group);
534
		jQuery.each(this.summaries, function(idx, summary)
535
		{
536
			var inGroup = group && summary.group == group;
537
			var noGroup = !group || !summary.group;
538
			if(inGroup || noGroup)
539
				summary.updateSummary(validators, refresh);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
540
			else
541
				summary.hideSummary(true);
542
		});
543
	}
544
};
545
546
/**
547
 * TValidationSummary displays a summary of validation errors.
548
 *
549
 * <p>The summary is displayed inline on a Web page,
550
 * in a message box, or both. By default, a validation summary will collect
551
 * <tt>ErrorMessage</tt> of all failed validators on the page. If
552
 * <tt>ValidationGroup</tt> is not empty, only those validators who belong
553
 * to the group will show their error messages in the summary.</p>
554
 *
555
 * <p>The summary can be displayed as a list, as a bulleted list, or as a single
556
 * paragraph based on the <tt>DisplayMode</tt> option.
557
 * The messages shown can be prefixed with <tt>HeaderText</tt>.</p>
558
 *
559
 * <p>The summary can be displayed on the Web page and in a message box by setting
560
 * the <tt>ShowSummary</tt> and <tt>ShowMessageBox</tt>
561
 * options, respectively.</p>
562
 *
563
 * @class Prado.WebUI.TValidationSummary
564
 */
565
Prado.WebUI.TValidationSummary = jQuery.klass();
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
566
Prado.WebUI.TValidationSummary.prototype =
567
{
568
	/**
569
	 * Initialize TValidationSummary.
570
	 * @constructor {protected} ?
571
	 * @param {object} options - Options for initialization
572
	 * @... {string} ID - ID of validation summary element
573
	 * @... {string} FormID - ID of form of this manager
574
	 * @... {optional string} ValidationGroup - ID of ValidationGroup.
575
	 * @... {optional boolean} ShowMessageBox - true to show the summary in an alert box.
576
	 * @... {optional boolean} ShowSummary - true to show the inline summary.
577
	 * @... {optional string} HeaderText - Summary header text
578
	 * @... {optional string} DisplayMode - Summary display style, 'BulletList', 'List', 'SingleParagraph'
579
	 * @... {optional boolean} Refresh - true to update the summary upon validator state change.
580
	 * @... {optional string} Display - Display mode, 'None', 'Fixed', 'Dynamic'.
581
	 * @... {optional boolean} ScrollToSummary - true to scroll to the validation summary upon refresh.
582
	 * @... {optional function} OnHideSummary - Called on hide event.
583
	 * @... {optional function} OnShowSummary - Called on show event.
584
	 */
585
	initialize : function(options)
586
	{
587
		/**
588
		 * Validator options
589
		 * @var {object} options
590
		 */
591
		this.options = options;
592
		/**
593
		 * ValidationGroup
594
		 * @var {string} group
595
		 */
596
		this.group = options.ValidationGroup;
597
		/**
598
		 * Summary DOM element
599
		 * @var {element} messages
600
		 */
601
		this.messages = jQuery("#" + options.ID).get(0);
602
		Prado.Registry[options.ID] = this;
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
603
		if(this.messages)
604
		{
605
			/**
606
			 * Current visibility state of summary
607
			 * @var {boolean} visible
608
			 */
609
			this.visible = this.messages.style.visibility != "hidden"
610
			this.visible = this.visible && this.messages.style.display != "none";
611
			Prado.Validation.addSummary(options.FormID, this);
612
		}
613
	},
614
615
	/**
616
	 * Update the validation summary.
617
	 * @function ?
618
	 * @param {TBaseValidator[]} validators - List of validators that failed validation.
619
	 * @param {boolean} update - true if visible summary should be updated
620
	 */
621
	updateSummary : function(validators, update)
622
	{
623
		if(validators.length <= 0)
624
		{
625
			if(update || this.options.Refresh != false)
626
			{
627
				return this.hideSummary(validators);
628
			}
629
			return;
630
		}
631
632
		var refresh = update || this.visible == false || this.options.Refresh != false;
633
		// Also, do not refresh summary if at least 1 validator is waiting for callback response.
634
		// This will avoid the flickering of summary if the validator passes its test
635
		for(var i = 0; i < validators.length; i++)
636
		{
637
			if(validators[i].requestDispatched)
638
			{
639
				refresh=false;
640
				break;
641
			}
642
		}
643
644
		if(this.options.ShowSummary != false && refresh)
645
		{
646
			this.updateHTMLMessages(this.getMessages(validators));
647
			this.showSummary(validators);
648
		}
649
650
		if(this.options.ScrollToSummary != false && refresh)
651
			window.scrollTo(this.messages.offsetLeft-20, this.messages.offsetTop-20);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
652
653
		if(this.options.ShowMessageBox == true && refresh)
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.options.ShowMessageBox == true && refresh is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
654
		{
655
			this.alertMessages(this.getMessages(validators));
656
			this.visible = true;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
657
		}
658
	},
659
660
	/**
661
	 * Display the validator error messages as inline HTML.
662
	 * @function ?
663
	 * @param {string[]} messages - Array of error messages.
664
	 */
665
	updateHTMLMessages : function(messages)
666
	{
667
		while(this.messages.childNodes.length > 0)
668
			this.messages.removeChild(this.messages.lastChild);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
669
		jQuery(this.messages).append(this.formatSummary(messages));
670
	},
671
672
	/**
673
	 * Display the validator error messages as an alert box.
674
	 * @function ?
675
	 * @param {string[]} messages - Array of error messages.
676
	 */
677
	alertMessages : function(messages)
678
	{
679
		var text = this.formatMessageBox(messages);
680
		setTimeout(function(){ alert(text); },20);
681
	},
682
683
	/**
684
	 * Get messages from validators.
685
	 * @function {string[]} ?
686
	 * @param {TBaseValidator[]} validators - Array of validators.
687
	 * @return Array of validator error messages.
688
	 */
689
	getMessages : function(validators)
690
	{
691
		var messages = [];
692
		jQuery.each(validators, function(idx, validator)
693
		{
694
			var message = validator.getErrorMessage();
695
			if(typeof(message) == 'string' && message.length > 0)
696
				messages.push(message);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
697
		})
698
		return messages;
699
	},
700
701
	/**
702
	 * Hide the validation summary.
703
	 * @function ?
704
	 * @param {TBaseValidator[]} validators - Array of validators.
705
	 */
706
	hideSummary : function(validators)
707
	{	if(typeof(this.options.OnHideSummary) == "function")
708
		{
709
			this.messages.style.visibility="visible";
710
			this.options.OnHideSummary(this,validators)
711
		}
712
		else
713
		{
714
			this.messages.style.visibility="hidden";
715
			if(this.options.Display == "None" || this.options.Display == "Dynamic")
716
				jQuery(this.messages).hide();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
717
		}
718
		this.visible = false;
719
	},
720
721
	/**
722
	 * Shows the validation summary.
723
	 * @function ?
724
	 * @param {TBaseValidator[]} validators - Array of validators.
725
	 */
726
	showSummary : function(validators)
727
	{
728
		this.messages.style.visibility="visible";
729
		if(typeof(this.options.OnShowSummary) == "function")
730
			this.options.OnShowSummary(this,validators);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
731
		else
732
			jQuery(this.messages).show();
733
		this.visible = true;
734
	},
735
736
	/**
737
	 * Return the format parameters for the summary.
738
	 * @function {object} ?
739
	 * @param {string} type - Format type: "List", "SingleParagraph", "HeaderOnly" or "BulletList" (default)
740
	 * @return Object with format parameters:
741
	 * @... {string} header - Text for header
742
	 * @... {string} first - Text to prepend before message list
743
	 * @... {string} pre - Text to prepend before each message
744
	 * @... {string} post - Text to append after each message
745
	 * @... {string} first - Text to append after message list
746
	 */
747
	formats : function(type)
748
	{
749
		switch(type)
750
		{
751
			case "SimpleList":
752
				return { header : "<br />", first : "", pre : "", post : "<br />", last : ""};
753
			case "SingleParagraph":
754
				return { header : " ", first : "", pre : "", post : " ", last : "<br />"};
755
			case "HeaderOnly":
756
				return { header : "", first : "<!--", pre : "", post : "", last : "-->"};
757
			case "BulletList":
758
			default:
759
				return { header : "", first : "<ul>", pre : "<li>", post : "</li>", last : "</ul>"};
760
		}
761
	},
762
763
	/**
764
	 * Format the message summary.
765
	 * @function {string} ?
766
	 * @param {string[]} messages - Array of error messages.
767
	 * @return Formatted message
768
	 */
769
	formatSummary : function(messages)
770
	{
771
		var format = this.formats(this.options.DisplayMode);
772
		var output = this.options.HeaderText ? this.options.HeaderText + format.header : "";
773
		output += format.first;
774
		jQuery.each(messages, function(idx, message)
775
		{
776
			output += message.length > 0 ? format.pre + message + format.post : "";
777
		});
778
//		for(var i = 0; i < messages.length; i++)
779
	//		output += (messages[i].length>0) ? format.pre + messages[i] + format.post : "";
780
		output += format.last;
781
		return output;
782
	},
783
	/**
784
	 * Format the message alert box.
785
	 * @function {string} ?
786
	 * @param {string[]} messages - Array of error messages.
787
	 * @return Formatted message for alert
788
	 */
789
	formatMessageBox : function(messages)
790
	{
791
		if(this.options.DisplayMode == 'HeaderOnly' && this.options.HeaderText)
792
			return this.options.HeaderText;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
793
794
		var output = this.options.HeaderText ? this.options.HeaderText + "\n" : "";
795
		for(var i = 0; i < messages.length; i++)
796
		{
797
			switch(this.options.DisplayMode)
798
			{
799
				case "List":
800
					output += messages[i] + "\n";
801
					break;
802
				case "BulletList":
803
                default:
0 ignored issues
show
Coding Style Comprehensibility introduced by
The default case is not the last statement in this switch statement. For the sake of readability, you might want to move it to the end of the statement.
Loading history...
804
					output += "  - " + messages[i] + "\n";
805
					break;
806
				case "SingleParagraph":
807
					output += messages[i] + " ";
808
					break;
809
			}
810
		}
811
		return output;
812
	}
813
};
814
815
/**
816
 * TBaseValidator serves as the base class for validator controls.
817
 *
818
 * <p>Validation is performed when a postback control, such as a TButton,
819
 * a TLinkButton or a TTextBox (under AutoPostBack mode) is submitting
820
 * the page and its <tt>CausesValidation</tt> option is true.
821
 * The input control to be validated is specified by <tt>ControlToValidate</tt>
822
 * option.</p>
823
 *
824
 * @class Prado.WebUI.TBaseValidator
825
 */
826
Prado.WebUI.TBaseValidator = jQuery.klass(Prado.WebUI.Control,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
827
{
828
	/**
829
	 * Initialize TBaseValidator.
830
	 * @constructor {protected} ?
831
	 * @param {object} options - Options for initialization.
832
	 * @... {string} ID - ID of validator
833
	 * @... {string} FormID - ID of form of this manager.
834
	 * @... {string} ControlToValidate - ID of control to validate.
835
	 * @... {optional string} InitialValue - Initial value of control to validate.
836
	 * @... {optional string} ErrorMessage - Validation error message.
837
	 * @... {optional string} ValidationGroup - ID of ValidationGroup.
838
	 * @... {optional string} Display - Display mode, 'None', 'Fixed', 'Dynamic'.
839
	 * @... {optional boolean} ObserveChanges - True to observer changes of ControlToValidate
840
	 * @... {optional boolean} FocusOnError - True to focus on validation error.
841
	 * @... {optional string} FocusElementID - ID of element to focus on error.
842
	 * @... {optional string} ControlCssClass - Css class to use on ControlToValidate on error
843
	 * @... {optional function} OnValidate - Called immediately after validation.
844
	 * @... {optional function} OnValidationSuccess - Called after successful validation.
845
	 * @... {optional function} OnValidationError - Called after validation error.
846
	 */
847
	initialize : function(options)
848
	{
849
		this.observers = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
850
		this.intervals = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
851
852
	/*	options.OnValidate = options.OnValidate || Prototype.emptyFunction;
853
		options.OnSuccess = options.OnSuccess || Prototype.emptyFunction;
854
		options.OnError = options.OnError || Prototype.emptyFunction;
855
	*/
856
		/**
857
		 * Wether the validator is enabled (default true)
858
		 * @var {boolean} enabled
859
		 */
860
		this.enabled = options.Enabled;
861
		/**
862
		 * Visibility state of validator(default false)
863
		 * @var {boolean} visible
864
		 */
865
		this.visible = false;
866
		/**
867
		 * State of validation (default true)
868
		 * @var {boolean} isValid
869
		 */
870
		this.isValid = true;
871
		/**
872
		 * DOM elements that are observed by this validator
873
		 * @var {private element[]} _isObserving
874
		 */
875
		this._isObserving = {};
876
		/**
877
		 * ValidationGroup
878
		 * @var {string} group
879
		 */
880
		this.group = null;
881
		/**
882
		 * Wether a request was dispatched (default false)
883
		 * @var {boolean} requestDispatched
884
		 */
885
		this.requestDispatched = false;
886
887
		/**
888
		 * Validator options
889
		 * @var {object} options
890
		 */
891
		this.options = options;
892
		/**
893
		 * DOM element of control to validate
894
		 * @var {element} control
895
		 */
896
		this.control = jQuery("#" + options.ControlToValidate).get(0);
897
		/**
898
		 * DOM element of validator
899
		 * @var {element} message
900
		 */
901
		this.message = jQuery("#" + options.ID).get(0);
902
903
		Prado.Registry[options.ID] = this;
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
904
905
		if (this.onInit) this.onInit();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
906
907
		if(this.control && this.message)
908
		{
909
			this.group = options.ValidationGroup;
910
911
			/**
912
			 * ValidationManager of this validator
913
			 * @var {ValidationManager} manager
914
			 */
915
			this.manager = Prado.Validation.addValidator(options.FormID, this);
916
		}
917
	},
918
919
	/**
920
	 * Get error message.
921
	 * @function {string} ?
922
	 * @return Validation error message.
923
	 */
924
	getErrorMessage : function()
925
	{
926
		return this.options.ErrorMessage;
927
	},
928
929
	/**
930
	 * Update the validator.
931
	 * Updating the validator control will set the validator
932
	 * <tt>visible</tt> property to true.
933
	 * @function ?
934
	 */
935
	updateControl: function()
936
	{
937
		this.refreshControlAndMessage();
938
939
		//if(this.options.FocusOnError && !this.isValid )
940
		//	Prado.Element.focus(this.options.FocusElementID);
941
942
		this.visible = true;
943
	},
944
945
	/**
946
	 * Updates span and input CSS class.
947
	 * @function ?
948
	 */
949
	refreshControlAndMessage : function()
950
	{
951
		this.visible = true;
952
		if(this.message)
953
		{
954
			if(this.options.Display == "Dynamic")
955
			{
956
				var msg=this.message;
957
				this.isValid ? jQuery(msg).hide() : jQuery(msg).show();
958
			}
959
			this.message.style.visibility = this.isValid ? "hidden" : "visible";
960
		}
961
		if(this.control)
962
			this.updateControlCssClass(this.control, this.isValid);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
963
	},
964
965
	/**
966
	 * Update CSS class of control to validate.
967
	 * Add a css class to the input control if validator is invalid,
968
	 * removes the css class if valid.
969
	 * @function ?
970
	 * @param {element} control - DOM element of control to validate
971
	 * @param {boolean} valid - Validation state of control
972
	 */
973
	updateControlCssClass : function(control, valid)
974
	{
975
		var CssClass = this.options.ControlCssClass;
976
		if(typeof(CssClass) == "string" && CssClass.length > 0)
977
		{
978
			if(valid)
979
			{
980
				if (control.lastValidator == this.options.ID)
981
				{
982
					control.lastValidator = null;
983
					jQuery(control).removeClass(CssClass);
984
				}
985
			}
986
			else
987
			{
988
				control.lastValidator = this.options.ID;
989
				jQuery(control).addClass(CssClass);
990
			}
991
		}
992
	},
993
994
	/**
995
	 * Hide the validator messages and remove any validation changes.
996
	 * @function ?
997
	 */
998
	hide : function()
999
	{
1000
		this.reset();
1001
		this.visible = false;
1002
	},
1003
1004
	/**
1005
	 * Reset validator.
1006
	 * Sets isValid = true and updates the validator display.
1007
	 * @function ?
1008
	 */
1009
	reset : function()
1010
	{
1011
		this.isValid = true;
1012
		this.updateControl();
1013
	},
1014
1015
	/**
1016
	 * Perform validation.
1017
	 * Calls evaluateIsValid() function to set the value of isValid property.
1018
	 * Triggers onValidate event and onSuccess or onError event.
1019
	 * @function {boolean} ?
1020
	 * @param {element} invoker - DOM element that triggered validation
1021
	 * @return Valdation state of control.
1022
	 */
1023
	validate : function(invoker)
1024
	{
1025
		//try to find the control.
1026
		if(!this.control)
1027
			this.control = jQuery("#" + this.options.ControlToValidate).get(0);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1028
1029
		if(!this.control || this.control.disabled || !jQuery.contains(document, this.control))
1030
		{
1031
			this.isValid = true;
1032
			return this.isValid;
1033
		}
1034
1035
		if(typeof(this.options.OnValidate) == "function")
1036
		{
1037
			if(this.requestDispatched == false)
1038
				this.options.OnValidate(this, invoker);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1039
		}
1040
1041
		if(this.enabled && !this.control.getAttribute('disabled'))
1042
			this.isValid = this.evaluateIsValid();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1043
		else
1044
			this.isValid = true;
1045
1046
		this.updateValidationDisplay(invoker);
1047
		this.observeChanges(this.control);
1048
1049
		return this.isValid;
1050
	},
1051
1052
	/**
1053
	 * Update validation display.
1054
	 * Updates the validation messages and the control to validate.
1055
	 * @param {element} invoker - DOM element that triggered validation
1056
	 */
1057
	updateValidationDisplay : function(invoker)
1058
	{
1059
		if(this.isValid)
1060
		{
1061
			if(typeof(this.options.OnValidationSuccess) == "function")
1062
			{
1063
				if(this.requestDispatched == false)
1064
				{
1065
					this.refreshControlAndMessage();
1066
					this.options.OnValidationSuccess(this, invoker);
1067
				}
1068
			}
1069
			else
1070
				this.updateControl();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1071
		}
1072
		else
1073
		{
1074
			if(typeof(this.options.OnValidationError) == "function")
1075
			{
1076
				if(this.requestDispatched == false)
1077
				{
1078
					this.refreshControlAndMessage();
1079
					this.options.OnValidationError(this, invoker)
1080
				}
1081
			}
1082
			else
1083
				this.updateControl();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1084
		}
1085
	},
1086
1087
	/**
1088
	 * Add control to observe for changes.
1089
	 * Re-validates upon change. If the validator is not visible,
1090
	 * no updates are propagated.
1091
	 * @function ?
1092
	 * @param {element} control - DOM element of control to observe
1093
	 */
1094
	observeChanges : function(control)
1095
	{
1096
		if(!control) return;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1097
1098
		var canObserveChanges = this.options.ObserveChanges != false;
1099
		var currentlyObserving = this._isObserving[control.id+this.options.ID];
1100
1101
		if(canObserveChanges && !currentlyObserving)
1102
		{
1103
			var validator = this;
1104
1105
			this.observe(control, 'change', function()
1106
			{
1107
				if(validator.visible)
1108
				{
1109
					validator.validate();
1110
					validator.manager.updateSummary(validator.group);
1111
				}
1112
			});
1113
			this._isObserving[control.id+this.options.ID] = true;
1114
		}
1115
	},
1116
1117
	/**
1118
	 * Trim a string.
1119
	 * @function {string} ?
1120
	 * @param {string} value - String that should be trimmed.
1121
	 * @return Trimmed string, empty string if value is not string.
1122
	 */
1123
	trim : function(value)
1124
	{
1125
		return typeof(value) == "string" ? value.trim() : "";
1126
	},
1127
1128
	/**
1129
	 * Convert the value to a specific data type.
1130
	 * @function {mixed|null} ?
1131
	 * @param {string} dataType - Data type: "Integer", "Double", "Date" or "String"
1132
	 * @param {mixed} value - Value to convert.
1133
	 * @return Converted data value.
1134
	 */
1135
	convert : function(dataType, value)
1136
	{
1137
		if(typeof(value) == "undefined")
1138
			value = this.getValidationValue();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1139
		var string = new String(value);
1140
		switch(dataType)
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1141
		{
1142
			case "Integer":
1143
				return string.toInteger();
1144
			case "Double" :
1145
			case "Float" :
1146
				return string.toDouble(this.options.DecimalChar);
1147
			case "Date":
1148
				if(typeof(value) != "string")
1149
					return value;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1150
				else
1151
				{
1152
					var value = Date.SimpleParse(string, this.options.DateFormat);
1153
					if(value && typeof(value.getTime) == "function")
1154
						return value.getTime();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1155
					else
1156
						return null;
1157
				}
1158
			case "String":
1159
				return string.toString();
1160
		}
1161
		return value;
1162
	},
1163
1164
	/**
1165
	 * Get value that should be validated.
1166
	 * The ControlType property comes from TBaseValidator::getClientControlClass()
1167
	 * Be sure to update the TBaseValidator::$_clientClass if new cases are added.
1168
	 * @function {mixed} ?
1169
	 * @param {optional element} control - Control to get value from (default: this.control)
1170
	 * @return Control value to validate
1171
	 */
1172
	 getRawValidationValue : function(control)
1173
	 {
1174
	 	if(!control)
1175
	 		control = this.control
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1176
	 	switch(this.options.ControlType)
1177
	 	{
1178
	 		case 'TDatePicker':
1179
	 			if(control.type == "text")
1180
	 			{
1181
	 				var value = this.trim(jQuery(control).val());
1182
1183
					if(this.options.DateFormat)
1184
	 				{
1185
	 					var date = Date.SimpleParse(value, this.options.DateFormat);
1186
	 					return date == null ? value : date;
1187
	 				}
1188
	 				else
1189
		 				return value;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1190
	 			}
1191
	 			else
1192
	 			{
1193
	 				this.observeDatePickerChanges();
1194
1195
	 				return Prado.WebUI.TDatePicker.getDropDownDate(control);//.getTime();
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1196
	 			}
1197
	 		case 'THtmlArea':
1198
	 		case 'THtmlArea4':
1199
	 			if(typeof tinyMCE != "undefined")
1 ignored issue
show
Bug introduced by
The variable tinyMCE seems to be never declared. If this is a global, consider adding a /** global: tinyMCE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1200
					tinyMCE.triggerSave();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1201
				return control.value;
1202
			case 'TRadioButton':
1203
			case 'TActiveRadioButton':
1204
				if(this.options.GroupName)
1205
					return this.getRadioButtonGroupValue();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1206
			case 'TCheckBox':
1207
			case 'TActiveCheckBox':
1208
				return control.checked;
1209
	 		default:
1210
	 			if(this.isListControlType())
1211
	 				return this.getFirstSelectedListValue();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1212
	 			else
1213
		 			return jQuery(control).val();
1214
	 	}
1215
	 },
1216
1217
	/**
1218
	 * Get a trimmed value that should be validated.
1219
	 * The ControlType property comes from TBaseValidator::getClientControlClass()
1220
	 * Be sure to update the TBaseValidator::$_clientClass if new cases are added.
1221
	 * @function {mixed} ?
1222
	 * @param {optional element} control - Control to get value fron (default: this.control)
1223
	 * @return Control value to validate
1224
	 */
1225
	 getValidationValue : function(control)
1226
	 {
1227
	 	var value = this.getRawValidationValue(control);
1228
		if(!control)
1229
			control = this.control
1 ignored issue
show
Unused Code introduced by
The assignment to variable control seems to be never used. Consider removing it.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1230
		switch(this.options.ControlType)
1231
		{
1232
			case 'TDatePicker':
1233
				return value;
1234
			case 'THtmlArea':
1235
			case 'THtmlArea4':
1236
				return this.trim(value);
1237
			case 'TRadioButton':
1238
			case 'TCheckBox':
1239
			case 'TActiveCheckBox':
1240
			case 'TActiveRadioButton':
1241
				return value;
1242
            case 'TReCaptcha2':
1243
                return document.getElementById(this.options.ResponseFieldName).value;
1244
			default:
1245
				if(this.isListControlType())
1246
					return value;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1247
				else
1248
					return this.trim(value);
1249
		}
1250
	 },
1251
1252
	/**
1253
	 * Get value of radio button group
1254
	 * @function {string} ?
1255
	 * @return Value of a radio button group
1256
	 */
1257
	getRadioButtonGroupValue : function()
1258
	{
1259
		var name = this.control.name;
1260
		var value = "";
1261
		jQuery.each(document.getElementsByName(name), function(idx, el)
1262
		{
1263
			if(el.checked)
1264
				value =  el.value;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1265
		});
1266
		return value;
1267
	},
1268
1269
	 /**
1270
	  * Observe changes in the drop down list date picker, IE only.
1271
	  * @function ?
1272
	  */
1273
	 observeDatePickerChanges : function()
1274
	 {
1275
 		var DatePicker = Prado.WebUI.TDatePicker;
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1276
 		this.observeChanges(DatePicker.getDayListControl(this.control));
1277
		this.observeChanges(DatePicker.getMonthListControl(this.control));
1278
		this.observeChanges(DatePicker.getYearListControl(this.control));
1279
	 },
1280
1281
	/**
1282
	 * Gets number of selections and their values.
1283
	 * @function {object} ?
1284
	 * @param {element[]} elements - Elements to get values from.
1285
	 * @param {string} initialValue - Initial value of element
1286
	 * @return Object:
1287
	 * @... {mixed[]} values - Array of selected values
1288
	 * @... {int} checks - Number of selections
1289
	 */
1290
	getSelectedValuesAndChecks : function(elements, initialValue)
1291
	{
1292
		var checked = 0;
1293
		var values = [];
1294
		var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected';
1295
		jQuery.each(elements, function(idx, element)
1296
		{
1297
			if(element[isSelected] && element.value != initialValue)
1298
			{
1299
				checked++;
1300
				values.push(element.value);
1301
			}
1302
		});
1303
		return {'checks' : checked, 'values' : values};
1304
	},
1305
1306
	/**
1307
	 * Get list elements of TCheckBoxList or TListBox.
1308
	 * Gets an array of the list control item input elements, for TCheckBoxList
1309
	 * checkbox input elements are returned, for TListBox HTML option elements
1310
	 * are returned.
1311
	 * @function {element[]} ?
1312
	 * @return Array of list control option DOM elements.
1313
	 */
1314
	getListElements : function()
1315
	{
1316
		switch(this.options.ControlType)
1317
		{
1318
			case 'TCheckBoxList': case 'TRadioButtonList':
1319
				var elements = [];
1320
				for(var i = 0; i < this.options.TotalItems; i++)
1321
				{
1322
					var element = jQuery("#" + this.options.ControlToValidate+"_c"+i).get(0);
1323
					if(this.isCheckBoxType(element))
1324
						elements.push(element);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1325
				}
1326
				return elements;
1327
			case 'TListBox':
1328
				var elements = [];
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable elements already seems to be declared on line 1319. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1329
				var element = jQuery("#" + this.options.ControlToValidate).get(0);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable element already seems to be declared on line 1322. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1330
				var type;
1331
				if(element && (type = element.type.toLowerCase()))
1332
				{
1333
					if(type == "select-one" || type == "select-multiple")
1334
						elements = element.options;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1335
				}
1336
				return elements;
1337
			default:
1338
				return [];
1339
		}
1340
	},
1341
1342
	/**
1343
	 * Check if control is of type checkbox or radio.
1344
	 * @function {boolean} ?
1345
	 * @param {element} element - DOM element to check.
1346
	 * @return True if element is of checkbox or radio type.
1347
	 */
1348
	isCheckBoxType : function(element)
1349
	{
1350
		if(element && element.type)
1351
		{
1352
			var type = element.type.toLowerCase();
1353
			return type == "checkbox" || type == "radio";
1354
		}
1355
		return false;
1356
	},
1357
1358
	/**
1359
	 * Check if control to validate is a TListControl type.
1360
	 * @function {boolean} ?
1361
	 * @return True if control to validate is a TListControl type.
1362
	 */
1363
	isListControlType : function()
1364
	{
1365
		var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox'];
1366
		return (jQuery.inArray(this.options.ControlType, list)!=-1);
1367
	},
1368
1369
	/**
1370
	 * Get first selected list value or initial value if none found.
1371
	 * @function {string} ?
1372
	 * @return First selected list value, initial value if none found.
1373
	 */
1374
	getFirstSelectedListValue : function()
1375
	{
1376
		var initial = "";
1377
		if(typeof(this.options.InitialValue) != "undefined")
1378
			initial = this.options.InitialValue;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1379
		var elements = this.getListElements();
1380
		var selection = this.getSelectedValuesAndChecks(elements, initial);
1381
		return selection.values.length > 0 ? selection.values[0] : initial;
1382
	}
1383
});
1384
1385
1386
/**
1387
 * TRequiredFieldValidator makes the associated input control a required field.
1388
 *
1389
 * <p>The input control fails validation if its value does not change from
1390
 * the <tt>InitialValue</tt> option upon losing focus.</p>
1391
 *
1392
 * @class Prado.WebUI.TRequiredFieldValidator
1393
 * @extends Prado.WebUI.TBaseValidator
1394
 */
1395
Prado.WebUI.TRequiredFieldValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1396
{
1397
	/**
1398
	 * Evaluate validation state
1399
	 * @function {boolean} ?
1400
	 * @return True if the input value is not empty nor equal to the initial value.
1401
	 */
1402
	evaluateIsValid : function()
1403
	{
1404
    	var a = this.getValidationValue();
1405
    	var b = this.trim(this.options.InitialValue);
1406
    	return(a != b);
1407
	}
1408
});
1409
1410
1411
/**
1412
 * TCompareValidator compares the value entered by the user into an input
1413
 * control with the value entered into another input control or a constant value.
1414
 *
1415
 * <p>To compare the associated input control with another input control,
1416
 * set the <tt>ControlToCompare</tt> option to the ID path
1417
 * of the control to compare with. To compare the associated input control with
1418
 * a constant value, specify the constant value to compare with by setting the
1419
 * <tt>ValueToCompare</tt> option.</p>
1420
 *
1421
 * <p>The <tt>DataType</tt> property is used to specify the data type
1422
 * of both comparison values. Both values are automatically converted to this data
1423
 * type before the comparison operation is performed. The following value types are supported:
1424
 * - <b>Integer</b> A 32-bit signed integer data type.
1425
 * - <b>Float</b> A double-precision floating point number data type.
1426
 * - <b>Date</b> A date data type. The format can be set by the <tt>DateFormat</tt> option.
1427
 * - <b>String</b> A string data type.</p>
1428
 *
1429
 * Use the <tt>Operator</tt> property to specify the type of comparison
1430
 * to perform. Valid operators include Equal, NotEqual, GreaterThan, GreaterThanEqual,
1431
 * LessThan and LessThanEqual.
1432
 *
1433
 * @class Prado.WebUI.TCompareValidator
1434
 * @extends Prado.WebUI.TBaseValidator
1435
 */
1436
Prado.WebUI.TCompareValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1437
{
1438
	/**
1439
	 * Additional constructor options.
1440
	 * @constructor initialize
1441
	 * @param {object} options - Additional constructor options:
1442
	 * @... {string} ControlToCompare - Control with compare value.
1443
	 * @... {string} ValueToCompare - Value to compare.
1444
	 * @... {string} Operator - Type of comparison: "Equal", "NotEqual", "GreaterThan",
1445
	 *   "GreaterThanEqual", "LessThan" or "LessThanEqual".
1446
	 * @... {string} Type - Type of values: "Integer", "Float", "Date" or "String".
1447
	 * @... {string} DateFormat - Valid date format.
1448
	 */
1449
1450
	//_observingComparee : false,
1451
1452
	/**
1453
	 * Evaluate validation state
1454
	 * @function {boolean} ?
1455
	 * @return True if comparision condition is met.
1456
	 */
1457
	evaluateIsValid : function()
1458
	{
1459
		var value = this.getValidationValue();
1460
	    if (value.length <= 0)
1461
	    	return true;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1462
1463
    	var comparee = jQuery("#" + this.options.ControlToCompare).get(0);
1464
1465
		if(comparee)
1466
			var compareTo = this.getValidationValue(comparee);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1467
		else
1468
			var compareTo = this.options.ValueToCompare || "";
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable compareTo already seems to be declared on line 1466. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1469
1470
	    var isValid =  this.compare(value, compareTo);
1471
1472
		if(comparee)
1473
		{
1474
			this.updateControlCssClass(comparee, isValid);
1475
			this.observeChanges(comparee);
1476
		}
1477
		return isValid;
1478
	},
1479
1480
	/**
1481
	 * Compare two operands.
1482
	 * The operand values are casted to type defined
1483
	 * by <tt>DataType</tt> option. False is returned if the first
1484
	 * operand converts to null. Returns true if the second operand
1485
	 * converts to null. The comparision is done based on the
1486
	 * <tt>Operator</tt> option.
1487
	 * @function ?
1488
	 * @param {mixed} operand1 - First operand.
1489
	 * @param {mixed} operand2 - Second operand.
1490
	 */
1491
	compare : function(operand1, operand2)
1492
	{
1493
		var op1, op2;
1494
		if((op1 = this.convert(this.options.DataType, operand1)) == null)
1495
			return false;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1496
		if ((op2 = this.convert(this.options.DataType, operand2)) == null)
1497
        	return true;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1498
    	switch (this.options.Operator)
1499
		{
1500
	        case "NotEqual":
1501
	            return (op1 != op2);
1502
	        case "GreaterThan":
1503
	            return (op1 > op2);
1504
	        case "GreaterThanEqual":
1505
	            return (op1 >= op2);
1506
	        case "LessThan":
1507
	            return (op1 < op2);
1508
	        case "LessThanEqual":
1509
	            return (op1 <= op2);
1510
	        default:
1511
	            return (op1 == op2);
1512
	    }
1513
	}
1514
});
1515
1516
/**
1517
 * TCustomValidator performs user-defined client-side validation on an
1518
 * input component.
1519
 *
1520
 * <p>To create a client-side validation function, add the client-side
1521
 * validation javascript function to the page template.
1522
 * The function should have the following signature:</p>
1523
 *
1524
 * <pre>
1525
 * &lt;script type="text/javascript"&gt;
1526
 * function ValidationFunctionName(sender, parameter)
1527
 * {
1528
 *    if(parameter == ...)
1529
 *       return true;
1530
 *    else
1531
 *       return false;
1532
 * }
1533
 * &lt;/script&gt;
1534
 * </pre>
1535
 *
1536
 * <p>Use the <tt>ClientValidationFunction</tt> option
1537
 * to specify the name of the client-side validation script function associated
1538
 * with the TCustomValidator.</p>
1539
 *
1540
 * @class Prado.WebUI.TCustomValidator
1541
 * @extends Prado.WebUI.TBaseValidator
1542
 */
1543
Prado.WebUI.TCustomValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1544
{
1545
	/**
1546
	 * Additional constructor options.
1547
	 * @constructor initialize
1548
	 * @param {object} options - Additional constructor options:
1549
	 * @... {function} ClientValidationFunction - Custom validation function.
1550
	 */
1551
1552
	/**
1553
	 * Evaluate validation state
1554
	 * Returns true if no valid custom validation function is present.
1555
	 * @function {boolean} ?
1556
	 * @return True if custom validation returned true.
1557
	 */
1558
	evaluateIsValid : function()
1559
	{
1560
		var value = this.getValidationValue();
1561
		var clientFunction = this.options.ClientValidationFunction;
1562
		if(typeof(clientFunction) == "string" && clientFunction.length > 0)
1563
		{
1564
			var validate = clientFunction.toFunction();
1565
			return validate(this, value);
1566
		}
1567
		return true;
1568
	}
1569
});
1570
1571
/**
1572
 * Uses callback request to perform validation.
1573
 *
1574
 * @class Prado.WebUI.TActiveCustomValidator
1575
 * @extends Prado.WebUI.TBaseValidator
1576
 */
1577
Prado.WebUI.TActiveCustomValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1578
{
1579
	/**
1580
	 * Override the parent implementation to store the invoker, in order to
1581
	 * re-validate after the callback has returned
1582
	 * Calls evaluateIsValid() function to set the value of isValid property.
1583
	 * Triggers onValidate event and onSuccess or onError event.
1584
	 * @function {boolean} ?
1585
	 * @param {element} invoker - DOM element that triggered validation
1586
	 * @return True if valid.
1587
	 */
1588
	validate : function(invoker)
1589
	{
1590
		this.invoker = invoker;
1591
1592
		//try to find the control.
1593
		if(!this.control)
1594
			this.control = jQuery("#" + this.options.ControlToValidate).get(0);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1595
1596
		if(!this.control || this.control.disabled)
1597
		{
1598
			this.isValid = true;
1599
			return this.isValid;
1600
		}
1601
1602
		if(typeof(this.options.OnValidate) == "function")
1603
		{
1604
			if(this.requestDispatched == false)
1605
				this.options.OnValidate(this, invoker);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1606
		}
1607
1608
		return true;
1609
	},
1610
1611
	/**
1612
	 * Send CallBack to start serverside validation.
1613
	 * @function {boolean} ?
1614
	 * @return True if valid.
1615
	 */
1616
	evaluateIsValid : function()
1617
	{
1618
		return this.isValid;
1619
	},
1620
1621
	/**
1622
	 * Parse CallBack response data on success.
1623
	 * @function ?
1624
	 * @param {CallbackRequest} request - CallbackRequest.
0 ignored issues
show
Documentation introduced by
The parameter request does not exist. Did you maybe forget to remove this comment?
Loading history...
1625
	 * @param {string} data - Response data.
1626
	 */
1627
	updateIsValid : function(data)
1628
	{
1629
		this.isValid = data;
1630
		this.requestDispatched = false;
1631
		if(typeof(this.options.onSuccess) == "function")
1632
			this.options.onSuccess(null,data);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1633
		this.updateValidationDisplay();
1634
		this.manager.updateSummary(this.group);
1635
	}
1636
});
1637
1638
/**
1639
 * TRangeValidator tests whether an input value is within a specified range.
1640
 *
1641
 * <p>TRangeValidator uses three key properties to perform its validation.</p>
1642
 *
1643
 * <p>The <tt>MinValue</tt> and <tt>MaxValue</tt> options specify the minimum
1644
 * and maximum values of the valid range.</p>
1645
 * <p>The <tt>DataType</tt> option is
1646
 * used to specify the data type of the value and the minimum and maximum range values.
1647
 * The values are converted to this data type before the validation
1648
 * operation is performed. The following value types are supported:</p>
1649
 *
1650
 * - <b>Integer</b> A 32-bit signed integer data type.<br />
1651
 * - <b>Float</b> A double-precision floating point number data type.<br />
1652
 * - <b>Date</b> A date data type. The date format can be specified by<br />
1653
 *   setting <tt>DateFormat</tt> option, which must be recognizable
1654
 *   by <tt>Date.SimpleParse</tt> javascript function.
1655
 * - <b>String</b> A string data type.
1656
 *
1657
 * @class Prado.WebUI.TRangeValidator
1658
 * @extends Prado.WebUI.TBaseValidator
1659
 */
1660
Prado.WebUI.TRangeValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1661
{
1662
	/**
1663
	 * Additional constructor options.
1664
	 * @constructor initialize
1665
	 * @param {object} options - Additional constructor options:
1666
	 * @... {string} MinValue - Minimum range value
1667
	 * @... {string} MaxValue - Maximum range value
1668
	 * @... {string} DataType - Value data type: "Integer", "Float", "Date" or "String"
1669
	 * @... {string} DateFormat - Date format for data type Date.
1670
	 */
1671
1672
	/**
1673
	 * Evaluate validation state
1674
	 * @function {boolean} ?
1675
	 * @return True if value is in range or value is empty,
1676
	 * false otherwhise and when type conversion failed.
1677
	 */
1678
	evaluateIsValid : function()
1679
	{
1680
		var value = this.getValidationValue();
1681
		if(value.length <= 0)
1682
			return true;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1683
		if(typeof(this.options.DataType) == "undefined")
1684
			this.options.DataType = "String";
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1685
1686
		if(this.options.DataType != "StringLength")
1687
		{
1688
			var min = this.convert(this.options.DataType, this.options.MinValue || null);
1689
			var max = this.convert(this.options.DataType, this.options.MaxValue || null);
1690
			value = this.convert(this.options.DataType, value);
1691
		}
1692
		else
1693
		{
1694
			var min = this.options.MinValue || 0;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable min already seems to be declared on line 1688. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1695
			var max = this.options.MaxValue || Number.POSITIVE_INFINITY;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable max already seems to be declared on line 1689. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
1696
			value = value.length;
1697
		}
1698
1699
		if(value == null)
1700
			return false;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1701
1702
		var valid = true;
1703
1704
		if(min != null)
1705
			valid = valid && (this.options.StrictComparison ? value > min : value >= min);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1706
		if(max != null)
1707
			valid = valid && (this.options.StrictComparison ? value < max : value <= max);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1708
		return valid;
1709
	}
1710
});
1711
1712
/**
1713
 * TRegularExpressionValidator validates whether the value of an associated
1714
 * input component matches the pattern specified by a regular expression.
1715
 *
1716
 * @class Prado.WebUI.TRegularExpressionValidator
1717
 * @extends Prado.WebUI.TBaseValidator
1718
 */
1719
Prado.WebUI.TRegularExpressionValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1720
{
1721
	/**
1722
	 * Additional constructor option.
1723
	 * @constructor initialize
1724
	 * @param {object} options - Additional constructor option:
1725
	 * @... {string} ValidationExpression - Regular expression to match against.
1726
	 * @... {string} PatternModifiers - Pattern modifiers: combinations of g, i, and m
1727
	 */
1728
1729
	/**
1730
	 * Evaluate validation state
1731
	 * @function {boolean} ?
1732
	 * @return True if value matches regular expression or value is empty.
1733
	 */
1734
	evaluateIsValid : function()
1735
	{
1736
		var value = this.getRawValidationValue();
1737
		if (value.length <= 0)
1738
	    	return true;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1739
1740
		var rx = new RegExp('^'+this.options.ValidationExpression+'$',this.options.PatternModifiers);
1741
		var matches = rx.exec(value);
1742
		return (matches != null && value == matches[0]);
1743
	}
1744
});
1745
1746
/**
1747
 * TEmailAddressValidator validates whether the value of an associated
1748
 * input component is a valid email address.
1749
 *
1750
 * @class Prado.WebUI.TEmailAddressValidator
1751
 * @extends Prado.WebUI.TRegularExpressionValidator
1752
 */
1753
Prado.WebUI.TEmailAddressValidator = Prado.WebUI.TRegularExpressionValidator;
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1754
1755
1756
/**
1757
 * TListControlValidator checks the number of selection and their values
1758
 * for a TListControl that allows multiple selections.
1759
 *
1760
 * @class Prado.WebUI.TListControlValidator
1761
 * @extends Prado.WebUI.TBaseValidator
1762
 */
1763
Prado.WebUI.TListControlValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1764
{
1765
	/**
1766
	 * Evaluate validation state
1767
	 * @function {boolean} ?
1768
	 * @return True if number of selections and/or their values match requirements.
1769
	 */
1770
	evaluateIsValid : function()
1771
	{
1772
		var elements = this.getListElements();
1773
		if(elements && elements.length <= 0)
1774
			return true;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1775
1776
		this.observeListElements(elements);
1777
1778
		var selection = this.getSelectedValuesAndChecks(elements);
1779
		return this.isValidList(selection.checks, selection.values);
1780
	},
1781
1782
	/**
1783
	 * Observe list elements for of changes (only IE)
1784
	 * @function ?
1785
	 * @param {element[]} elements - Array of DOM elements to observe
1786
	 */
1787
	 observeListElements : function(elements)
1788
	 {
1789
		if(this.isCheckBoxType(elements[0]))
1790
		{
1791
			var validator = this;
1792
			jQuery.each(elements, function(idx, element)
1793
			{
1794
				validator.observeChanges(element);
1795
			});
1796
		}
1797
	 },
1798
1799
	/**
1800
	 * Check if list is valid.
1801
	 * Determine if the number of checked values and the checked values
1802
	 * satisfy the required number of checks and/or the checked values
1803
	 * equal to the required values.
1804
	 * @function {boolean} ?
1805
	 * @param {int} checked - Number of required checked values
1806
	 * @param {string[]} values - Array of required checked values
1807
	 * @return True if checked values and number of checks are satisfied.
1808
	 */
1809
	isValidList : function(checked, values)
1810
	{
1811
		var exists = true;
1812
1813
		//check the required values
1814
		var required = this.getRequiredValues();
1815
		if(required.length > 0)
1816
		{
1817
			if(values.length < required.length)
1818
				return false;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1819
			jQuery.each(required, function(idx, requiredValue)
1820
			{
1821
				exists = exists && (jQuery.inArray(requiredValue, values)!=-1);
1822
			});
1823
		}
1824
1825
		var min = typeof(this.options.Min) == "undefined" ?
1826
					Number.NEGATIVE_INFINITY : this.options.Min;
1827
		var max = typeof(this.options.Max) == "undefined" ?
1828
					Number.POSITIVE_INFINITY : this.options.Max;
1829
		return exists && checked >= min && checked <= max;
1830
	},
1831
1832
	/**
1833
	 * Get list of required values.
1834
	 * @function {string[]} ?
1835
	 * @return Array of required values that must be selected.
1836
	 */
1837
	getRequiredValues : function()
1838
	{
1839
		var required = [];
1840
		if(this.options.Required && this.options.Required.length > 0)
1841
			required = this.options.Required.split(/,\s*/);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1842
		return required;
1843
	}
1844
});
1845
1846
1847
/**
1848
 * TDataTypeValidator verifies if the input data is of the type specified
1849
 * by <tt>DataType</tt> option.
1850
 *
1851
 * <p>The following data types are supported:</p>
1852
 *
1853
 * - <b>Integer</b> A 32-bit signed integer data type.<br />
1854
 * - <b>Float</b> A double-precision floating point number data type.<br />
1855
 * - <b>Date</b> A date data type.<br />
1856
 * - <b>String</b> A string data type.<br />
1857
 *
1858
 * <p>For <b>Date</b> type, the option <tt>DateFormat</tt>
1859
 * will be used to determine how to parse the date string.</p>
1860
 *
1861
 * @class Prado.WebUI.TDataTypeValidator
1862
 * @extends Prado.WebUI.TBaseValidator
1863
 */
1864
Prado.WebUI.TDataTypeValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1865
{
1866
	/**
1867
	 * Additional constructor option.
1868
	 * @constructor initialize
1869
	 * @param {object} options - Additional constructor option:
1870
	 * @... {string} DataType - Value data type: "Integer", "Float", "Date" or "String"
1871
	 * @... {string} DateFormat - Date format for data type Date.
1872
	 */
1873
1874
	/**
1875
	 * Evaluate validation state
1876
	 * @function {boolean} ?
1877
	 * @return True if value matches required data type.
1878
	 */
1879
	evaluateIsValid : function()
1880
	{
1881
		var value = this.getValidationValue();
1882
		if(value.length <= 0)
1883
			return true;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1884
		return this.convert(this.options.DataType, value) != null;
1885
	}
1886
});
1887
1888
/**
1889
 * TCaptchaValidator verifies if the input data is the same as
1890
 * the token shown in the associated CAPTCHA control.
1891
 *
1892
 * @class Prado.WebUI.TCaptchaValidator
1893
 * @extends Prado.WebUI.TBaseValidator
1894
 */
1895
Prado.WebUI.TCaptchaValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1896
{
1897
	/**
1898
	 * Evaluate validation state
1899
	 * @function {boolean} ?
1900
	 * @return True if value matches captcha text
1901
	 */
1902
	evaluateIsValid : function()
1903
	{
1904
		var a = this.getValidationValue();
1905
		var h = 0;
1906
		if (this.options.CaseSensitive==false)
1907
			a = a.toUpperCase();
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1908
		for(var i = a.length-1; i >= 0; --i)
1909
			h += a.charCodeAt(i);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1910
		return h == this.options.TokenHash;
1911
	},
1912
1913
	crc32 : function(str)
1914
	{
1915
	    function Utf8Encode(string)
1916
		{
1917
	        string = string.replace(/\r\n/g,"\n");
1918
	        var utftext = "";
1919
1920
	        for (var n = 0; n < string.length; n++)
1921
			{
1922
	            var c = string.charCodeAt(n);
1923
1924
	            if (c < 128) {
1925
	                utftext += String.fromCharCode(c);
1926
	            }
1927
	            else if((c > 127) && (c < 2048)) {
1928
	                utftext += String.fromCharCode((c >> 6) | 192);
1929
	                utftext += String.fromCharCode((c & 63) | 128);
1930
	            }
1931
	            else {
1932
	                utftext += String.fromCharCode((c >> 12) | 224);
1933
	                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
1934
	                utftext += String.fromCharCode((c & 63) | 128);
1935
	            }
1936
	        }
1937
1938
	        return utftext;
1939
	    };
1940
1941
	    str = Utf8Encode(str);
1942
1943
	    var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
1944
		var crc = 0;
1945
	    var x = 0;
1946
	    var y = 0;
1947
1948
	    crc = crc ^ (-1);
1949
	    for( var i = 0, iTop = str.length; i < iTop; i++ )
1950
		{
1951
	        y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
1952
	        x = "0x" + table.substr( y * 9, 8 );
1953
	        crc = ( crc >>> 8 ) ^ x;
1954
	    }
1955
	    return crc ^ (-1);
1956
	}
1957
});
1958
1959
1960
/**
1961
 * TReCaptchaValidator client-side control.
1962
 *
1963
 * @class Prado.WebUI.TReCaptchaValidator
1964
 * @extends Prado.WebUI.TBaseValidator
1965
 */
1966
Prado.WebUI.TReCaptchaValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1967
{
1968
	onInit : function()
1969
	{
1970
		var obj = this;
1971
		var elements = document.getElementsByName(this.options.ResponseFieldName);
1972
		if (elements)
1973
		 if (elements.length>=1)
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1974
		 {
1975
		  this.observe(elements[0],'change',function() { obj.responseChanged() });
1976
		  this.observe(elements[0],'keydown',function() { obj.responseChanged() });
1977
		 }
1978
	},
1979
1980
	responseChanged: function()
1981
	{
1982
		var field = jQuery("#" + this.options.ID+'_1').get(0);
1983
		if (field.value=='1') return;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1984
		field.value = '1';
1985
		Prado.Validation.validateControl(this.options.ID);
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1986
	},
1987
1988
	/**
1989
	 * Evaluate validation state
1990
	 * @function {boolean} ?
1991
	 * @return True if the captcha has validate, False otherwise.
1992
	 */
1993
	evaluateIsValid : function()
1994
	{
1995
		return (jQuery("#" + this.options.ID+'_1').get(0).value=='1');
1996
	}
1997
});
1998
1999
/**
2000
 * Registry for TReCaptcha2 components
2001
 */
2002
Prado.WebUI.TReCaptcha2Instances = {};
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2003
/**
2004
 * Render callback; called by google's js when loaded
2005
 */
2006
TReCaptcha2_onloadCallback = function()
0 ignored issues
show
Bug introduced by
The variable TReCaptcha2_onloadCallback seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.TReCaptcha2_onloadCallback.
Loading history...
2007
{
2008
	jQuery.each(Prado.WebUI.TReCaptcha2Instances, function(index, item) {
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2009
    	item.build();
2010
	});
2011
}
2012
2013
/**
2014
 * TReCaptcha2 client-side control.
2015
 *
2016
 * @class Prado.WebUI.TReCaptcha2
2017
 * @extends Prado.WebUI.Control
2018
 */
2019
Prado.WebUI.TReCaptcha2 = jQuery.klass(Prado.WebUI.Control,
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2020
{
2021
    onInit: function(options)
2022
    {
2023
        for (key in options) { this[key] = options[key]; }
0 ignored issues
show
Bug introduced by
The variable key seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.key.
Loading history...
2024
        this.options['callback'] = jQuery.proxy(this.callback,this);
2025
        this.options['expired-callback'] = jQuery.proxy(this.callbackExpired,this);
2026
        
2027
        Prado.WebUI.TReCaptcha2Instances[this.element.id] = this;
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2028
    },
2029
    build: function()
2030
    {
2031
       if (grecaptcha !== undefined) this.widgetId = grecaptcha.render(this.element, this.options);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Comprehensibility Bug Compatibility introduced by
Using grecaptcha !== undefined to check if a variable is declared may throw an Error. Consider using typeof {name} === "undefined"instead.
Loading history...
2032
    },
2033
    callback: function(response)
2034
    {
2035
        var responseField = jQuery('#' + this.ID + ' textarea').attr('id');
2036
        var params = {
2037
            widgetId: this.widgetId,
2038
            response: response,
2039
            responseField: responseField,
2040
            onCallback: this.onCallback
2041
        };
2042
        var request = new Prado.CallbackRequest(this.EventTarget,this);
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2043
        request.setCallbackParameter(params);
2044
        request.dispatch();
2045
    },
2046
    callbackExpired: function()
2047
    {
2048
        var responseField = jQuery('#' + this.ID + ' textarea').attr('id');
2049
        var params = {
2050
            responseField: responseField,
2051
            onCallbackExpired: this.onCallbackExpired
2052
        };
2053
        var request = new Prado.CallbackRequest(this.EventTarget,this);
1 ignored issue
show
Bug introduced by
The variable Prado seems to be never declared. If this is a global, consider adding a /** global: Prado */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2054
        request.setCallbackParameter(params);
2055
        request.dispatch();
2056
    }
2057
});
2058
2059
/**
2060
 * TReCaptcha2Validator client-side control.
2061
 *
2062
 * @class Prado.WebUI.TReCaptcha2Validator
2063
 * @extends Prado.WebUI.TBaseValidator
2064
 */
2065
Prado.WebUI.TReCaptcha2Validator = jQuery.klass(Prado.WebUI.TBaseValidator,
2066
{
2067
    /**
2068
     * Evaluate validation state
2069
     * @function {boolean} ?
2070
     * @return True if the captcha has validate, False otherwise.
2071
     */
2072
    evaluateIsValid : function()
2073
    {
2074
        var a = this.getValidationValue();
2075
        var b = this.trim(this.options.InitialValue);
2076
        return(a != b);
2077
    }
2078
});