summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/base
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/Javascripts/base')
-rw-r--r--framework/Web/Javascripts/base/ajax.js76
-rw-r--r--framework/Web/Javascripts/base/date.js147
-rw-r--r--framework/Web/Javascripts/base/datepicker.js274
-rw-r--r--framework/Web/Javascripts/base/prado.js3
-rw-r--r--framework/Web/Javascripts/base/rico.js175
-rw-r--r--framework/Web/Javascripts/base/util.js92
-rw-r--r--framework/Web/Javascripts/base/validation.js80
-rw-r--r--framework/Web/Javascripts/base/validators.js18
8 files changed, 506 insertions, 359 deletions
diff --git a/framework/Web/Javascripts/base/ajax.js b/framework/Web/Javascripts/base/ajax.js
index ccfb085d..06c3d741 100644
--- a/framework/Web/Javascripts/base/ajax.js
+++ b/framework/Web/Javascripts/base/ajax.js
@@ -386,86 +386,16 @@ Prado.AJAX.Validate = function(options)
if(options.CausesValidation)
{
if(options.ValidatorGroup)
- return Prado.AJAX.ValidateGroup1(options.ValidatorGroup);
+ return Prado.Validation.ValidateValidatorGroup(options.ValidatorGroup);
else if(options.ValidationGroup)
- return Prado.AJAX.ValidateGroup2(options.ValidationGroup);
+ return Prado.Validation.ValidateValidationGroup(options.ValidationGroup);
else
- return Prado.AJAX.ValidateOthers(options.ValidationForm);
+ return Prado.Validation.ValidateNonGroup(options.ValidationForm);
}
else
return true;
};
-/**
- * Validate Validator Groups.
- * @param string ValidatorGroup
- * @return boolean true if valid, false otherwise
- */
-Prado.AJAX.ValidateGroup1 = function(groupId)
-{
- var groups = Prado.Validation.groups;
- var group = null;
- for(var i = 0; i < groups.length; i++)
- {
- if(groups[i].id == groupId)
- {
- group = groups[i];
- Prado.Validation.groups[i].active = true;
- Prado.Validation.CurrentTargetGroup = null;
- Prado.Validation.IsGroupValidation = true;
- }
- else
- {
- Prado.Validation.groups[i].active = false;
- }
- }
- if(group)
- {
- return Prado.Validation.IsValid(group.target.form);
- }
- return true;
-};
-
-/**
- * Validate ValidationGroup
- * @param string ValidationGroup
- * @return boolean true if valid, false otherwise.
- */
-Prado.AJAX.ValidateGroup2 = function(groupId)
-{
- var groups = Prado.Validation.TargetGroups;
- for(var id in groups)
- {
- if(groups[id] == groupId)
- {
- var target = $(id);
- Prado.Validation.ActiveTarget = target;
- Prado.Validation.CurrentTargetGroup = groupId;
- Prado.Validation.IsGroupValidation = false;
- return Prado.Validation.IsValid(target.form);
- }
- }
- return true;
-};
-
-/**
- * Validate the page
- * @return boolean true if valid, false otherwise.
- */
-Prado.AJAX.ValidateOthers = function(formId)
-{
- if(Prado.Validation)
- {
- var form = $(formId);
- form = form || document.forms[0];
- Prado.Validation.ActiveTarget = form;
- Prado.Validation.CurrentTargetGroup = null;
- Prado.Validation.IsGroupValidation = false;
- return Prado.Validation.IsValid(form);
- }
- return true;
-};
-
//Available callback service
Prado.AJAX.Callback.Server = '';
diff --git a/framework/Web/Javascripts/base/date.js b/framework/Web/Javascripts/base/date.js
new file mode 100644
index 00000000..375c59df
--- /dev/null
+++ b/framework/Web/Javascripts/base/date.js
@@ -0,0 +1,147 @@
+
+Object.extend(Date.prototype,
+{
+ SimpleFormat: function(format)
+ {
+ var bits = new Array();
+ bits['d'] = this.getDate();
+ bits['dd'] = Prado.Util.pad(this.getDate(),2);
+
+ bits['M'] = this.getMonth()+1;
+ bits['MM'] = Prado.Util.pad(this.getMonth()+1,2);
+
+ var yearStr = "" + this.getFullYear();
+ yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr;
+ bits['yyyy'] = yearStr;
+ bits['yy'] = bits['yyyy'].toString().substr(2,2);
+
+ // do some funky regexs to replace the format string
+ // with the real values
+ var frm = new String(format);
+ for (var sect in bits)
+ {
+ var reg = new RegExp("\\b"+sect+"\\b" ,"g");
+ frm = frm.replace(reg, bits[sect]);
+ }
+ return frm;
+ },
+
+ toISODate : function()
+ {
+ var y = this.getFullYear();
+ var m = Prado.Util.pad(this.getMonth() + 1);
+ var d = Prado.Util.pad(this.getDate());
+ return String(y) + String(m) + String(d);
+ }
+});
+
+Object.extend(Date,
+{
+ SimpleParse: function(value, format)
+ {
+ val=String(value);
+ format=String(format);
+
+ if(val.length <= 0) return null;
+
+ if(format.length <= 0) return new Date(value);
+
+ var isInteger = function (val)
+ {
+ var digits="1234567890";
+ for (var i=0; i < val.length; i++)
+ {
+ if (digits.indexOf(val.charAt(i))==-1) { return false; }
+ }
+ return true;
+ };
+
+ var getInt = function(str,i,minlength,maxlength)
+ {
+ for (var x=maxlength; x>=minlength; x--)
+ {
+ var token=str.substring(i,i+x);
+ if (token.length < minlength) { return null; }
+ if (isInteger(token)) { return token; }
+ }
+ return null;
+ };
+
+ var i_val=0;
+ var i_format=0;
+ var c="";
+ var token="";
+ var token2="";
+ var x,y;
+ var now=new Date();
+ var year=now.getFullYear();
+ var month=now.getMonth()+1;
+ var date=1;
+
+ while (i_format < format.length)
+ {
+ // Get next token from format string
+ c=format.charAt(i_format);
+ token="";
+ while ((format.charAt(i_format)==c) && (i_format < format.length))
+ {
+ token += format.charAt(i_format++);
+ }
+
+ // Extract contents of value based on format token
+ if (token=="yyyy" || token=="yy" || token=="y")
+ {
+ if (token=="yyyy") { x=4;y=4; }
+ if (token=="yy") { x=2;y=2; }
+ if (token=="y") { x=2;y=4; }
+ year=getInt(val,i_val,x,y);
+ if (year==null) { return null; }
+ i_val += year.length;
+ if (year.length==2)
+ {
+ if (year > 70) { year=1900+(year-0); }
+ else { year=2000+(year-0); }
+ }
+ }
+
+ else if (token=="MM"||token=="M")
+ {
+ month=getInt(val,i_val,token.length,2);
+ if(month==null||(month<1)||(month>12)){return null;}
+ i_val+=month.length;
+ }
+ else if (token=="dd"||token=="d")
+ {
+ date=getInt(val,i_val,token.length,2);
+ if(date==null||(date<1)||(date>31)){return null;}
+ i_val+=date.length;
+ }
+ else
+ {
+ if (val.substring(i_val,i_val+token.length)!=token) {return null;}
+ else {i_val+=token.length;}
+ }
+ }
+
+ // If there are any trailing characters left in the value, it doesn't match
+ if (i_val != val.length) { return null; }
+
+ // Is date valid for month?
+ if (month==2)
+ {
+ // Check for leap year
+ if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
+ if (date > 29){ return null; }
+ }
+ else { if (date > 28) { return null; } }
+ }
+
+ if ((month==4)||(month==6)||(month==9)||(month==11))
+ {
+ if (date > 30) { return null; }
+ }
+
+ var newdate=new Date(year,month-1,date, 0, 0, 0);
+ return newdate;
+ }
+}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/datepicker.js b/framework/Web/Javascripts/base/datepicker.js
index 046a0a4b..68e63168 100644
--- a/framework/Web/Javascripts/base/datepicker.js
+++ b/framework/Web/Javascripts/base/datepicker.js
@@ -3,272 +3,7 @@ Prado.Calendar = Class.create();
Prado.Calendar.Util = Class.create();
Object.extend(Prado.Calendar.Util,
-{
- // utility function to pad a number to a given width
- pad : function(number, X)
- {
- X = (!X ? 2 : X);
- number = ""+number;
- while (number.length < X)
- number = "0" + number;
- return number;
- },
-
- //allow for deprecated formats
- FormatDate : function(date, format)
- {
- if(!isObject(date)) return "";
- if(format.indexOf("%") > -1)
- {
- alert('Please use the new SimpleDateFormat pattern, e.g. yyyy-MM-dd');
- return this.FormatDateDepr(date,format);
- }
- else
- {
- return this.SimpleFormatDate(date, format);
- }
- },
-
- //allow for deprecated format
- ParseDate : function(value, format)
- {
- val=String(value);
- format=String(format);
-
- if(val.length <= 0) return null;
-
- if(format.length <= 0) return new Date(value);
-
- if(format.indexOf("%") > -1)
- return this.ParseDateDepr(value, format);
- else
- return this.SimpleParseDate(value, format);
- },
-
- //deprecated format
- FormatDateDepr : function(date, str)
- {
- var m = date.getMonth();
- var d = date.getDate();
- var y = date.getFullYear();
-
- var s = {};
-
- s["%d"] = this.pad(d); // the day of the month (range 01 to 31)
- s["%e"] = d; // the day of the month (range 1 to 31)
- s["%m"] = this.pad(m+1);
- s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
- s["%Y"] = y; // year with the century
-
- var re = /%./g;
-
- var a = str.match(re);
- for (var i = 0; i < a.length; i++)
- {
- var tmp = s[a[i]];
- if (tmp)
- {
- re = new RegExp(a[i], 'g');
- str = str.replace(re, tmp);
- }
- }
-
- return str;
- },
-
- //deprecated format parser
- ParseDateDepr : function(value, format)
- {
- var y = 0;
- var m = -1;
- var d = 0;
- var a = value.split(/\W+/);
- var b = format.match(/%./g);
- var i = 0, j = 0;
- var hr = 0;
- var min = 0;
- for (i = 0; i < a.length; ++i) {
- if (!a[i])
- continue;
- switch (b[i]) {
- case "%d":
- case "%e":
- d = parseInt(a[i], 10);
- break;
-
- case "%m":
- m = parseInt(a[i], 10) - 1;
- break;
-
- case "%Y":
- case "%y":
- y = parseInt(a[i], 10);
- (y < 100) && (y += (y > 29) ? 1900 : 2000);
- break;
-
- case "%H":
- case "%I":
- case "%k":
- case "%l":
- hr = parseInt(a[i], 10);
- break;
-
- case "%P":
- case "%p":
- if (/pm/i.test(a[i]) && hr < 12)
- hr += 12;
- break;
-
- case "%M":
- min = parseInt(a[i], 10);
- break;
- }
- }
- if (y != 0 && m != -1 && d != 0)
- {
- var date = new Date(y, m, d, hr, min, 0);
- return (isObject(date)
- && y == date.getFullYear()
- && m == date.getMonth()
- && d == date.getDate()) ? date : null;
- }
- return null;
- },
-
- SimpleFormatDate : function(date, format)
- {
- if(!isObject(date)) return "";
- var bits = new Array();
- bits['d'] = date.getDate();
- bits['dd'] = this.pad(date.getDate(),2);
-
- bits['M'] = date.getMonth()+1;
- bits['MM'] = this.pad(date.getMonth()+1,2);
-
- var yearStr = "" + date.getFullYear();
- yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr;
- bits['yyyy'] = yearStr;
- bits['yy'] = bits['yyyy'].toString().substr(2,2);
-
- // do some funky regexs to replace the format string
- // with the real values
- var frm = new String(format);
- for (var sect in bits)
- {
- var reg = new RegExp("\\b"+sect+"\\b" ,"g");
- frm = frm.replace(reg, bits[sect]);
- }
- return frm;
- },
-
- SimpleParseDate : function(value, format)
- {
- val=String(value);
- format=String(format);
-
- if(val.length <= 0) return null;
-
- if(format.length <= 0) return new Date(value);
-
- var isInteger = function (val)
- {
- var digits="1234567890";
- for (var i=0; i < val.length; i++)
- {
- if (digits.indexOf(val.charAt(i))==-1) { return false; }
- }
- return true;
- };
-
- var getInt = function(str,i,minlength,maxlength)
- {
- for (var x=maxlength; x>=minlength; x--)
- {
- var token=str.substring(i,i+x);
- if (token.length < minlength) { return null; }
- if (isInteger(token)) { return token; }
- }
- return null;
- };
-
- var i_val=0;
- var i_format=0;
- var c="";
- var token="";
- var token2="";
- var x,y;
- var now=new Date();
- var year=now.getFullYear();
- var month=now.getMonth()+1;
- var date=1;
-
- while (i_format < format.length)
- {
- // Get next token from format string
- c=format.charAt(i_format);
- token="";
- while ((format.charAt(i_format)==c) && (i_format < format.length))
- {
- token += format.charAt(i_format++);
- }
-
- // Extract contents of value based on format token
- if (token=="yyyy" || token=="yy" || token=="y")
- {
- if (token=="yyyy") { x=4;y=4; }
- if (token=="yy") { x=2;y=2; }
- if (token=="y") { x=2;y=4; }
- year=getInt(val,i_val,x,y);
- if (year==null) { return null; }
- i_val += year.length;
- if (year.length==2)
- {
- if (year > 70) { year=1900+(year-0); }
- else { year=2000+(year-0); }
- }
- }
-
- else if (token=="MM"||token=="M")
- {
- month=getInt(val,i_val,token.length,2);
- if(month==null||(month<1)||(month>12)){return null;}
- i_val+=month.length;
- }
- else if (token=="dd"||token=="d")
- {
- date=getInt(val,i_val,token.length,2);
- if(date==null||(date<1)||(date>31)){return null;}
- i_val+=date.length;
- }
- else
- {
- if (val.substring(i_val,i_val+token.length)!=token) {return null;}
- else {i_val+=token.length;}
- }
- }
-
- // If there are any trailing characters left in the value, it doesn't match
- if (i_val != val.length) { return null; }
-
- // Is date valid for month?
- if (month==2)
- {
- // Check for leap year
- if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
- if (date > 29){ return null; }
- }
- else { if (date > 28) { return null; } }
- }
-
- if ((month==4)||(month==6)||(month==9)||(month==11))
- {
- if (date > 30) { return null; }
- }
-
- var newdate=new Date(year,month-1,date, 0, 0, 0);
- return newdate;
- },
-
+{
IsLeapYear : function (year)
{
return ((year%4 == 0) && ((year%100 != 0) || (year%400 == 0)));
@@ -288,13 +23,6 @@ Object.extend(Prado.Calendar.Util,
Calendar.LEAP_NUM_DAYS : Calendar.NUM_DAYS;
return a[date.getMonth()] + date.getDate();
},
- ISODate : function(date)
- {
- var y = date.getFullYear();
- var m = this.pad(date.getMonth() + 1);
- var d = this.pad(date.getDate());
- return String(y) + String(m) + String(d);
- },
browser : function()
{
diff --git a/framework/Web/Javascripts/base/prado.js b/framework/Web/Javascripts/base/prado.js
index 7dd14e19..95600f09 100644
--- a/framework/Web/Javascripts/base/prado.js
+++ b/framework/Web/Javascripts/base/prado.js
@@ -1 +1,2 @@
-var Prado = { Version: 2.0 }; \ No newline at end of file
+var Prado = { Version: 2.0 };
+
diff --git a/framework/Web/Javascripts/base/rico.js b/framework/Web/Javascripts/base/rico.js
new file mode 100644
index 00000000..d3df3a9b
--- /dev/null
+++ b/framework/Web/Javascripts/base/rico.js
@@ -0,0 +1,175 @@
+Prado.RicoLiveGrid = Class.create();
+Prado.RicoLiveGrid.prototype = Object.extend(Rico.LiveGrid.prototype,
+{
+ initialize : function(tableId, options)
+ {
+ this.options = {
+ tableClass: $(tableId).className || '',
+ loadingClass: $(tableId).className || '',
+ scrollerBorderRight: '1px solid #ababab',
+ bufferTimeout: 20000,
+ sortAscendImg: 'images/sort_asc.gif',
+ sortDescendImg: 'images/sort_desc.gif',
+ sortImageWidth: 9,
+ sortImageHeight: 5,
+ ajaxSortURLParms: [],
+ onRefreshComplete: null,
+ requestParameters: null,
+ inlineStyles: true,
+ visibleRows: 10,
+ totalRows: 0,
+ initialOffset: 0
+ };
+ Object.extend(this.options, options || {});
+
+ //this.ajaxOptions = {parameters: null};
+ //Object.extend(this.ajaxOptions, ajaxOptions || {});
+
+ this.tableId = tableId;
+ this.table = $(tableId);
+
+ this.addLiveGridHtml();
+
+ var columnCount = this.table.rows[0].cells.length;
+ this.metaData = new Rico.LiveGridMetaData(this.options.visibleRows, this.options.totalRows, columnCount, options);
+ this.buffer = new Rico.LiveGridBuffer(this.metaData);
+
+ var rowCount = this.table.rows.length;
+ this.viewPort = new Rico.GridViewPort(this.table,
+ this.table.offsetHeight/rowCount,
+ this.options.visibleRows,
+ this.buffer, this);
+ this.scroller = new Rico.LiveGridScroller(this,this.viewPort);
+ this.options.sortHandler = this.sortHandler.bind(this);
+
+ if ( $(tableId + '_header') )
+ this.sort = new Rico.LiveGridSort(tableId + '_header', this.options)
+
+ this.processingRequest = null;
+ this.unprocessedRequest = null;
+
+ //this.initAjax(url);
+ if (this.options.initialOffset >= 0)
+ {
+ var offset = this.options.initialOffset;
+ this.scroller.moveScroll(offset);
+ this.viewPort.scrollTo(this.scroller.rowToPixel(offset));
+ if (this.options.sortCol) {
+ this.sortCol = options.sortCol;
+ this.sortDir = options.sortDir;
+ }
+ var grid = this;
+ setTimeout(function(){
+ grid.requestContentRefresh(offset);
+ },100);
+ }
+ },
+
+ fetchBuffer: function(offset)
+ {
+ if ( this.buffer.isInRange(offset) &&
+ !this.buffer.isNearingLimit(offset)) {
+ return;
+ }
+ if (this.processingRequest) {
+ this.unprocessedRequest = new Rico.LiveGridRequest(offset);
+ return;
+ }
+ var bufferStartPos = this.buffer.getFetchOffset(offset);
+ this.processingRequest = new Rico.LiveGridRequest(offset);
+ this.processingRequest.bufferOffset = bufferStartPos;
+ var fetchSize = this.buffer.getFetchSize(offset);
+ var partialLoaded = false;
+
+ // var queryString
+ // if (this.options.requestParameters)
+ // queryString = this._createQueryString(this.options.requestParameters, 0);
+ var param =
+ {
+ 'page_size' : fetchSize,
+ 'offset' : bufferStartPos
+ };
+ if(this.sortCol)
+ {
+ Object.extend(param,
+ {
+ 'sort_col': this.sortCol,
+ 'sort_dir': this.sortDir
+ });
+ }
+ /*queryString = (queryString == null) ? '' : queryString+'&';
+ queryString = queryString+'id='+this.tableId+'&page_size='+fetchSize+'&offset='+bufferStartPos;
+ if (this.sortCol)
+ queryString = queryString+'&sort_col='+escape(this.sortCol)+'&sort_dir='+this.sortDir;
+
+ this.ajaxOptions.parameters = queryString;
+
+ ajaxEngine.sendRequest( this.tableId + '_request', this.ajaxOptions );
+ */
+ Prado.Callback(this.tableId, param, this.ajaxUpdate.bind(this), this.options);
+ this.timeoutHandler = setTimeout( this.handleTimedOut.bind(this), this.options.bufferTimeout);
+
+ },
+
+ ajaxUpdate: function(result, output)
+ {
+ try {
+ clearTimeout( this.timeoutHandler );
+ this.buffer.update(result,this.processingRequest.bufferOffset);
+ this.viewPort.bufferChanged();
+ }
+ catch(err) {}
+ finally {this.processingRequest = null; }
+ this.processQueuedRequest();
+ }
+});
+
+Object.extend(Rico.LiveGridBuffer.prototype,
+{
+ update: function(newRows, start)
+ {
+ if (this.rows.length == 0) { // initial load
+ this.rows = newRows;
+ this.size = this.rows.length;
+ this.startPos = start;
+ return;
+ }
+ if (start > this.startPos) { //appending
+ if (this.startPos + this.rows.length < start) {
+ this.rows = newRows;
+ this.startPos = start;//
+ } else {
+ this.rows = this.rows.concat( newRows.slice(0, newRows.length));
+ if (this.rows.length > this.maxBufferSize) {
+ var fullSize = this.rows.length;
+ this.rows = this.rows.slice(this.rows.length - this.maxBufferSize, this.rows.length)
+ this.startPos = this.startPos + (fullSize - this.rows.length);
+ }
+ }
+ } else { //prepending
+ if (start + newRows.length < this.startPos) {
+ this.rows = newRows;
+ } else {
+ this.rows = newRows.slice(0, this.startPos).concat(this.rows);
+ if (this.rows.length > this.maxBufferSize)
+ this.rows = this.rows.slice(0, this.maxBufferSize)
+ }
+ this.startPos = start;
+ }
+ this.size = this.rows.length;
+ }
+});
+
+
+Object.extend(Rico.GridViewPort.prototype,
+{
+ populateRow: function(htmlRow, row)
+ {
+ if(isdef(htmlRow))
+ {
+ for (var j=0; j < row.length; j++) {
+ htmlRow.cells[j].innerHTML = row[j]
+ }
+ }
+ }
+}); \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/util.js b/framework/Web/Javascripts/base/util.js
new file mode 100644
index 00000000..61b7d646
--- /dev/null
+++ b/framework/Web/Javascripts/base/util.js
@@ -0,0 +1,92 @@
+Prado.Util = {}
+
+/**
+ * Pad a number with zeros from the left.
+ * @param integer number
+ * @param integer total string length
+ * @return string zero padded number
+ */
+Prado.Util.pad = function(number, X)
+{
+ X = (!X ? 2 : X);
+ number = ""+number;
+ while (number.length < X)
+ number = "0" + number;
+ return number;
+}
+
+/**
+ * Convert a string into integer, returns null if not integer.
+ * @param {string} the string to convert to integer
+ * @type {integer|null} null if string does not represent an integer.
+ */
+Prado.Util.toInteger = function(value)
+{
+ var exp = /^\s*[-\+]?\d+\s*$/;
+ if (value.match(exp) == null)
+ return null;
+ var num = parseInt(value, 10);
+ return (isNaN(num) ? null : num);
+}
+
+/**
+ * Convert a string into a double/float value. <b>Internationalization
+ * is not supported</b>
+ * @param {string} the string to convert to double/float
+ * @param {string} the decimal character
+ * @return {float|null} null if string does not represent a float value
+ */
+Prado.Util.toDouble = function(value, decimalchar)
+{
+ decimalchar = undef(decimalchar) ? "." : decimalchar;
+ var exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
+ var m = value.match(exp);
+ if (m == null)
+ return null;
+ var cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
+ var num = parseFloat(cleanInput);
+ return (isNaN(num) ? null : num);
+}
+
+/**
+ * Convert strings that represent a currency value (e.g. a float with grouping
+ * characters) to float. E.g. "10,000.50" will become "10000.50". The number
+ * of dicimal digits, grouping and decimal characters can be specified.
+ * <i>The currency input format is <b>very</b> strict, null will be returned if
+ * the pattern does not match</i>.
+ * @param {string} the currency value
+ * @param {string} the grouping character, default is ","
+ * @param {int} number of decimal digits
+ * @param {string} the decimal character, default is "."
+ * @type {float|null} the currency value as float.
+ */
+Prado.Util.toCurrency = function(value, groupchar, digits, decimalchar)
+{
+ groupchar = undef(groupchar) ? "," : groupchar;
+ decimalchar = undef(decimalchar) ? "." : decimalchar;
+ digits = undef(digits) ? 2 : digits;
+
+ var exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + groupchar + ")*)(\\d+)"
+ + ((digits > 0) ? "(\\" + decimalchar + "(\\d{1," + digits + "}))?" : "")
+ + "\\s*$");
+ var m = value.match(exp);
+ if (m == null)
+ return null;
+ var intermed = m[2] + m[5] ;
+ var cleanInput = m[1] + intermed.replace(
+ new RegExp("(\\" + groupchar + ")", "g"), "")
+ + ((digits > 0) ? "." + m[7] : "");
+ var num = parseFloat(cleanInput);
+ return (isNaN(num) ? null : num);
+}
+
+/**
+ * Trim the value, if the value is undefined, empty string is return.
+ * @param {string} string to be trimmed.
+ * @type {string} trimmed string.
+ */
+Prado.Util.trim = function(value)
+{
+ if(!isString(value)) return "";
+ return value.replace(/^\s+|\s+$/g, "");
+} \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/validation.js b/framework/Web/Javascripts/base/validation.js
index e7fa9203..78694ca4 100644
--- a/framework/Web/Javascripts/base/validation.js
+++ b/framework/Web/Javascripts/base/validation.js
@@ -152,7 +152,7 @@ Prado.Validation.Util.toDate = function(value, format)
*/
Prado.Validation.Util.trim = function(value)
{
- if(!isString(value)) return "";
+ if(undef(value)) return "";
return value.replace(/^\s+|\s+$/g, "");
}
@@ -367,8 +367,6 @@ Prado.Validation.prototype =
*/
update : function()
{
- Logger.info("isvalid ? " + this.isValid);
-
if(this.attr.display == "Dynamic")
this.isValid ? Element.hide(this.message) : Element.show(this.message);
@@ -380,6 +378,9 @@ Prado.Validation.prototype =
if(this.control && isString(className) && className.length>0)
Element.condClassName(this.control, className, !this.isValid);
Prado.Validation.ShowSummary();
+
+ if(this.attr.focusonerror)
+ Prado.Element.focus(this.attr.focuselementid);
},
/**
@@ -671,6 +672,79 @@ Prado.Validation.OnLoad = function()
Event.observe(Prado.Validation.forms,"submit", Prado.Validation.OnSubmit);
}
+
+/**
+ * Validate Validator Groups.
+ * @param string ValidatorGroup
+ * @return boolean true if valid, false otherwise
+ */
+Prado.Validation.ValidateValidatorGroup = function(groupId)
+{
+ var groups = Prado.Validation.groups;
+ var group = null;
+ for(var i = 0; i < groups.length; i++)
+ {
+ if(groups[i].id == groupId)
+ {
+ group = groups[i];
+ Prado.Validation.groups[i].active = true;
+ Prado.Validation.CurrentTargetGroup = null;
+ Prado.Validation.IsGroupValidation = true;
+ }
+ else
+ {
+ Prado.Validation.groups[i].active = false;
+ }
+ }
+ if(group)
+ {
+ return Prado.Validation.IsValid(group.target.form);
+ }
+ return true;
+};
+
+/**
+ * Validate ValidationGroup
+ * @param string ValidationGroup
+ * @return boolean true if valid, false otherwise.
+ */
+Prado.Validation.ValidateValidationGroup= function(groupId)
+{
+ var groups = Prado.Validation.TargetGroups;
+ for(var id in groups)
+ {
+ if(groups[id] == groupId)
+ {
+ var target = $(id);
+ Prado.Validation.ActiveTarget = target;
+ Prado.Validation.CurrentTargetGroup = groupId;
+ Prado.Validation.IsGroupValidation = false;
+ return Prado.Validation.IsValid(target.form);
+ }
+ }
+ return true;
+};
+
+/**
+ * Validate the page
+ * @return boolean true if valid, false otherwise.
+ */
+Prado.Validation.ValidateNonGroup= function(formId)
+{
+ if(Prado.Validation)
+ {
+ var form = $(formId);
+ form = form || document.forms[0];
+ Prado.Validation.ActiveTarget = form;
+ Prado.Validation.CurrentTargetGroup = null;
+ Prado.Validation.IsGroupValidation = false;
+ return Prado.Validation.IsValid(form);
+ }
+ return true;
+};
+
+
+
/**
* Register Prado.Validation.Onload() for window.onload event.
*/
diff --git a/framework/Web/Javascripts/base/validators.js b/framework/Web/Javascripts/base/validators.js
index 2f49eb12..427b46fc 100644
--- a/framework/Web/Javascripts/base/validators.js
+++ b/framework/Web/Javascripts/base/validators.js
@@ -5,8 +5,8 @@ Prado.Validation.TRequiredFieldValidator=function(){
return true;
}
else{
- var trim=Prado.Validation.Util.trim;
- var a=trim($F(this.control));
+ var trim=Prado.Util.trim;
+ var a=trim(Form.Element.getValue(this.control));
var b=trim(this.attr.initialvalue);
return(a!=b);
}
@@ -15,8 +15,8 @@ Prado.Validation.TRequiredFieldValidator=function(){
Prado.Validation.TRegularExpressionValidator = function()
{
- var trim = Prado.Validation.Util.trim;
- var value = trim($F(this.control));
+ var trim = Prado.Util.trim;
+ var value = trim(Form.Element.getValue(this.control));
if (value == "") return true;
var rx = new RegExp(this.attr.validationexpression);
var matches = rx.exec(value);
@@ -35,8 +35,8 @@ Prado.Validation.TCustomValidator = function()
Prado.Validation.TRangeValidator = function()
{
- var trim = Prado.Validation.Util.trim;
- var value = trim($F(this.control));
+ var trim = Prado.Util.trim;
+ var value = trim(Form.Element.getValue(this.control));
if (value == "") return true;
var minval = this.attr.minimumvalue;
@@ -62,8 +62,8 @@ Prado.Validation.TRangeValidator = function()
Prado.Validation.TCompareValidator = function()
{
- var trim = Prado.Validation.Util.trim;
- var value = trim($F(this.control));
+ var trim = Prado.Util.trim;
+ var value = trim(Form.Element.getValue(this.control));
if (value.length == 0) return true;
var compareTo;
@@ -71,7 +71,7 @@ Prado.Validation.TCompareValidator = function()
var comparee = $(this.attr.controlhookup);;
if(comparee)
- compareTo = trim($F(comparee));
+ compareTo = trim(Form.Element.getValue(comparee));
else
{
compareTo = isString(this.attr.valuetocompare) ? this.attr.valuetocompare : "";