|
1
|
|
|
/*! PRADO main js file | github.com/pradosoft/prado */ |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Polyfill for ECMAScript5's bind() function. |
|
5
|
|
|
* ---------- |
|
6
|
|
|
* Adds compatible .bind() function; needed for Internet Explorer < 9 |
|
7
|
|
|
* Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
if (!Function.prototype.bind) { |
|
11
|
|
|
Function.prototype.bind = function (oThis) { |
|
|
|
|
|
|
12
|
|
|
if (typeof this !== "function") { |
|
13
|
|
|
// closest thing possible to the ECMAScript 5 internal IsCallable function |
|
14
|
|
|
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
var aArgs = Array.prototype.slice.call(arguments, 1), |
|
18
|
|
|
fToBind = this, |
|
19
|
|
|
fNOP = function () {}, |
|
20
|
|
|
fBound = function () { |
|
21
|
|
|
return fToBind.apply(this instanceof fNOP && oThis |
|
22
|
|
|
? this |
|
23
|
|
|
: oThis, |
|
24
|
|
|
aArgs.concat(Array.prototype.slice.call(arguments))); |
|
25
|
|
|
}; |
|
26
|
|
|
|
|
27
|
|
|
fNOP.prototype = this.prototype; |
|
28
|
|
|
fBound.prototype = new fNOP(); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
return fBound; |
|
31
|
|
|
}; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/* |
|
35
|
|
|
* Low Pro JQ |
|
36
|
|
|
* ---------- |
|
37
|
|
|
* |
|
38
|
|
|
* Author: Dan Webb ([email protected]) |
|
39
|
|
|
* GIT: github.com:danwrong/low-pro-for-jquery.git |
|
40
|
|
|
* Download: http://github.com/danwrong/low-pro-for-jquery/tree/master/src/lowpro.jquery.js?raw=true |
|
41
|
|
|
* |
|
42
|
|
|
* A jQuery port of the Low Pro behavior framework that was originally written for Prototype. |
|
43
|
|
|
* |
|
44
|
|
|
* Prado actually uses it as a base to emulate OOP subclassing, inheritance and contructor events. |
|
45
|
|
|
* The "behaviour" and the "Remote" bits are not used and have been commented out. |
|
46
|
|
|
*/ |
|
47
|
|
|
|
|
48
|
|
|
(function($) { |
|
49
|
|
|
|
|
50
|
|
|
var addMethods = function(source) { |
|
51
|
|
|
var ancestor = this.superclass && this.superclass.prototype; |
|
52
|
|
|
var properties = $.keys(source); |
|
53
|
|
|
|
|
54
|
|
|
if (!$.keys({ toString: true }).length) properties.push("toString", "valueOf"); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
for (var i = 0, length = properties.length; i < length; i++) { |
|
57
|
|
|
var property = properties[i], value = source[property]; |
|
58
|
|
|
if (ancestor && $.isFunction(value) && $.argumentNames(value)[0] == "$super") { |
|
59
|
|
|
|
|
60
|
|
|
var method = value, value = $.extend($.wrap((function(m) { |
|
|
|
|
|
|
61
|
|
|
return function() { return ancestor[m].apply(this, arguments) }; |
|
62
|
|
|
})(property), method), { |
|
63
|
|
|
valueOf: function() { return method }, |
|
|
|
|
|
|
64
|
|
|
toString: function() { return method.toString() } |
|
|
|
|
|
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
this.prototype[property] = value; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return this; |
|
71
|
|
|
}; |
|
72
|
|
|
|
|
73
|
|
|
$.extend({ |
|
74
|
|
|
keys: function(obj) { |
|
75
|
|
|
var keys = []; |
|
76
|
|
|
for (var key in obj) keys.push(key); |
|
|
|
|
|
|
77
|
|
|
return keys; |
|
78
|
|
|
}, |
|
79
|
|
|
|
|
80
|
|
|
argumentNames: function(func) { |
|
81
|
|
|
var names = func.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(/, ?/); |
|
82
|
|
|
return names.length == 1 && !names[0] ? [] : names; |
|
83
|
|
|
}, |
|
84
|
|
|
|
|
85
|
|
|
bind: function(func, scope) { |
|
86
|
|
|
return function() { |
|
87
|
|
|
return func.apply(scope, $.makeArray(arguments)); |
|
88
|
|
|
}; |
|
89
|
|
|
}, |
|
90
|
|
|
|
|
91
|
|
|
wrap: function(func, wrapper) { |
|
92
|
|
|
var __method = func; |
|
93
|
|
|
return function() { |
|
94
|
|
|
return wrapper.apply(this, [$.bind(__method, this)].concat($.makeArray(arguments))); |
|
95
|
|
|
}; |
|
96
|
|
|
}, |
|
97
|
|
|
|
|
98
|
|
|
klass: function() { |
|
99
|
|
|
var parent = null, properties = $.makeArray(arguments); |
|
100
|
|
|
if ($.isFunction(properties[0])) parent = properties.shift(); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
var klass = function() { |
|
103
|
|
|
this.initialize.apply(this, arguments); |
|
104
|
|
|
}; |
|
105
|
|
|
|
|
106
|
|
|
klass.superclass = parent; |
|
107
|
|
|
klass.subclasses = []; |
|
108
|
|
|
klass.addMethods = addMethods; |
|
109
|
|
|
|
|
110
|
|
|
if (parent) { |
|
111
|
|
|
var subclass = function() { }; |
|
112
|
|
|
subclass.prototype = parent.prototype; |
|
113
|
|
|
klass.prototype = new subclass; |
|
|
|
|
|
|
114
|
|
|
parent.subclasses.push(klass); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
for (var i = 0; i < properties.length; i++) |
|
118
|
|
|
klass.addMethods(properties[i]); |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
if (!klass.prototype.initialize) |
|
121
|
|
|
klass.prototype.initialize = function() {}; |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
klass.prototype.constructor = klass; |
|
124
|
|
|
|
|
125
|
|
|
return klass; |
|
126
|
|
|
}, |
|
127
|
|
|
delegate: function(rules) { |
|
128
|
|
|
return function(e) { |
|
129
|
|
|
var target = $(e.target), parent = null; |
|
130
|
|
|
for (var selector in rules) { |
|
|
|
|
|
|
131
|
|
|
if (target.is(selector) || ((parent = target.parents(selector)) && parent.length > 0)) { |
|
132
|
|
|
return rules[selector].apply(this, [parent || target].concat($.makeArray(arguments))); |
|
133
|
|
|
} |
|
134
|
|
|
parent = null; |
|
135
|
|
|
} |
|
|
|
|
|
|
136
|
|
|
}; |
|
137
|
|
|
} |
|
138
|
|
|
}); |
|
139
|
|
|
/* |
|
140
|
|
|
var bindEvents = function(instance) { |
|
141
|
|
|
for (var member in instance) { |
|
142
|
|
|
if (member.match(/^on(.+)/) && typeof instance[member] == 'function') { |
|
143
|
|
|
instance.element.live(RegExp.$1, {'behavior': instance}, instance[member]); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
}; |
|
147
|
|
|
|
|
148
|
|
|
var behaviorWrapper = function(behavior) { |
|
149
|
|
|
return $.klass(behavior, { |
|
150
|
|
|
initialize: function($super, element, args) { |
|
151
|
|
|
this.element = element; |
|
152
|
|
|
if ($super) $super.apply(this, args); |
|
153
|
|
|
}, |
|
154
|
|
|
trigger: function(eventType, extraParameters) { |
|
155
|
|
|
var parameters = [this].concat(extraParameters); |
|
156
|
|
|
this.element.trigger(eventType, parameters); |
|
157
|
|
|
} |
|
158
|
|
|
}); |
|
159
|
|
|
}; |
|
160
|
|
|
|
|
161
|
|
|
var attachBehavior = function(el, behavior, args) { |
|
162
|
|
|
var wrapper = behaviorWrapper(behavior); |
|
163
|
|
|
var instance = new wrapper(el, args); |
|
164
|
|
|
|
|
165
|
|
|
bindEvents(instance); |
|
166
|
|
|
|
|
167
|
|
|
if (!behavior.instances) behavior.instances = []; |
|
168
|
|
|
|
|
169
|
|
|
behavior.instances.push(instance); |
|
170
|
|
|
|
|
171
|
|
|
return instance; |
|
172
|
|
|
}; |
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
$.fn.extend({ |
|
176
|
|
|
attach: function() { |
|
177
|
|
|
var args = $.makeArray(arguments), behavior = args.shift(); |
|
178
|
|
|
attachBehavior(this, behavior, args); |
|
179
|
|
|
return this; |
|
180
|
|
|
}, |
|
181
|
|
|
delegate: function(type, rules) { |
|
182
|
|
|
return this.bind(type, $.delegate(rules)); |
|
183
|
|
|
}, |
|
184
|
|
|
attached: function(behavior) { |
|
185
|
|
|
var instances = []; |
|
186
|
|
|
|
|
187
|
|
|
if (!behavior.instances) return instances; |
|
188
|
|
|
|
|
189
|
|
|
this.each(function(i, element) { |
|
190
|
|
|
$.each(behavior.instances, function(i, instance) { |
|
191
|
|
|
if (instance.element.get(0) == element) instances.push(instance); |
|
192
|
|
|
}); |
|
193
|
|
|
}); |
|
194
|
|
|
|
|
195
|
|
|
return instances; |
|
196
|
|
|
}, |
|
197
|
|
|
firstAttached: function(behavior) { |
|
198
|
|
|
return this.attached(behavior)[0]; |
|
199
|
|
|
} |
|
200
|
|
|
}); |
|
201
|
|
|
|
|
202
|
|
|
Remote = $.klass({ |
|
203
|
|
|
initialize: function(options) { |
|
204
|
|
|
if (this.element.attr('nodeName') == 'FORM') this.element.attach(Remote.Form, options); |
|
205
|
|
|
else this.element.attach(Remote.Link, options); |
|
206
|
|
|
} |
|
207
|
|
|
}); |
|
208
|
|
|
|
|
209
|
|
|
Remote.Base = $.klass({ |
|
210
|
|
|
initialize : function(options) { |
|
211
|
|
|
this.options = $.extend(true, {}, options || {}); |
|
212
|
|
|
}, |
|
213
|
|
|
_makeRequest : function(options) { |
|
214
|
|
|
$.ajax(options); |
|
215
|
|
|
return false; |
|
216
|
|
|
} |
|
217
|
|
|
}); |
|
218
|
|
|
|
|
219
|
|
|
Remote.Link = $.klass(Remote.Base, { |
|
220
|
|
|
onclick: function(e) { |
|
221
|
|
|
var options = $.extend({ |
|
222
|
|
|
url: $(this).attr('href'), |
|
223
|
|
|
type: 'GET' |
|
224
|
|
|
}, this.options); |
|
225
|
|
|
return e.data.behavior._makeRequest(e.data.behavior.options); |
|
226
|
|
|
} |
|
227
|
|
|
}); |
|
228
|
|
|
|
|
229
|
|
|
Remote.Form = $.klass(Remote.Base, { |
|
230
|
|
|
onclick: function(e) { |
|
231
|
|
|
var target = e.target; |
|
232
|
|
|
|
|
233
|
|
|
if ($.inArray(target.nodeName.toLowerCase(), ['input', 'button']) >= 0 && target.type.match(/submit|image/)) |
|
234
|
|
|
e.data.behavior._submitButton = target; |
|
235
|
|
|
}, |
|
236
|
|
|
onsubmit: function(e) { |
|
237
|
|
|
var elm = $(this), data = elm.serializeArray(); |
|
238
|
|
|
|
|
239
|
|
|
if (e.data.behavior._submitButton) data.push({ |
|
240
|
|
|
name: e.data.behavior._submitButton.name, |
|
241
|
|
|
value: e.data.behavior._submitButton.value |
|
242
|
|
|
}); |
|
243
|
|
|
|
|
244
|
|
|
var options = $.extend({ |
|
245
|
|
|
url : elm.attr('action'), |
|
246
|
|
|
type : elm.attr('method') || 'GET', |
|
247
|
|
|
data : data |
|
248
|
|
|
}, e.data.behavior.options); |
|
249
|
|
|
|
|
250
|
|
|
e.data.behavior._makeRequest(options); |
|
251
|
|
|
|
|
252
|
|
|
return false; |
|
253
|
|
|
} |
|
254
|
|
|
}); |
|
255
|
|
|
|
|
256
|
|
|
$.ajaxSetup({ |
|
257
|
|
|
beforeSend: function(xhr) { |
|
258
|
|
|
if (!this.dataType) |
|
259
|
|
|
xhr.setRequestHeader("Accept", "text/javascript, text/html, application/xml, text/xml, *\/*"); |
|
260
|
|
|
} |
|
261
|
|
|
}); |
|
262
|
|
|
*/ |
|
263
|
|
|
})(jQuery); |
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Prado base namespace |
|
268
|
|
|
* @namespace Prado |
|
269
|
|
|
*/ |
|
270
|
|
|
var Prado = |
|
271
|
|
|
{ |
|
272
|
|
|
/** |
|
273
|
|
|
* Version of Prado clientscripts |
|
274
|
|
|
* @var Version |
|
275
|
|
|
*/ |
|
276
|
|
|
Version: '4.0.0', |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Registry for Prado components |
|
280
|
|
|
* @var Registry |
|
281
|
|
|
*/ |
|
282
|
|
|
Registry: {} |
|
283
|
|
|
}; |
|
284
|
|
|
|
|
285
|
|
|
Prado.RequestManager = |
|
286
|
|
|
{ |
|
287
|
|
|
FIELD_POSTBACK_TARGET : 'PRADO_POSTBACK_TARGET', |
|
288
|
|
|
|
|
289
|
|
|
FIELD_POSTBACK_PARAMETER : 'PRADO_POSTBACK_PARAMETER' |
|
290
|
|
|
}; |
|
291
|
|
|
/** |
|
292
|
|
|
* Performs a PostBack using javascript. |
|
293
|
|
|
* @function Prado.PostBack |
|
294
|
|
|
* @param options - Postback options |
|
295
|
|
|
* @param event - Event that triggered this postback |
|
296
|
|
|
* @... {string} FormID - Form that should be posted back |
|
297
|
|
|
* @... {optional boolean} CausesValidation - Validate before PostBack if true |
|
298
|
|
|
* @... {optional string} ValidationGroup - Group to Validate |
|
299
|
|
|
* @... {optional string} ID - Validation ID |
|
300
|
|
|
* @... {optional string} PostBackUrl - Postback URL |
|
301
|
|
|
* @... {optional boolean} TrackFocus - Keep track of focused element if true |
|
302
|
|
|
* @... {string} EventTarget - Id of element that triggered PostBack |
|
303
|
|
|
* @... {string} EventParameter - EventParameter for PostBack |
|
304
|
|
|
*/ |
|
305
|
|
|
Prado.PostBack = jQuery.klass( |
|
306
|
|
|
{ |
|
307
|
|
|
options : {}, |
|
308
|
|
|
|
|
309
|
|
|
initialize: function(options, event) |
|
310
|
|
|
{ |
|
311
|
|
|
jQuery.extend(this.options, options || {}); |
|
312
|
|
|
this.event = event; |
|
313
|
|
|
this.doPostBack(); |
|
314
|
|
|
}, |
|
315
|
|
|
|
|
316
|
|
|
getForm : function() |
|
317
|
|
|
{ |
|
318
|
|
|
return jQuery("#" + this.options['FormID']).get(0); |
|
319
|
|
|
}, |
|
320
|
|
|
|
|
321
|
|
|
doPostBack : function() |
|
322
|
|
|
{ |
|
323
|
|
|
var form = this.getForm(); |
|
324
|
|
|
if(this.options['CausesValidation'] && typeof(Prado.Validation) != "undefined") |
|
325
|
|
|
{ |
|
326
|
|
|
if(!Prado.Validation.validate(this.options['FormID'], this.options['ValidationGroup'], jQuery("#" + this.options['ID']))) |
|
327
|
|
|
return this.event.preventDefault(); |
|
|
|
|
|
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
if(this.options['PostBackUrl'] && this.options['PostBackUrl'].length > 0) |
|
331
|
|
|
form.action = this.options['PostBackUrl']; |
|
|
|
|
|
|
332
|
|
|
|
|
333
|
|
|
if(this.options['TrackFocus']) |
|
334
|
|
|
{ |
|
335
|
|
|
var lastFocus = jQuery('#PRADO_LASTFOCUS'); |
|
336
|
|
|
if(lastFocus) |
|
337
|
|
|
{ |
|
338
|
|
|
var active = document.activeElement; //where did this come from |
|
339
|
|
|
if(active) |
|
340
|
|
|
lastFocus.value = active.id; |
|
|
|
|
|
|
341
|
|
|
else |
|
342
|
|
|
lastFocus.value = this.options['EventTarget']; |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
var input=null; |
|
|
|
|
|
|
347
|
|
|
if(this.options.EventTarget) |
|
348
|
|
|
{ |
|
349
|
|
|
input = document.createElement("input"); |
|
350
|
|
|
input.setAttribute("type", "hidden"); |
|
351
|
|
|
input.setAttribute("name", Prado.RequestManager.FIELD_POSTBACK_TARGET); |
|
352
|
|
|
input.setAttribute("value", this.options.EventTarget); |
|
353
|
|
|
form.appendChild(input); |
|
354
|
|
|
} |
|
355
|
|
|
if(this.options.EventParameter) |
|
356
|
|
|
{ |
|
357
|
|
|
input = document.createElement("input"); |
|
358
|
|
|
input.setAttribute("type", "hidden"); |
|
359
|
|
|
input.setAttribute("name", Prado.RequestManager.FIELD_POSTBACK_PARAMETER); |
|
360
|
|
|
input.setAttribute("value", this.options.EventParameter); |
|
361
|
|
|
form.appendChild(input); |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
jQuery(form).trigger('submit'); |
|
|
|
|
|
|
365
|
|
|
} |
|
366
|
|
|
}); |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* Prado utilities to manipulate DOM elements. |
|
370
|
|
|
* @object Prado.Element |
|
371
|
|
|
*/ |
|
372
|
|
|
Prado.Element = |
|
373
|
|
|
{ |
|
374
|
|
|
/** |
|
375
|
|
|
* Executes a jQuery method on a particular element. |
|
376
|
|
|
* @function ? |
|
377
|
|
|
* @param {string} element - Element id |
|
378
|
|
|
* @param {string} method - method name |
|
379
|
|
|
* @param {array} value - method parameters |
|
|
|
|
|
|
380
|
|
|
*/ |
|
381
|
|
|
j: function(element, method, params) |
|
382
|
|
|
{ |
|
383
|
|
|
var obj=jQuery("#" + element); |
|
384
|
|
|
obj[method].apply(obj, params); |
|
385
|
|
|
}, |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* Select options from a selectable element. |
|
389
|
|
|
* @function ? |
|
390
|
|
|
* @param {string} element - Element id |
|
391
|
|
|
* @param {string} method - Name of any {@link Prado.Element.Selection} method |
|
392
|
|
|
* @param {array|boolean|string} value - Values that should be selected |
|
393
|
|
|
* @param {int} total - Number of elements |
|
394
|
|
|
*/ |
|
395
|
|
|
select : function(element, method, value, total) |
|
396
|
|
|
{ |
|
397
|
|
|
var el = jQuery("#" + element).get(0); |
|
398
|
|
|
if(!el) return; |
|
|
|
|
|
|
399
|
|
|
var selection = Prado.Element.Selection; |
|
400
|
|
|
if(typeof(selection[method]) == "function") |
|
401
|
|
|
{ |
|
402
|
|
|
var control = selection.isSelectable(el) ? [el] : selection.getListElements(element,total); |
|
403
|
|
|
selection[method](control, value); |
|
404
|
|
|
} |
|
405
|
|
|
}, |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* Sets an attribute of a DOM element. |
|
409
|
|
|
* @function ? |
|
410
|
|
|
* @param {string} element - Element id |
|
411
|
|
|
* @param {string} attribute - Name of attribute |
|
412
|
|
|
* @param {string} value - Value of attribute |
|
413
|
|
|
*/ |
|
414
|
|
|
setAttribute : function(element, attribute, value) |
|
415
|
|
|
{ |
|
416
|
|
|
var el = jQuery("#" + element); |
|
417
|
|
|
if(!el) return; |
|
|
|
|
|
|
418
|
|
|
if((attribute == "disabled" || attribute == "multiple" || attribute == "readonly" || attribute == "href") && value==false) |
|
419
|
|
|
el.removeAttr(attribute); |
|
|
|
|
|
|
420
|
|
|
else if(attribute.match(/^on/i)) //event methods |
|
421
|
|
|
{ |
|
422
|
|
|
try |
|
423
|
|
|
{ |
|
424
|
|
|
eval("(func = function(event){"+value+"})"); |
|
|
|
|
|
|
425
|
|
|
el.get(0)[attribute] = func; |
|
|
|
|
|
|
426
|
|
|
} |
|
427
|
|
|
catch(e) |
|
428
|
|
|
{ |
|
429
|
|
|
debugger; |
|
|
|
|
|
|
430
|
|
|
throw "Error in evaluating '"+value+"' for attribute "+attribute+" for element "+element; |
|
431
|
|
|
} |
|
432
|
|
|
} |
|
433
|
|
|
else |
|
434
|
|
|
el.attr(attribute, value); |
|
|
|
|
|
|
435
|
|
|
}, |
|
436
|
|
|
|
|
437
|
|
|
scrollTo : function(element, options) |
|
438
|
|
|
{ |
|
439
|
|
|
var op = { |
|
440
|
|
|
duration : 500, |
|
441
|
|
|
offset : 50 |
|
442
|
|
|
}; |
|
443
|
|
|
jQuery.extend(op, options || {}); |
|
444
|
|
|
jQuery('html, body').animate({ |
|
445
|
|
|
scrollTop: jQuery("#"+element).offset().top - op.offset |
|
446
|
|
|
}, op.duration); |
|
447
|
|
|
}, |
|
448
|
|
|
|
|
449
|
|
|
focus : function(element) |
|
450
|
|
|
{ |
|
451
|
|
|
if(jQuery.active > 0) |
|
452
|
|
|
{ |
|
453
|
|
|
setTimeout(function(){ |
|
454
|
|
|
jQuery("#"+element).focus(); |
|
455
|
|
|
}, 100); |
|
456
|
|
|
} else { |
|
457
|
|
|
jQuery("#"+element).focus(); |
|
458
|
|
|
} |
|
459
|
|
|
}, |
|
460
|
|
|
|
|
461
|
|
|
/** |
|
462
|
|
|
* Sets the options for a select element. |
|
463
|
|
|
* @function ? |
|
464
|
|
|
* @param {string} element - Element id |
|
465
|
|
|
* @param {array[]} options - Array of options, each an array of structure |
|
466
|
|
|
* [ "optionText" , "optionValue" , "optionGroup" ] |
|
467
|
|
|
*/ |
|
468
|
|
|
setOptions : function(element, options) |
|
469
|
|
|
{ |
|
470
|
|
|
var el = jQuery("#" + element).get(0); |
|
471
|
|
|
var previousGroup = null; |
|
|
|
|
|
|
472
|
|
|
var optGroup=null; |
|
|
|
|
|
|
473
|
|
|
if(el && el.tagName.toLowerCase() == "select") |
|
474
|
|
|
{ |
|
475
|
|
|
while(el.childNodes.length > 0) |
|
476
|
|
|
el.removeChild(el.lastChild); |
|
|
|
|
|
|
477
|
|
|
|
|
478
|
|
|
var optDom = Prado.Element.createOptions(options); |
|
479
|
|
|
for(var i = 0; i < optDom.length; i++) |
|
480
|
|
|
el.appendChild(optDom[i]); |
|
|
|
|
|
|
481
|
|
|
} |
|
482
|
|
|
}, |
|
483
|
|
|
|
|
484
|
|
|
/** |
|
485
|
|
|
* Create opt-group options from an array of options. |
|
486
|
|
|
* @function {array} ? |
|
487
|
|
|
* @param {array[]} options - Array of options, each an array of structure |
|
488
|
|
|
* [ "optionText" , "optionValue" , "optionGroup" ] |
|
489
|
|
|
* @returns Array of option DOM elements |
|
490
|
|
|
*/ |
|
491
|
|
|
createOptions : function(options) |
|
492
|
|
|
{ |
|
493
|
|
|
var previousGroup = null; |
|
494
|
|
|
var optgroup=null; |
|
495
|
|
|
var result = []; |
|
496
|
|
|
for(var i = 0; i<options.length; i++) |
|
497
|
|
|
{ |
|
498
|
|
|
var option = options[i]; |
|
499
|
|
|
if(option.length > 2) |
|
500
|
|
|
{ |
|
501
|
|
|
var group = option[2]; |
|
502
|
|
|
if(group!=previousGroup) |
|
503
|
|
|
{ |
|
504
|
|
|
if(previousGroup!=null && optgroup!=null) |
|
505
|
|
|
{ |
|
506
|
|
|
result.push(optgroup); |
|
507
|
|
|
previousGroup=null; |
|
|
|
|
|
|
508
|
|
|
optgroup=null; |
|
|
|
|
|
|
509
|
|
|
} |
|
510
|
|
|
optgroup = document.createElement('optgroup'); |
|
511
|
|
|
optgroup.label = group; |
|
512
|
|
|
previousGroup = group; |
|
513
|
|
|
} |
|
514
|
|
|
} |
|
515
|
|
|
var opt = document.createElement('option'); |
|
516
|
|
|
opt.text = option[0]; |
|
517
|
|
|
opt.innerHTML = option[0]; |
|
518
|
|
|
opt.value = option[1]; |
|
519
|
|
|
if(optgroup!=null) |
|
520
|
|
|
optgroup.appendChild(opt); |
|
|
|
|
|
|
521
|
|
|
else |
|
522
|
|
|
result.push(opt); |
|
523
|
|
|
} |
|
524
|
|
|
if(optgroup!=null) |
|
525
|
|
|
result.push(optgroup); |
|
|
|
|
|
|
526
|
|
|
return result; |
|
527
|
|
|
}, |
|
528
|
|
|
|
|
529
|
|
|
/** |
|
530
|
|
|
* Replace a DOM element either with given content or |
|
531
|
|
|
* with content from a CallBack response boundary |
|
532
|
|
|
* using a replacement method. |
|
533
|
|
|
* @function ? |
|
534
|
|
|
* @param {string|element} element - DOM element or element id |
|
535
|
|
|
* @param {optional string} content - New content of element |
|
536
|
|
|
* @param {optional string} boundary - Boundary of new content |
|
537
|
|
|
* @param {optional boolean} self - Whether to replace itself or just the inner content |
|
538
|
|
|
*/ |
|
539
|
|
|
replace : function(element, content, boundary, self) |
|
540
|
|
|
{ |
|
541
|
|
|
if(boundary) |
|
542
|
|
|
{ |
|
543
|
|
|
var result = this.extractContent(boundary); |
|
544
|
|
|
if(result != null) |
|
545
|
|
|
content = result; |
|
|
|
|
|
|
546
|
|
|
} |
|
547
|
|
|
if(self) |
|
548
|
|
|
jQuery('#'+element).replaceWith(content); |
|
|
|
|
|
|
549
|
|
|
else |
|
550
|
|
|
jQuery('#'+element).html(content); |
|
551
|
|
|
}, |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* Appends a javascript block to the document. |
|
555
|
|
|
* @function ? |
|
556
|
|
|
* @param {string} boundary - Boundary containing the javascript code |
|
557
|
|
|
*/ |
|
558
|
|
|
appendScriptBlock : function(boundary) |
|
559
|
|
|
{ |
|
560
|
|
|
var content = this.extractContent(boundary); |
|
561
|
|
|
if(content == null) |
|
562
|
|
|
return; |
|
|
|
|
|
|
563
|
|
|
|
|
564
|
|
|
var el = document.createElement("script"); |
|
565
|
|
|
el.type = "text/javascript"; |
|
566
|
|
|
el.id = 'inline_' + boundary; |
|
567
|
|
|
el.text = content; |
|
568
|
|
|
|
|
569
|
|
|
(document.getElementsByTagName('head')[0] || document.documentElement).appendChild(el); |
|
570
|
|
|
el.parentNode.removeChild(el); |
|
571
|
|
|
}, |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* Evaluate a javascript snippet from a string. |
|
575
|
|
|
* @function ? |
|
576
|
|
|
* @param {string} content - String containing the script |
|
577
|
|
|
* @param {string} boundary - Boundary containing the script |
|
578
|
|
|
*/ |
|
579
|
|
|
evaluateScript : function(content, boundary) |
|
580
|
|
|
{ |
|
581
|
|
|
if(boundary) |
|
582
|
|
|
{ |
|
583
|
|
|
var result = this.extractContent(boundary); |
|
584
|
|
|
if(result != null) |
|
585
|
|
|
content = result; |
|
|
|
|
|
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
try |
|
589
|
|
|
{ |
|
590
|
|
|
jQuery.globalEval(content); |
|
591
|
|
|
} |
|
592
|
|
|
catch(e) |
|
593
|
|
|
{ |
|
594
|
|
|
if(typeof(Logger) != "undefined") |
|
|
|
|
|
|
595
|
|
|
Logger.error('Error during evaluation of script "'+content+'"'); |
|
|
|
|
|
|
596
|
|
|
else |
|
597
|
|
|
debugger; |
|
|
|
|
|
|
598
|
|
|
throw e; |
|
599
|
|
|
} |
|
600
|
|
|
} |
|
601
|
|
|
}; |
|
602
|
|
|
|
|
603
|
|
|
/** |
|
604
|
|
|
* Utilities for selections. |
|
605
|
|
|
* @object Prado.Element.Selection |
|
606
|
|
|
*/ |
|
607
|
|
|
Prado.Element.Selection = |
|
608
|
|
|
{ |
|
609
|
|
|
/** |
|
610
|
|
|
* Check if an DOM element can be selected. |
|
611
|
|
|
* @function {boolean} ? |
|
612
|
|
|
* @param {element} el - DOM elemet |
|
613
|
|
|
* @returns true if element is selectable |
|
614
|
|
|
*/ |
|
615
|
|
|
isSelectable : function(el) |
|
616
|
|
|
{ |
|
617
|
|
|
if(el && el.type) |
|
618
|
|
|
{ |
|
619
|
|
|
switch(el.type.toLowerCase()) |
|
|
|
|
|
|
620
|
|
|
{ |
|
621
|
|
|
case 'checkbox': |
|
622
|
|
|
case 'radio': |
|
623
|
|
|
case 'select': |
|
624
|
|
|
case 'select-multiple': |
|
625
|
|
|
case 'select-one': |
|
626
|
|
|
return true; |
|
627
|
|
|
} |
|
628
|
|
|
} |
|
629
|
|
|
return false; |
|
630
|
|
|
}, |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* Set checked attribute of a checkbox or radiobutton to value. |
|
634
|
|
|
* @function {boolean} ? |
|
635
|
|
|
* @param {element} el - DOM element |
|
636
|
|
|
* @param {boolean} value - New value of checked attribute |
|
637
|
|
|
* @returns New value of checked attribute |
|
638
|
|
|
*/ |
|
639
|
|
|
inputValue : function(el, value) |
|
640
|
|
|
{ |
|
641
|
|
|
switch(el.type.toLowerCase()) |
|
|
|
|
|
|
642
|
|
|
{ |
|
643
|
|
|
case 'checkbox': |
|
644
|
|
|
case 'radio': |
|
645
|
|
|
return el.checked = value; |
|
646
|
|
|
} |
|
|
|
|
|
|
647
|
|
|
}, |
|
648
|
|
|
|
|
649
|
|
|
/** |
|
650
|
|
|
* Set selected attribute for elements options by value. |
|
651
|
|
|
* If value is boolean, all elements options selected attribute will be set |
|
652
|
|
|
* to value. Otherwhise all options that have the given value will be selected. |
|
653
|
|
|
* @function ? |
|
654
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
655
|
|
|
* @param {boolean|string} value - Value of options that should be selected or boolean value of selection status |
|
656
|
|
|
*/ |
|
657
|
|
|
selectValue : function(elements, value) |
|
658
|
|
|
{ |
|
659
|
|
|
jQuery.each(elements, function(idx, el) |
|
660
|
|
|
{ |
|
661
|
|
|
jQuery.each(el.options, function(idx, option) |
|
662
|
|
|
{ |
|
663
|
|
|
if(typeof(value) == "boolean") |
|
664
|
|
|
option.selected = value; |
|
|
|
|
|
|
665
|
|
|
else if(option.value == value) |
|
666
|
|
|
option.selected = true; |
|
|
|
|
|
|
667
|
|
|
}); |
|
668
|
|
|
}) |
|
669
|
|
|
}, |
|
670
|
|
|
|
|
671
|
|
|
/** |
|
672
|
|
|
* Set selected attribute for elements options by array of values. |
|
673
|
|
|
* @function ? |
|
674
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
675
|
|
|
* @param {string[]} value - Array of values to select |
|
|
|
|
|
|
676
|
|
|
*/ |
|
677
|
|
|
selectValues : function(elements, values) |
|
678
|
|
|
{ |
|
679
|
|
|
var selection = this; |
|
680
|
|
|
jQuery.each(values, function(idx, value) |
|
681
|
|
|
{ |
|
682
|
|
|
selection.selectValue(elements,value); |
|
683
|
|
|
}) |
|
684
|
|
|
}, |
|
685
|
|
|
|
|
686
|
|
|
/** |
|
687
|
|
|
* Set selected attribute for elements options by option index. |
|
688
|
|
|
* @function ? |
|
689
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
690
|
|
|
* @param {int} index - Index of option to select |
|
691
|
|
|
*/ |
|
692
|
|
|
selectIndex : function(elements, index) |
|
693
|
|
|
{ |
|
694
|
|
|
jQuery.each(elements, function(idx, el) |
|
695
|
|
|
{ |
|
696
|
|
|
if(el.type.toLowerCase() == 'select-one') |
|
697
|
|
|
el.selectedIndex = index; |
|
|
|
|
|
|
698
|
|
|
else |
|
699
|
|
|
{ |
|
700
|
|
|
for(var i = 0; i<el.length; i++) |
|
701
|
|
|
{ |
|
702
|
|
|
if(i == index) |
|
703
|
|
|
el.options[i].selected = true; |
|
|
|
|
|
|
704
|
|
|
} |
|
705
|
|
|
} |
|
706
|
|
|
}) |
|
707
|
|
|
}, |
|
708
|
|
|
|
|
709
|
|
|
/** |
|
710
|
|
|
* Set selected attribute to true for all elements options. |
|
711
|
|
|
* @function ? |
|
712
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
713
|
|
|
*/ |
|
714
|
|
|
selectAll : function(elements) |
|
715
|
|
|
{ |
|
716
|
|
|
jQuery.each(elements, function(idx, el) |
|
717
|
|
|
{ |
|
718
|
|
|
if(el.type.toLowerCase() != 'select-one') |
|
719
|
|
|
{ |
|
720
|
|
|
jQuery.each(el.options, function(idx, option) |
|
721
|
|
|
{ |
|
722
|
|
|
option.selected = true; |
|
723
|
|
|
}) |
|
724
|
|
|
} |
|
725
|
|
|
}) |
|
726
|
|
|
}, |
|
727
|
|
|
|
|
728
|
|
|
/** |
|
729
|
|
|
* Toggle the selected attribute for elements options. |
|
730
|
|
|
* @function ? |
|
731
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
732
|
|
|
*/ |
|
733
|
|
|
selectInvert : function(elements) |
|
734
|
|
|
{ |
|
735
|
|
|
jQuery.each(elements, function(idx, el) |
|
736
|
|
|
{ |
|
737
|
|
|
if(el.type.toLowerCase() != 'select-one') |
|
738
|
|
|
{ |
|
739
|
|
|
jQuery.each(el.options, function(idx, option) |
|
740
|
|
|
{ |
|
741
|
|
|
option.selected = !option.selected; |
|
742
|
|
|
}) |
|
743
|
|
|
} |
|
744
|
|
|
}) |
|
745
|
|
|
}, |
|
746
|
|
|
|
|
747
|
|
|
/** |
|
748
|
|
|
* Set selected attribute for elements options by array of option indices. |
|
749
|
|
|
* @function ? |
|
750
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
751
|
|
|
* @param {int[]} indices - Array of option indices to select |
|
752
|
|
|
*/ |
|
753
|
|
|
selectIndices : function(elements, indices) |
|
754
|
|
|
{ |
|
755
|
|
|
var selection = this; |
|
756
|
|
|
jQuery.each(indices, function(idx, index) |
|
757
|
|
|
{ |
|
758
|
|
|
selection.selectIndex(elements,index); |
|
759
|
|
|
}) |
|
760
|
|
|
}, |
|
761
|
|
|
|
|
762
|
|
|
/** |
|
763
|
|
|
* Unselect elements. |
|
764
|
|
|
* @function ? |
|
765
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
766
|
|
|
*/ |
|
767
|
|
|
selectClear : function(elements) |
|
768
|
|
|
{ |
|
769
|
|
|
jQuery.each(elements, function(idx, el) |
|
770
|
|
|
{ |
|
771
|
|
|
el.selectedIndex = -1; |
|
772
|
|
|
}) |
|
773
|
|
|
}, |
|
774
|
|
|
|
|
775
|
|
|
/** |
|
776
|
|
|
* Get list elements of an element. |
|
777
|
|
|
* @function {element[]} ? |
|
778
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
|
|
|
|
|
779
|
|
|
* @param {int} total - Number of list elements to return |
|
780
|
|
|
* @returns Array of list DOM elements |
|
781
|
|
|
*/ |
|
782
|
|
|
getListElements : function(element, total) |
|
783
|
|
|
{ |
|
784
|
|
|
var elements = new Array(); |
|
|
|
|
|
|
785
|
|
|
var el; |
|
786
|
|
|
for(var i = 0; i < total; i++) |
|
787
|
|
|
{ |
|
788
|
|
|
el = jQuery("#"+element+"_c"+i).get(0); |
|
789
|
|
|
if(el) |
|
790
|
|
|
elements.push(el); |
|
|
|
|
|
|
791
|
|
|
} |
|
792
|
|
|
return elements; |
|
793
|
|
|
}, |
|
794
|
|
|
|
|
795
|
|
|
/** |
|
796
|
|
|
* Set checked attribute of elements by value. |
|
797
|
|
|
* If value is boolean, checked attribute will be set to value. |
|
798
|
|
|
* Otherwhise all elements that have the given value will be checked. |
|
799
|
|
|
* @function ? |
|
800
|
|
|
* @param {element[]} elements - Array of checkable DOM elements |
|
801
|
|
|
* @param {boolean|String} value - Value that should be checked or boolean value of checked status |
|
802
|
|
|
* |
|
803
|
|
|
*/ |
|
804
|
|
|
checkValue : function(elements, value) |
|
805
|
|
|
{ |
|
806
|
|
|
jQuery.each(elements, function(idx, el) |
|
807
|
|
|
{ |
|
808
|
|
|
if(typeof(value) == "boolean") |
|
809
|
|
|
el.checked = value; |
|
|
|
|
|
|
810
|
|
|
else if(el.value == value) |
|
811
|
|
|
el.checked = true; |
|
|
|
|
|
|
812
|
|
|
}); |
|
813
|
|
|
}, |
|
814
|
|
|
|
|
815
|
|
|
/** |
|
816
|
|
|
* Set checked attribute of elements by array of values. |
|
817
|
|
|
* @function ? |
|
818
|
|
|
* @param {element[]} elements - Array of checkable DOM elements |
|
819
|
|
|
* @param {string[]} values - Values that should be checked |
|
820
|
|
|
* |
|
821
|
|
|
*/ |
|
822
|
|
|
checkValues : function(elements, values) |
|
823
|
|
|
{ |
|
824
|
|
|
var selection = this; |
|
825
|
|
|
jQuery(values).each(function(idx, value) |
|
826
|
|
|
{ |
|
827
|
|
|
selection.checkValue(elements, value); |
|
828
|
|
|
}) |
|
829
|
|
|
}, |
|
830
|
|
|
|
|
831
|
|
|
/** |
|
832
|
|
|
* Set checked attribute of elements by list index. |
|
833
|
|
|
* @function ? |
|
834
|
|
|
* @param {element[]} elements - Array of checkable DOM elements |
|
835
|
|
|
* @param {int} index - Index of element to set checked |
|
836
|
|
|
*/ |
|
837
|
|
|
checkIndex : function(elements, index) |
|
838
|
|
|
{ |
|
839
|
|
|
for(var i = 0; i<elements.length; i++) |
|
840
|
|
|
{ |
|
841
|
|
|
if(i == index) |
|
842
|
|
|
elements[i].checked = true; |
|
|
|
|
|
|
843
|
|
|
} |
|
844
|
|
|
}, |
|
845
|
|
|
|
|
846
|
|
|
/** |
|
847
|
|
|
* Set checked attribute of elements by array of list indices. |
|
848
|
|
|
* @function ? |
|
849
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
850
|
|
|
* @param {int[]} indices - Array of list indices to set checked |
|
851
|
|
|
*/ |
|
852
|
|
|
checkIndices : function(elements, indices) |
|
853
|
|
|
{ |
|
854
|
|
|
var selection = this; |
|
855
|
|
|
jQuery.each(indices, function(idx, index) |
|
856
|
|
|
{ |
|
857
|
|
|
selection.checkIndex(elements, index); |
|
858
|
|
|
}) |
|
859
|
|
|
}, |
|
860
|
|
|
|
|
861
|
|
|
/** |
|
862
|
|
|
* Uncheck elements. |
|
863
|
|
|
* @function ? |
|
864
|
|
|
* @param {element[]} elements - Array of checkable DOM elements |
|
865
|
|
|
*/ |
|
866
|
|
|
checkClear : function(elements) |
|
867
|
|
|
{ |
|
868
|
|
|
jQuery.each(elements, function(idx, el) |
|
869
|
|
|
{ |
|
870
|
|
|
el.checked = false; |
|
871
|
|
|
}); |
|
872
|
|
|
}, |
|
873
|
|
|
|
|
874
|
|
|
/** |
|
875
|
|
|
* Set checked attribute of all elements to true. |
|
876
|
|
|
* @function ? |
|
877
|
|
|
* @param {element[]} elements - Array of checkable DOM elements |
|
878
|
|
|
*/ |
|
879
|
|
|
checkAll : function(elements) |
|
880
|
|
|
{ |
|
881
|
|
|
jQuery.each(elements, function(idx, el) |
|
882
|
|
|
{ |
|
883
|
|
|
el.checked = true; |
|
884
|
|
|
}) |
|
885
|
|
|
}, |
|
886
|
|
|
|
|
887
|
|
|
/** |
|
888
|
|
|
* Toggle the checked attribute of elements. |
|
889
|
|
|
* @function ? |
|
890
|
|
|
* @param {element[]} elements - Array of selectable DOM elements |
|
891
|
|
|
*/ |
|
892
|
|
|
checkInvert : function(elements) |
|
893
|
|
|
{ |
|
894
|
|
|
jQuery.each(elements, function(idx, el) |
|
895
|
|
|
{ |
|
896
|
|
|
el.checked = !el.checked; |
|
897
|
|
|
}) |
|
898
|
|
|
} |
|
899
|
|
|
}; |
|
900
|
|
|
|
|
901
|
|
|
jQuery.extend(String.prototype, { |
|
902
|
|
|
|
|
903
|
|
|
/** |
|
904
|
|
|
* Add padding to string |
|
905
|
|
|
* @function {string} ? |
|
906
|
|
|
* @param {string} side - "left" to pad the string on the left, "right" to pad right. |
|
907
|
|
|
* @param {int} len - Minimum string length. |
|
908
|
|
|
* @param {string} chr - Character(s) to pad |
|
909
|
|
|
* @returns Padded string |
|
910
|
|
|
*/ |
|
911
|
|
|
pad : function(side, len, chr) { |
|
912
|
|
|
if (!chr) chr = ' '; |
|
|
|
|
|
|
913
|
|
|
var s = this; |
|
914
|
|
|
var left = side.toLowerCase()=='left'; |
|
915
|
|
|
while (s.length<len) s = left? chr + s : s + chr; |
|
|
|
|
|
|
916
|
|
|
return s; |
|
917
|
|
|
}, |
|
918
|
|
|
|
|
919
|
|
|
/** |
|
920
|
|
|
* Add left padding to string |
|
921
|
|
|
* @function {string} ? |
|
922
|
|
|
* @param {int} len - Minimum string length. |
|
923
|
|
|
* @param {string} chr - Character(s) to pad |
|
924
|
|
|
* @returns Padded string |
|
925
|
|
|
*/ |
|
926
|
|
|
padLeft : function(len, chr) { |
|
927
|
|
|
return this.pad('left',len,chr); |
|
928
|
|
|
}, |
|
929
|
|
|
|
|
930
|
|
|
/** |
|
931
|
|
|
* Add right padding to string |
|
932
|
|
|
* @function {string} ? |
|
933
|
|
|
* @param {int} len - Minimum string length. |
|
934
|
|
|
* @param {string} chr - Character(s) to pad |
|
935
|
|
|
* @returns Padded string |
|
936
|
|
|
*/ |
|
937
|
|
|
padRight : function(len, chr) { |
|
938
|
|
|
return this.pad('right',len,chr); |
|
939
|
|
|
}, |
|
940
|
|
|
|
|
941
|
|
|
/** |
|
942
|
|
|
* Add zeros to the right of string |
|
943
|
|
|
* @function {string} ? |
|
944
|
|
|
* @param {int} len - Minimum string length. |
|
945
|
|
|
* @returns Padded string |
|
946
|
|
|
*/ |
|
947
|
|
|
zerofill : function(len) { |
|
948
|
|
|
return this.padLeft(len,'0'); |
|
949
|
|
|
}, |
|
950
|
|
|
|
|
951
|
|
|
/** |
|
952
|
|
|
* Remove white spaces from both ends of string. |
|
953
|
|
|
* @function {string} ? |
|
954
|
|
|
* @returns Trimmed string |
|
955
|
|
|
*/ |
|
956
|
|
|
trim : function() { |
|
957
|
|
|
return this.replace(/^\s+|\s+$/g,''); |
|
958
|
|
|
}, |
|
959
|
|
|
|
|
960
|
|
|
/** |
|
961
|
|
|
* Remove white spaces from the left side of string. |
|
962
|
|
|
* @function {string} ? |
|
963
|
|
|
* @returns Trimmed string |
|
964
|
|
|
*/ |
|
965
|
|
|
trimLeft : function() { |
|
966
|
|
|
return this.replace(/^\s+/,''); |
|
967
|
|
|
}, |
|
968
|
|
|
|
|
969
|
|
|
/** |
|
970
|
|
|
* Remove white spaces from the right side of string. |
|
971
|
|
|
* @function {string} ? |
|
972
|
|
|
* @returns Trimmed string |
|
973
|
|
|
*/ |
|
974
|
|
|
trimRight : function() { |
|
975
|
|
|
return this.replace(/\s+$/,''); |
|
976
|
|
|
}, |
|
977
|
|
|
|
|
978
|
|
|
/** |
|
979
|
|
|
* Convert period separated function names into a function reference. |
|
980
|
|
|
* <br />Example: |
|
981
|
|
|
* <pre> |
|
982
|
|
|
* "Prado.AJAX.Callback.Action.setValue".toFunction() |
|
983
|
|
|
* </pre> |
|
984
|
|
|
* @function {function} ? |
|
985
|
|
|
* @returns Reference to the corresponding function |
|
986
|
|
|
*/ |
|
987
|
|
|
toFunction : function() |
|
988
|
|
|
{ |
|
989
|
|
|
var commands = this.split(/\./); |
|
990
|
|
|
var command = window; |
|
991
|
|
|
jQuery(commands).each(function(idx, action) |
|
992
|
|
|
{ |
|
993
|
|
|
if(command[new String(action)]) |
|
994
|
|
|
command=command[new String(action)]; |
|
|
|
|
|
|
995
|
|
|
}); |
|
996
|
|
|
if(typeof(command) == "function") |
|
997
|
|
|
return command; |
|
|
|
|
|
|
998
|
|
|
else |
|
999
|
|
|
{ |
|
1000
|
|
|
if(typeof Logger != "undefined") |
|
|
|
|
|
|
1001
|
|
|
Logger.error("Missing function", this); |
|
|
|
|
|
|
1002
|
|
|
|
|
1003
|
|
|
throw new Error ("Missing function '"+this+"'"); |
|
1004
|
|
|
} |
|
1005
|
|
|
}, |
|
1006
|
|
|
|
|
1007
|
|
|
/** |
|
1008
|
|
|
* Convert string into integer, returns null if not integer. |
|
1009
|
|
|
* @function {int} ? |
|
1010
|
|
|
* @returns Integer, null if string does not represent an integer. |
|
1011
|
|
|
*/ |
|
1012
|
|
|
toInteger : function() |
|
1013
|
|
|
{ |
|
1014
|
|
|
var exp = /^\s*[-\+]?\d+\s*$/; |
|
1015
|
|
|
if (this.match(exp) == null) |
|
1016
|
|
|
return null; |
|
|
|
|
|
|
1017
|
|
|
var num = parseInt(this, 10); |
|
1018
|
|
|
return (isNaN(num) ? null : num); |
|
1019
|
|
|
}, |
|
1020
|
|
|
|
|
1021
|
|
|
/** |
|
1022
|
|
|
* Convert string into a double/float value. <b>Internationalization |
|
1023
|
|
|
* is not supported</b> |
|
1024
|
|
|
* @function {double} ? |
|
1025
|
|
|
* @param {string} decimalchar - Decimal character, defaults to "." |
|
1026
|
|
|
* @returns Double, null if string does not represent a float value |
|
1027
|
|
|
*/ |
|
1028
|
|
|
toDouble : function(decimalchar) |
|
1029
|
|
|
{ |
|
1030
|
|
|
if(this.length <= 0) return null; |
|
|
|
|
|
|
1031
|
|
|
decimalchar = decimalchar || "."; |
|
1032
|
|
|
var exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$"); |
|
1033
|
|
|
var m = this.match(exp); |
|
1034
|
|
|
|
|
1035
|
|
|
if (m == null) |
|
1036
|
|
|
return null; |
|
|
|
|
|
|
1037
|
|
|
m[1] = m[1] || ""; |
|
1038
|
|
|
m[2] = m[2] || "0"; |
|
1039
|
|
|
m[4] = m[4] || "0"; |
|
1040
|
|
|
|
|
1041
|
|
|
var cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4]; |
|
1042
|
|
|
var num = parseFloat(cleanInput); |
|
1043
|
|
|
return (isNaN(num) ? null : num); |
|
1044
|
|
|
}, |
|
1045
|
|
|
|
|
1046
|
|
|
/** |
|
1047
|
|
|
* Convert strings that represent a currency value to float. |
|
1048
|
|
|
* E.g. "10,000.50" will become "10000.50". The number |
|
1049
|
|
|
* of dicimal digits, grouping and decimal characters can be specified. |
|
1050
|
|
|
* <i>The currency input format is <b>very</b> strict, null will be returned if |
|
1051
|
|
|
* the pattern does not match</i>. |
|
1052
|
|
|
* @function {double} ? |
|
1053
|
|
|
* @param {string} groupchar - Grouping character, defaults to "," |
|
1054
|
|
|
* @param {int} digits - Number of decimal digits |
|
1055
|
|
|
* @param {string} decimalchar - Decimal character, defaults to "." |
|
1056
|
|
|
* @returns Double, null if string does not represent a currency value |
|
1057
|
|
|
*/ |
|
1058
|
|
|
toCurrency : function(groupchar, digits, decimalchar) |
|
1059
|
|
|
{ |
|
1060
|
|
|
groupchar = groupchar || ","; |
|
1061
|
|
|
decimalchar = decimalchar || "."; |
|
1062
|
|
|
digits = typeof(digits) == "undefined" ? 2 : digits; |
|
1063
|
|
|
|
|
1064
|
|
|
var exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + groupchar + ")*)(\\d+)" |
|
1065
|
|
|
+ ((digits > 0) ? "(\\" + decimalchar + "(\\d{1," + digits + "}))?" : "") |
|
1066
|
|
|
+ "\\s*$"); |
|
1067
|
|
|
var m = this.match(exp); |
|
1068
|
|
|
if (m == null) |
|
1069
|
|
|
return null; |
|
|
|
|
|
|
1070
|
|
|
var intermed = m[2] + m[5] ; |
|
1071
|
|
|
var cleanInput = m[1] + intermed.replace( |
|
1072
|
|
|
new RegExp("(\\" + groupchar + ")", "g"), "") |
|
1073
|
|
|
+ ((digits > 0) ? "." + m[7] : ""); |
|
1074
|
|
|
var num = parseFloat(cleanInput); |
|
1075
|
|
|
return (isNaN(num) ? null : num); |
|
1076
|
|
|
} |
|
1077
|
|
|
}); |
|
1078
|
|
|
|
|
1079
|
|
|
jQuery.extend(Date.prototype, |
|
1080
|
|
|
{ |
|
1081
|
|
|
/** |
|
1082
|
|
|
* SimpleFormat |
|
1083
|
|
|
* @function ? |
|
1084
|
|
|
* @param {string} format - TODO |
|
1085
|
|
|
* @param {string} data - TODO |
|
1086
|
|
|
* @returns TODO |
|
1087
|
|
|
*/ |
|
1088
|
|
|
SimpleFormat: function(format, data) |
|
1089
|
|
|
{ |
|
1090
|
|
|
data = data || {}; |
|
1091
|
|
|
var bits = new Array(); |
|
|
|
|
|
|
1092
|
|
|
bits['d'] = this.getDate(); |
|
1093
|
|
|
bits['dd'] = String(this.getDate()).zerofill(2); |
|
1094
|
|
|
|
|
1095
|
|
|
bits['M'] = this.getMonth()+1; |
|
1096
|
|
|
bits['MM'] = String(this.getMonth()+1).zerofill(2); |
|
1097
|
|
|
if(data.AbbreviatedMonthNames) |
|
1098
|
|
|
bits['MMM'] = data.AbbreviatedMonthNames[this.getMonth()]; |
|
|
|
|
|
|
1099
|
|
|
if(data.MonthNames) |
|
1100
|
|
|
bits['MMMM'] = data.MonthNames[this.getMonth()]; |
|
|
|
|
|
|
1101
|
|
|
var yearStr = "" + this.getFullYear(); |
|
1102
|
|
|
yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr; |
|
1103
|
|
|
bits['yyyy'] = yearStr; |
|
1104
|
|
|
bits['yy'] = bits['yyyy'].toString().substr(2,2); |
|
1105
|
|
|
|
|
1106
|
|
|
// do some funky regexs to replace the format string |
|
1107
|
|
|
// with the real values |
|
1108
|
|
|
var frm = new String(format); |
|
1109
|
|
|
for (var sect in bits) |
|
|
|
|
|
|
1110
|
|
|
{ |
|
1111
|
|
|
var reg = new RegExp("\\b"+sect+"\\b" ,"g"); |
|
1112
|
|
|
frm = frm.replace(reg, bits[sect]); |
|
1113
|
|
|
} |
|
1114
|
|
|
return frm; |
|
1115
|
|
|
}, |
|
1116
|
|
|
|
|
1117
|
|
|
/** |
|
1118
|
|
|
* toISODate |
|
1119
|
|
|
* @function {string} ? |
|
1120
|
|
|
* @returns TODO |
|
1121
|
|
|
*/ |
|
1122
|
|
|
toISODate : function() |
|
1123
|
|
|
{ |
|
1124
|
|
|
var y = this.getFullYear(); |
|
1125
|
|
|
var m = String(this.getMonth() + 1).zerofill(2); |
|
1126
|
|
|
var d = String(this.getDate()).zerofill(2); |
|
1127
|
|
|
return String(y) + String(m) + String(d); |
|
1128
|
|
|
} |
|
1129
|
|
|
}); |
|
1130
|
|
|
|
|
1131
|
|
|
jQuery.extend(Date, |
|
1132
|
|
|
{ |
|
1133
|
|
|
/** |
|
1134
|
|
|
* SimpleParse |
|
1135
|
|
|
* @function ? |
|
1136
|
|
|
* @param {string} format - TODO |
|
1137
|
|
|
* @param {string} data - TODO |
|
|
|
|
|
|
1138
|
|
|
* @returns TODO |
|
1139
|
|
|
*/ |
|
1140
|
|
|
SimpleParse: function(value, format) |
|
1141
|
|
|
{ |
|
1142
|
|
|
var val=String(value); |
|
1143
|
|
|
format=String(format); |
|
1144
|
|
|
|
|
1145
|
|
|
if(val.length <= 0) return null; |
|
|
|
|
|
|
1146
|
|
|
|
|
1147
|
|
|
if(format.length <= 0) return new Date(value); |
|
|
|
|
|
|
1148
|
|
|
|
|
1149
|
|
|
var isInteger = function (val) |
|
1150
|
|
|
{ |
|
1151
|
|
|
var digits="1234567890"; |
|
1152
|
|
|
for (var i=0; i < val.length; i++) |
|
1153
|
|
|
{ |
|
1154
|
|
|
if (digits.indexOf(val.charAt(i))==-1) { return false; } |
|
1155
|
|
|
} |
|
1156
|
|
|
return true; |
|
1157
|
|
|
}; |
|
1158
|
|
|
|
|
1159
|
|
|
var getInt = function(str,i,minlength,maxlength) |
|
1160
|
|
|
{ |
|
1161
|
|
|
for (var x=maxlength; x>=minlength; x--) |
|
1162
|
|
|
{ |
|
1163
|
|
|
var token=str.substring(i,i+x); |
|
1164
|
|
|
if (token.length < minlength) { return null; } |
|
1165
|
|
|
if (isInteger(token)) { return token; } |
|
1166
|
|
|
} |
|
1167
|
|
|
return null; |
|
1168
|
|
|
}; |
|
1169
|
|
|
|
|
1170
|
|
|
var i_val=0; |
|
1171
|
|
|
var i_format=0; |
|
1172
|
|
|
var c=""; |
|
1173
|
|
|
var token=""; |
|
1174
|
|
|
var token2=""; |
|
|
|
|
|
|
1175
|
|
|
var x,y; |
|
1176
|
|
|
var now=new Date(); |
|
1177
|
|
|
var year=now.getFullYear(); |
|
1178
|
|
|
var month=now.getMonth()+1; |
|
1179
|
|
|
var date=1; |
|
1180
|
|
|
|
|
1181
|
|
|
while (i_format < format.length) |
|
1182
|
|
|
{ |
|
1183
|
|
|
// Get next token from format string |
|
1184
|
|
|
c=format.charAt(i_format); |
|
1185
|
|
|
token=""; |
|
1186
|
|
|
while ((format.charAt(i_format)==c) && (i_format < format.length)) |
|
1187
|
|
|
{ |
|
1188
|
|
|
token += format.charAt(i_format++); |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
// Extract contents of value based on format token |
|
1192
|
|
|
if (token=="yyyy" || token=="yy" || token=="y") |
|
1193
|
|
|
{ |
|
1194
|
|
|
if (token=="yyyy") { x=4;y=4; } |
|
1195
|
|
|
if (token=="yy") { x=2;y=2; } |
|
1196
|
|
|
if (token=="y") { x=2;y=4; } |
|
1197
|
|
|
year=getInt(val,i_val,x,y); |
|
|
|
|
|
|
1198
|
|
|
if (year==null) { return null; } |
|
1199
|
|
|
i_val += year.length; |
|
1200
|
|
|
if (year.length==2) |
|
1201
|
|
|
{ |
|
1202
|
|
|
if (year > 70) { year=1900+(year-0); } |
|
1203
|
|
|
else { year=2000+(year-0); } |
|
1204
|
|
|
} |
|
1205
|
|
|
} |
|
1206
|
|
|
|
|
1207
|
|
|
else if (token=="MM"||token=="M") |
|
1208
|
|
|
{ |
|
1209
|
|
|
month=getInt(val,i_val,token.length,2); |
|
1210
|
|
|
if(month==null||(month<1)||(month>12)){return null;} |
|
1211
|
|
|
i_val+=month.length; |
|
1212
|
|
|
} |
|
1213
|
|
|
else if (token=="dd"||token=="d") |
|
1214
|
|
|
{ |
|
1215
|
|
|
date=getInt(val,i_val,token.length,2); |
|
1216
|
|
|
if(date==null||(date<1)||(date>31)){return null;} |
|
1217
|
|
|
i_val+=date.length; |
|
1218
|
|
|
} |
|
1219
|
|
|
else |
|
1220
|
|
|
{ |
|
1221
|
|
|
if (val.substring(i_val,i_val+token.length)!=token) {return null;} |
|
1222
|
|
|
else {i_val+=token.length;} |
|
1223
|
|
|
} |
|
1224
|
|
|
} |
|
1225
|
|
|
|
|
1226
|
|
|
// If there are any trailing characters left in the value, it doesn't match |
|
1227
|
|
|
if (i_val != val.length) { return null; } |
|
1228
|
|
|
|
|
1229
|
|
|
// Is date valid for month? |
|
1230
|
|
|
if (month==2) |
|
1231
|
|
|
{ |
|
1232
|
|
|
// Check for leap year |
|
1233
|
|
|
if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year |
|
1234
|
|
|
if (date > 29){ return null; } |
|
1235
|
|
|
} |
|
1236
|
|
|
else { if (date > 28) { return null; } } |
|
1237
|
|
|
} |
|
1238
|
|
|
|
|
1239
|
|
|
if ((month==4)||(month==6)||(month==9)||(month==11)) |
|
1240
|
|
|
{ |
|
1241
|
|
|
if (date > 30) { return null; } |
|
1242
|
|
|
} |
|
1243
|
|
|
|
|
1244
|
|
|
var newdate=new Date(year,month-1,date, 0, 0, 0); |
|
1245
|
|
|
return newdate; |
|
1246
|
|
|
} |
|
1247
|
|
|
}); |
|
1248
|
|
|
|