diff options
author | wei <> | 2006-01-09 04:39:05 +0000 |
---|---|---|
committer | wei <> | 2006-01-09 04:39:05 +0000 |
commit | 9f2ecd591d5be41bb9dc7b8a0fa144ac35a173bb (patch) | |
tree | 122d77d166d5df687d524173b883d87fd6674c0d /framework | |
parent | 9c9a2d731fea9679f65904a3a6b72dd78b4253a4 (diff) |
TRequiredFieldValidator works now. See FunctionalTests/index.php in your browser.
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Web/Javascripts/base/postback.js | 7 | ||||
-rw-r--r-- | framework/Web/Javascripts/base/validation.js | 4 | ||||
-rw-r--r-- | framework/Web/Javascripts/base/validators.js | 10 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/base.js | 192 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/dom.js | 520 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/logger.js | 184 | ||||
-rw-r--r-- | framework/Web/Javascripts/js/validator.js | 177 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TBaseValidator.php | 25 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TButton.php | 12 |
9 files changed, 656 insertions, 475 deletions
diff --git a/framework/Web/Javascripts/base/postback.js b/framework/Web/Javascripts/base/postback.js index b7e095a4..186495cc 100644 --- a/framework/Web/Javascripts/base/postback.js +++ b/framework/Web/Javascripts/base/postback.js @@ -13,7 +13,12 @@ Prado.doPostBack = function(formID, eventTarget, eventParameter, performValidati if (performValidation)
{
//canSubmit = Prado.Validation.validate(validationGroup);
- canSubmit = Prado.Validation.OnSubmit(theForm);
+ /* Prado.Validation.ActiveTarget = theForm;
+ Prado.Validation.CurrentTargetGroup = null;
+ Prado.Validation.IsGroupValidation = false;
+ canSubmit = Prado.Validation.IsValid(theForm);
+ Logger.debug(canSubmit);*/
+ canSubmit = Prado.Validation.IsValid(theForm);
}
if (canSubmit)
{
diff --git a/framework/Web/Javascripts/base/validation.js b/framework/Web/Javascripts/base/validation.js index ceebc2ba..e7fa9203 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(undef(value)) return "";
+ if(!isString(value)) return "";
return value.replace(/^\s+|\s+$/g, "");
}
@@ -367,6 +367,8 @@ 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);
diff --git a/framework/Web/Javascripts/base/validators.js b/framework/Web/Javascripts/base/validators.js index 99d6b416..2f49eb12 100644 --- a/framework/Web/Javascripts/base/validators.js +++ b/framework/Web/Javascripts/base/validators.js @@ -6,7 +6,7 @@ Prado.Validation.TRequiredFieldValidator=function(){ }
else{
var trim=Prado.Validation.Util.trim;
- var a=trim(Form.Element.getValue(this.control));
+ var a=trim($F(this.control));
var b=trim(this.attr.initialvalue);
return(a!=b);
}
@@ -16,7 +16,7 @@ Prado.Validation.TRequiredFieldValidator=function(){ Prado.Validation.TRegularExpressionValidator = function()
{
var trim = Prado.Validation.Util.trim;
- var value = trim(Form.Element.getValue(this.control));
+ var value = trim($F(this.control));
if (value == "") return true;
var rx = new RegExp(this.attr.validationexpression);
var matches = rx.exec(value);
@@ -36,7 +36,7 @@ Prado.Validation.TCustomValidator = function() Prado.Validation.TRangeValidator = function()
{
var trim = Prado.Validation.Util.trim;
- var value = trim(Form.Element.getValue(this.control));
+ var value = trim($F(this.control));
if (value == "") return true;
var minval = this.attr.minimumvalue;
@@ -63,7 +63,7 @@ Prado.Validation.TRangeValidator = function() Prado.Validation.TCompareValidator = function()
{
var trim = Prado.Validation.Util.trim;
- var value = trim(Form.Element.getValue(this.control));
+ var value = trim($F(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(Form.Element.getValue(comparee));
+ compareTo = trim($F(comparee));
else
{
compareTo = isString(this.attr.valuetocompare) ? this.attr.valuetocompare : "";
diff --git a/framework/Web/Javascripts/js/base.js b/framework/Web/Javascripts/js/base.js index 86c7ef83..8b687300 100644 --- a/framework/Web/Javascripts/js/base.js +++ b/framework/Web/Javascripts/js/base.js @@ -1,4 +1,4 @@ -var Prototype={Version:"1.4.0_rc1",emptyFunction:function(){ +var Prototype={Version:"1.4.0",ScriptFragment:"(?:<script.*?>)((\n|\r|.)*?)(?:</script>)",emptyFunction:function(){ },K:function(x){ return x; }}; @@ -60,47 +60,47 @@ return "..."; throw e; } }; -Function.prototype.bind=function(_4){ -var _5=this; +Function.prototype.bind=function(){ +var _4=this,args=$A(arguments),object=args.shift(); return function(){ -return _5.apply(_4,arguments); +return _4.apply(object,args.concat($A(arguments))); }; }; -Function.prototype.bindAsEventListener=function(_6){ -var _7=this; -return function(_8){ -return _7.call(_6,_8||window.event); +Function.prototype.bindAsEventListener=function(_5){ +var _6=this; +return function(_7){ +return _6.call(_5,_7||window.event); }; }; Object.extend(Number.prototype,{toColorPart:function(){ -var _9=this.toString(16); +var _8=this.toString(16); if(this<16){ -return "0"+_9; +return "0"+_8; } -return _9; +return _8; },succ:function(){ return this+1; -},times:function(_10){ -$R(0,this,true).each(_10); +},times:function(_9){ +$R(0,this,true).each(_9); return this; }}); var Try={these:function(){ -var _11; +var _10; for(var i=0;i<arguments.length;i++){ -var _13=arguments[i]; +var _12=arguments[i]; try{ -_11=_13(); +_10=_12(); break; } catch(e){ } } -return _11; +return _10; }}; var PeriodicalExecuter=Class.create(); -PeriodicalExecuter.prototype={initialize:function(_14,_15){ -this.callback=_14; -this.frequency=_15; +PeriodicalExecuter.prototype={initialize:function(_13,_14){ +this.callback=_13; +this.frequency=_14; this.currentlyExecuting=false; this.registerCallback(); },registerCallback:function(){ @@ -117,18 +117,18 @@ this.currentlyExecuting=false; } }}; function $(){ -var _16=new Array(); +var _15=new Array(); for(var i=0;i<arguments.length;i++){ -var _17=arguments[i]; -if(typeof _17=="string"){ -_17=document.getElementById(_17); +var _16=arguments[i]; +if(typeof _16=="string"){ +_16=document.getElementById(_16); } if(arguments.length==1){ -return _17; +return _16; } -_16.push(_17); +_15.push(_16); } -return _16; +return _15; } function isElement(o,_2){ @@ -221,35 +221,45 @@ return o&&isObject(o)&&(isArray(o)||o.item); Object.extend(String.prototype,{stripTags:function(){ return this.replace(/<\/?[^>]+>/gi,""); +},stripScripts:function(){ +return this.replace(new RegExp(Prototype.ScriptFragment,"img"),""); +},extractScripts:function(){ +var _1=new RegExp(Prototype.ScriptFragment,"img"); +var _2=new RegExp(Prototype.ScriptFragment,"im"); +return (this.match(_1)||[]).map(function(_3){ +return (_3.match(_2)||["",""])[1]; +}); +},evalScripts:function(){ +return this.extractScripts().map(eval); },escapeHTML:function(){ -var _1=document.createElement("div"); -var _2=document.createTextNode(this); -_1.appendChild(_2); -return _1.innerHTML; +var _4=document.createElement("div"); +var _5=document.createTextNode(this); +_4.appendChild(_5); +return _4.innerHTML; },unescapeHTML:function(){ -var _3=document.createElement("div"); -_3.innerHTML=this.stripTags(); -return _3.childNodes[0]?_3.childNodes[0].nodeValue:""; +var _6=document.createElement("div"); +_6.innerHTML=this.stripTags(); +return _6.childNodes[0]?_6.childNodes[0].nodeValue:""; },toQueryParams:function(){ -var _4=this.match(/^\??(.*)$/)[1].split("&"); -return _4.inject({},function(_5,_6){ -var _7=_6.split("="); -_5[_7[0]]=_7[1]; -return _5; +var _7=this.match(/^\??(.*)$/)[1].split("&"); +return _7.inject({},function(_8,_9){ +var _10=_9.split("="); +_8[_10[0]]=_10[1]; +return _8; }); },toArray:function(){ return this.split(""); },camelize:function(){ -var _8=this.split("-"); -if(_8.length==1){ -return _8[0]; +var _11=this.split("-"); +if(_11.length==1){ +return _11[0]; } -var _9=this.indexOf("-")==0?_8[0].charAt(0).toUpperCase()+_8[0].substring(1):_8[0]; -for(var i=1,len=_8.length;i<len;i++){ -var s=_8[i]; -_9+=s.charAt(0).toUpperCase()+s.substring(1); +var _12=this.indexOf("-")==0?_11[0].charAt(0).toUpperCase()+_11[0].substring(1):_11[0]; +for(var i=1,len=_11.length;i<len;i++){ +var s=_11[i]; +_12+=s.charAt(0).toUpperCase()+s.substring(1); } -return _9; +return _12; },inspect:function(){ return "'"+this.replace("\\","\\\\").replace("'","\\'")+"'"; }}); @@ -282,6 +292,22 @@ return this.replace(/^\s+|\s+$/g,""); return this.replace(/^\s+/,""); },trimRight:function(){ return this.replace(/\s+$/,""); +},toFunction:function(){ +var _12=this.split(/\./); +var _13=window; +_12.each(function(_14){ +if(_13[new String(_14)]){ +_13=_13[new String(_14)]; +} +}); +if(isFunction(_13)){ +return _13; +}else{ +if(typeof Logger!="undefined"){ +Logger.error("Missing function",this); +} +return Prototype.emptyFunction; +} }}); var $break=new Object(); @@ -308,7 +334,8 @@ throw e; },all:function(_4){ var _5=true; this.each(function(_6,_7){ -if(!(_5&=(_4||Prototype.K)(_6,_7))){ +_5=_5&&!!(_4||Prototype.K)(_6,_7); +if(!_5){ throw $break; } }); @@ -316,7 +343,7 @@ return _5; },any:function(_8){ var _9=true; this.each(function(_10,_11){ -if(_9&=(_8||Prototype.K)(_10,_11)){ +if(_9=!!(_8||Prototype.K)(_10,_11)){ throw $break; } }); @@ -435,6 +462,9 @@ return "#<Enumerable:"+this.toArray().inspect()+">"; Object.extend(Enumerable,{map:Enumerable.collect,find:Enumerable.detect,select:Enumerable.findAll,member:Enumerable.include,entries:Enumerable.toArray}); var $A=Array.from=function(_1){ +if(!_1){ +return []; +} if(_1.toArray){ return _1.toArray(); }else{ @@ -446,10 +476,14 @@ return _2; } }; Object.extend(Array.prototype,Enumerable); +Array.prototype._reverse=Array.prototype.reverse; Object.extend(Array.prototype,{_each:function(_4){ for(var i=0;i<this.length;i++){ _4(this[i]); } +},clear:function(){ +this.length=0; +return this; },first:function(){ return this[0]; },last:function(){ @@ -473,13 +507,16 @@ if(this[i]==_10){ return i; } } -return false; -},reverse:function(){ -var _11=[]; -for(var i=this.length;i>0;i--){ -_11.push(this[i-1]); -} -return _11; +return -1; +},reverse:function(_11){ +return (_11!==false?this:this.toArray())._reverse(); +},shift:function(){ +var _12=this[0]; +for(var i=0;i<this.length-1;i++){ +this[i]=this[i+1]; +} +this.length--; +return _12; },inspect:function(){ return "["+this.map(Object.inspect).join(", ")+"]"; }}); @@ -782,9 +819,9 @@ Object.extend(_10,Hash); return _10; } -var Range=Class.create(); -Object.extend(Range.prototype,Enumerable); -Object.extend(Range.prototype,{initialize:function(_1,_2,_3){ +ObjectRange=Class.create(); +Object.extend(ObjectRange.prototype,Enumerable); +Object.extend(ObjectRange.prototype,{initialize:function(_1,_2,_3){ this.start=_1; this.end=_2; this.exclusive=_3; @@ -804,7 +841,7 @@ return _6<this.end; return _6<=this.end; }}); var $R=function(_7,_8,_9){ -return new Range(_7,_8,_9); +return new ObjectRange(_7,_8,_9); }; function __strfn(_1,fn){ @@ -839,38 +876,7 @@ _7.push(fn(_6[i],i,_6)); return _7; } -Prado=Class.create(); -Prado.version="3.0a"; -Prado.Button=Class.create(); -Prado.Button.buttonFired=false; -Prado.Button.fireButton=function(_1,_2){ -if(!Prado.Button.buttonFired&&_1.keyCode==13&&!(_1.srcElement&&(_1.srcElement.tagName.toLowerCase()=="textarea"))){ -var _3=document.getElementById?document.getElementById(_2):document.all[_2]; -if(_3&&typeof (_3.click)!="undefined"){ -Prado.Button.buttonFired=true; -_3.click(); -_1.cancelBubble=true; -if(_1.stopPropagation){ -_1.stopPropagation(); -} -return false; -} -} -return true; -}; -Prado.TextBox=Class.create(); -Prado.TextBox.handleReturnKey=function(ev){ -var kc=ev.keyCode!=null?ev.keyCode:ev.charCode; -if(kc==Event.KEY_RETURN){ -var _6=Event.element(ev); -if(_6&&isFunction(_6.onchange)){ -_6.onchange(); -Event.stop(ev); -return false; -} -} -return true; -}; +var Prado={Version:2}; Prado.doPostBack=function(_1,_2,_3,_4,_5,_6,_7,_8){ if(typeof (_4)=="undefined"){ @@ -883,7 +889,7 @@ var _8=true; var _9=document.getElementById?document.getElementById(_1):document.forms[_1]; var _10=true; if(_4){ -_10=Prado.Validation.OnSubmit(); +_10=Prado.Validation.IsValid(_9); } if(_10){ if(_6!=null&&(_6.length>0)){ diff --git a/framework/Web/Javascripts/js/dom.js b/framework/Web/Javascripts/js/dom.js index f22d5c80..b93a6c63 100644 --- a/framework/Web/Javascripts/js/dom.js +++ b/framework/Web/Javascripts/js/dom.js @@ -1,7 +1,7 @@ document.getElementsByClassName=function(_1,_2){ var _3=($(_2)||document.body).getElementsByTagName("*"); return $A(_3).inject([],function(_4,_5){ -if(Element.hasClassName(_5,_1)){ +if(_5.className.match(new RegExp("(^|\\s)"+_1+"(\\s|$)"))){ _4.push(_5); } return _4; @@ -30,121 +30,128 @@ _10.style.display=""; },remove:function(_11){ _11=$(_11); _11.parentNode.removeChild(_11); -},getHeight:function(_12){ -_12=$(_12); -return _12.offsetHeight; -},classNames:function(_13){ -return new Element.ClassNames(_13); -},hasClassName:function(_14,_15){ -if(!(_14=$(_14))){ -return; -} -return Element.classNames(_14).include(_15); -},addClassName:function(_16,_17){ +},update:function(_12,_13){ +$(_12).innerHTML=_13.stripScripts(); +setTimeout(function(){ +_13.evalScripts(); +},10); +},getHeight:function(_14){ +_14=$(_14); +return _14.offsetHeight; +},classNames:function(_15){ +return new Element.ClassNames(_15); +},hasClassName:function(_16,_17){ if(!(_16=$(_16))){ return; } -return Element.classNames(_16).add(_17); -},removeClassName:function(_18,_19){ +return Element.classNames(_16).include(_17); +},addClassName:function(_18,_19){ if(!(_18=$(_18))){ return; } -return Element.classNames(_18).remove(_19); -},cleanWhitespace:function(_20){ -if(undef(_20)||isNull(_20)){ +return Element.classNames(_18).add(_19); +},removeClassName:function(_20,_21){ +if(!(_20=$(_20))){ return; } -_20=$(_20); -for(var i=0;i<_20.childNodes.length;i++){ -var _21=_20.childNodes[i]; -if(_21.nodeType==3&&!/\S/.test(_21.nodeValue)){ -_21.parentNode.removeChild(_21); +return Element.classNames(_20).remove(_21); +},cleanWhitespace:function(_22){ +_22=$(_22); +for(var i=0;i<_22.childNodes.length;i++){ +var _23=_22.childNodes[i]; +if(_23.nodeType==3&&!/\S/.test(_23.nodeValue)){ +Element.remove(_23); } } -},empty:function(_22){ -return $(_22).innerHTML.match(/^\s*$/); -},scrollTo:function(_23){ -_23=$(_23); -var x=_23.x?_23.x:_23.offsetLeft,y=_23.y?_23.y:_23.offsetTop; -window.scrollTo(x,y); -},getStyle:function(_25,_26){ +},empty:function(_24){ +return $(_24).innerHTML.match(/^\s*$/); +},scrollTo:function(_25){ _25=$(_25); -var _27=_25.style[_26.camelize()]; -if(!_27){ +var x=_25.x?_25.x:_25.offsetLeft,y=_25.y?_25.y:_25.offsetTop; +window.scrollTo(x,y); +},getStyle:function(_27,_28){ +_27=$(_27); +var _29=_27.style[_28.camelize()]; +if(!_29){ if(document.defaultView&&document.defaultView.getComputedStyle){ -var css=document.defaultView.getComputedStyle(_25,null); -_27=css?css.getPropertyValue(_26):null; +var css=document.defaultView.getComputedStyle(_27,null); +_29=css?css.getPropertyValue(_28):null; }else{ -if(_25.currentStyle){ -_27=_25.currentStyle[_26.camelize()]; +if(_27.currentStyle){ +_29=_27.currentStyle[_28.camelize()]; } } } -if(window.opera&&["left","top","right","bottom"].include(_26)){ -if(Element.getStyle(_25,"position")=="static"){ -_27="auto"; +if(window.opera&&["left","top","right","bottom"].include(_28)){ +if(Element.getStyle(_27,"position")=="static"){ +_29="auto"; } } -return _27=="auto"?null:_27; -},getDimensions:function(_29){ -_29=$(_29); -if(Element.getStyle(_29,"display")!="none"){ -return {width:_29.offsetWidth,height:_29.offsetHeight}; +return _29=="auto"?null:_29; +},setStyle:function(_31,_32){ +_31=$(_31); +for(name in _32){ +_31.style[name.camelize()]=_32[name]; +} +},getDimensions:function(_33){ +_33=$(_33); +if(Element.getStyle(_33,"display")!="none"){ +return {width:_33.offsetWidth,height:_33.offsetHeight}; } -var els=_29.style; -var _31=els.visibility; -var _32=els.position; +var els=_33.style; +var _35=els.visibility; +var _36=els.position; els.visibility="hidden"; els.position="absolute"; els.display=""; -var _33=_29.clientWidth; -var _34=_29.clientHeight; +var _37=_33.clientWidth; +var _38=_33.clientHeight; els.display="none"; -els.position=_32; -els.visibility=_31; -return {width:_33,height:_34}; -},makePositioned:function(_35){ -_35=$(_35); -var pos=Element.getStyle(_35,"position"); +els.position=_36; +els.visibility=_35; +return {width:_37,height:_38}; +},makePositioned:function(_39){ +_39=$(_39); +var pos=Element.getStyle(_39,"position"); if(pos=="static"||!pos){ -_35._madePositioned=true; -_35.style.position="relative"; +_39._madePositioned=true; +_39.style.position="relative"; if(window.opera){ -_35.style.top=0; -_35.style.left=0; +_39.style.top=0; +_39.style.left=0; } } -},undoPositioned:function(_37){ -_37=$(_37); -if(_37._madePositioned){ -_37._madePositioned=undefined; -_37.style.position=_37.style.top=_37.style.left=_37.style.bottom=_37.style.right=""; +},undoPositioned:function(_41){ +_41=$(_41); +if(_41._madePositioned){ +_41._madePositioned=undefined; +_41.style.position=_41.style.top=_41.style.left=_41.style.bottom=_41.style.right=""; } -},makeClipping:function(_38){ -_38=$(_38); -if(_38._overflow){ +},makeClipping:function(_42){ +_42=$(_42); +if(_42._overflow){ return; } -_38._overflow=_38.style.overflow; -if((Element.getStyle(_38,"overflow")||"visible")!="hidden"){ -_38.style.overflow="hidden"; +_42._overflow=_42.style.overflow; +if((Element.getStyle(_42,"overflow")||"visible")!="hidden"){ +_42.style.overflow="hidden"; } -},undoClipping:function(_39){ -_39=$(_39); -if(_39._overflow){ +},undoClipping:function(_43){ +_43=$(_43); +if(_43._overflow){ return; } -_39.style.overflow=_39._overflow; -_39._overflow=undefined; +_43.style.overflow=_43._overflow; +_43._overflow=undefined; }}); var Toggle=new Object(); Toggle.display=Element.toggle; -Abstract.Insertion=function(_40){ -this.adjacency=_40; +Abstract.Insertion=function(_44){ +this.adjacency=_44; }; -Abstract.Insertion.prototype={initialize:function(_41,_42){ -this.element=$(_41); -this.content=_42; +Abstract.Insertion.prototype={initialize:function(_45,_46){ +this.element=$(_45); +this.content=_46.stripScripts(); if(this.adjacency&&this.element.insertAdjacentHTML){ try{ this.element.insertAdjacentHTML(this.adjacency,this.content); @@ -163,6 +170,9 @@ this.initializeRange(); } this.insertContent([this.range.createContextualFragment(this.content)]); } +setTimeout(function(){ +_46.evalScripts(); +},10); },contentFromAnonymousTable:function(){ var div=document.createElement("div"); div.innerHTML="<table><tbody>"+this.content+"</tbody></table>"; @@ -172,58 +182,58 @@ var Insertion=new Object(); Insertion.Before=Class.create(); Insertion.Before.prototype=Object.extend(new Abstract.Insertion("beforeBegin"),{initializeRange:function(){ this.range.setStartBefore(this.element); -},insertContent:function(_44){ -_44.each((function(_45){ -this.element.parentNode.insertBefore(_45,this.element); +},insertContent:function(_48){ +_48.each((function(_49){ +this.element.parentNode.insertBefore(_49,this.element); }).bind(this)); }}); Insertion.Top=Class.create(); Insertion.Top.prototype=Object.extend(new Abstract.Insertion("afterBegin"),{initializeRange:function(){ this.range.selectNodeContents(this.element); this.range.collapse(true); -},insertContent:function(_46){ -_46.reverse().each((function(_47){ -this.element.insertBefore(_47,this.element.firstChild); +},insertContent:function(_50){ +_50.reverse(false).each((function(_51){ +this.element.insertBefore(_51,this.element.firstChild); }).bind(this)); }}); Insertion.Bottom=Class.create(); Insertion.Bottom.prototype=Object.extend(new Abstract.Insertion("beforeEnd"),{initializeRange:function(){ this.range.selectNodeContents(this.element); this.range.collapse(this.element); -},insertContent:function(_48){ -_48.each((function(_49){ -this.element.appendChild(_49); +},insertContent:function(_52){ +_52.each((function(_53){ +this.element.appendChild(_53); }).bind(this)); }}); Insertion.After=Class.create(); Insertion.After.prototype=Object.extend(new Abstract.Insertion("afterEnd"),{initializeRange:function(){ this.range.setStartAfter(this.element); -},insertContent:function(_50){ -_50.each((function(_51){ -this.element.parentNode.insertBefore(_51,this.element.nextSibling); +},insertContent:function(_54){ +_54.each((function(_55){ +this.element.parentNode.insertBefore(_55,this.element.nextSibling); }).bind(this)); }}); Element.ClassNames=Class.create(); -Element.ClassNames.prototype={initialize:function(_52){ -this.element=$(_52); -},_each:function(_53){ -this.element.className.split(/\s+/).select(function(_54){ -return _54.length>0; -})._each(_53); -},set:function(_55){ -this.element.className=_55; -},add:function(_56){ -if(this.include(_56)){ +Element.ClassNames.prototype={initialize:function(_56){ +this.element=$(_56); +},_each:function(_57){ +this.element.className.split(/\s+/).select(function(_58){ +return _58.length>0; +})._each(_57); +},set:function(_59){ +this.element.className=_59; +},add:function(_60){ +if(this.include(_60)){ return; } -this.set(this.toArray().concat(_56).join(" ")); -},remove:function(_57){ -if(!this.include(_57)){ +this.set(this.toArray().concat(_60).join(" ")); +},remove:function(_61){ +if(!this.include(_61)){ return; } -this.set(this.select(function(_58){ -return _58!=_57; -})); +this.set(this.select(function(_62){ +return _62!=_61; +}).join(" ")); },toString:function(){ return this.toArray().join(" "); }}; @@ -232,6 +242,124 @@ Object.extend(Element.ClassNames.prototype,Enumerable); Object.extend(Element,{condClassName:function(_1,_2,_3){ (_3?Element.addClassName:Element.removeClassName)(_1,_2); }}); +Prado.Element={setValue:function(_4,_5){ +var el=$(_4); +if(el&&typeof (el.value)!="undefined"){ +el.value=_5; +} +},select:function(_7,_8,_9){ +var el=$(_7); +var _10=_7.indexOf("[]")>-1; +if(!el&&!_10){ +return; +} +_8=_10?"check"+_8:el.tagName.toLowerCase()+_8; +var _11=Prado.Element.Selection; +if(isFunction(_11[_8])){ +_11[_8](_10?_7:el,_9); +} +},click:function(_12){ +var el=$(_12); +if(!el){ +return; +} +if(document.createEvent){ +var evt=document.createEvent("HTMLEvents"); +evt.initEvent("click",true,true); +el.dispatchEvent(evt); +}else{ +if(el.fireEvent){ +el.fireEvent("onclick"); +if(isFunction(el.onclick)){ +el.onclick(); +} +} +} +},setAttribute:function(_14,_15,_16){ +var el=$(_14); +if(_15=="disabled"&&_16==false){ +el.removeAttribute(_15); +}else{ +el.setAttribute(_15,_16); +} +},setOptions:function(_17,_18){ +var el=$(_17); +if(el&&el.tagName.toLowerCase()=="select"){ +while(el.length>0){ +el.remove(0); +} +for(var i=0;i<_18.length;i++){ +el.options[el.options.length]=new Option(_18[i][0],_18[i][1]); +} +} +}}; +Prado.Element.Selection={inputValue:function(el,_20){ +switch(el.type.toLowerCase()){ +case "checkbox": +case "radio": +return el.checked=_20; +} +},selectValue:function(el,_21){ +$A(el.options).each(function(_22){ +_22.selected=_22.value==_21; +}); +},selectIndex:function(el,_23){ +if(el.type=="select-one"){ +el.selectedIndex=_23; +}else{ +for(var i=0;i<el.length;i++){ +if(i==_23){ +el.options[i].selected=true; +} +} +} +},selectClear:function(el){ +el.selectedIndex=-1; +},selectAll:function(el){ +$A(el.options).each(function(_24){ +_24.selected=true; +Logger.warn(_24.value); +}); +},selectInvert:function(el){ +$A(el.options).each(function(_25){ +_25.selected=!_25.selected; +}); +},checkValue:function(_26,_27){ +$A(document.getElementsByName(_26)).each(function(el){ +el.checked=el.value==_27; +}); +},checkIndex:function(_28,_29){ +var _30=$A(document.getElementsByName(_28)); +for(var i=0;i<_30.length;i++){ +if(i==_29){ +_30[i].checked=true; +} +} +},checkClear:function(_31){ +$A(document.getElementsByName(_31)).each(function(el){ +el.checked=false; +}); +},checkAll:function(_32){ +$A(document.getElementsByName(_32)).each(function(el){ +el.checked=true; +}); +},checkInvert:function(_33){ +$A(document.getElementsByName(_33)).each(function(el){ +el.checked=!el.checked; +}); +}}; +Object.extend(Prado.Element,{Insert:{After:function(_34,_35){ +new Insertion.After(_34,_35); +},Before:function(_36,_37){ +new Insertion.Before(_36.innerHTML); +},Below:function(_38,_39){ +new Insertion.Bottom(_38,_39); +},Above:function(_40,_41){ +new Insertion.Top(_40,_41); +}},CssClass:{set:function(_42,_43){ +_42=new Element.ClassNames(_42); +_42.set(_43); +}}}); var Field={clear:function(){ for(var i=0;i<arguments.length;i++){ @@ -249,8 +377,11 @@ return true; },select:function(_3){ $(_3).select(); },activate:function(_4){ -$(_4).focus(); -$(_4).select(); +_4=$(_4); +_4.focus(); +if(_4.select){ +_4.select(); +} }}; var Form={serialize:function(_5){ var _6=Form.getElements($(_5)); @@ -263,7 +394,7 @@ _7.push(_8); } return _7.join("&"); },getElements:function(_9){ -var _9=$(_9); +_9=$(_9); var _10=new Array(); for(tagName in Form.Element.Serializers){ var _11=_9.getElementsByTagName(tagName); @@ -273,7 +404,7 @@ _10.push(_11[j]); } return _10; },getInputs:function(_13,_14,_15){ -var _13=$(_13); +_13=$(_13); var _16=_13.getElementsByTagName("input"); if(!_14&&!_15){ return _16; @@ -300,94 +431,99 @@ for(var i=0;i<_23.length;i++){ var _24=_23[i]; _24.disabled=""; } -},focusFirstElement:function(_25){ -var _25=$(_25); -var _26=Form.getElements(_25); -for(var i=0;i<_26.length;i++){ -var _27=_26[i]; -if(_27.type!="hidden"&&!_27.disabled){ -Field.activate(_27); -break; -} -} +},findFirstElement:function(_25){ +return Form.getElements(_25).find(function(_26){ +return _26.type!="hidden"&&!_26.disabled&&["input","select","textarea"].include(_26.tagName.toLowerCase()); +}); +},focusFirstElement:function(_27){ +Field.activate(Form.findFirstElement(_27)); },reset:function(_28){ $(_28).reset(); }}; Form.Element={serialize:function(_29){ -var _29=$(_29); +_29=$(_29); var _30=_29.tagName.toLowerCase(); var _31=Form.Element.Serializers[_30](_29); if(_31){ -return encodeURIComponent(_31[0])+"="+encodeURIComponent(_31[1]); +var key=encodeURIComponent(_31[0]); +if(key.length==0){ +return; +} +if(_31[1].constructor!=Array){ +_31[1]=[_31[1]]; } -},getValue:function(_32){ -var _32=$(_32); -var _33=_32.tagName.toLowerCase(); -var _34=Form.Element.Serializers[_33](_32); -if(_34){ -return _34[1]; +return _31[1].map(function(_33){ +return key+"="+encodeURIComponent(_33); +}).join("&"); +} +},getValue:function(_34){ +_34=$(_34); +var _35=_34.tagName.toLowerCase(); +var _36=Form.Element.Serializers[_35](_34); +if(_36){ +return _36[1]; } }}; -Form.Element.Serializers={input:function(_35){ -switch(_35.type.toLowerCase()){ +Form.Element.Serializers={input:function(_37){ +switch(_37.type.toLowerCase()){ case "submit": case "hidden": case "password": case "text": -return Form.Element.Serializers.textarea(_35); +return Form.Element.Serializers.textarea(_37); case "checkbox": case "radio": -return Form.Element.Serializers.inputSelector(_35); +return Form.Element.Serializers.inputSelector(_37); } return false; -},inputSelector:function(_36){ -if(_36.checked){ -return [_36.name,_36.value]; -} -},textarea:function(_37){ -return [_37.name,_37.value]; -},select:function(_38){ -return Form.Element.Serializers[_38.type=="select-one"?"selectOne":"selectMany"](_38); -},selectOne:function(_39){ -var _40="",opt,index=_39.selectedIndex; +},inputSelector:function(_38){ +if(_38.checked){ +return [_38.name,_38.value]; +} +},textarea:function(_39){ +return [_39.name,_39.value]; +},select:function(_40){ +return Form.Element.Serializers[_40.type=="select-one"?"selectOne":"selectMany"](_40); +},selectOne:function(_41){ +var _42="",opt,index=_41.selectedIndex; if(index>=0){ -opt=_39.options[index]; -_40=opt.value; -if(!_40&&!("value" in opt)){ -_40=opt.text; +opt=_41.options[index]; +_42=opt.value; +if(!_42&&!("value" in opt)){ +_42=opt.text; } } -return [_39.name,_40]; -},selectMany:function(_41){ -var _42=new Array(); -for(var i=0;i<_41.length;i++){ -var opt=_41.options[i]; +return [_41.name,_42]; +},selectMany:function(_43){ +var _44=new Array(); +for(var i=0;i<_43.length;i++){ +var opt=_43.options[i]; if(opt.selected){ -var _44=opt.value; -if(!_44&&!("value" in opt)){ -_44=opt.text; +var _46=opt.value; +if(!_46&&!("value" in opt)){ +_46=opt.text; } -_42.push(_44); +_44.push(_46); } } -return [_41.name,_42]; +return [_43.name,_44]; }}; var $F=Form.Element.getValue; Abstract.TimedObserver=function(){ }; -Abstract.TimedObserver.prototype={initialize:function(_45,_46,_47){ -this.frequency=_46; -this.element=$(_45); -this.callback=_47; +Abstract.TimedObserver.prototype={initialize:function(_47,_48,_49){ +this.frequency=_48; +this.element=$(_47); +this.callback=_49; this.lastValue=this.getValue(); this.registerCallback(); },registerCallback:function(){ setInterval(this.onTimerEvent.bind(this),this.frequency*1000); },onTimerEvent:function(){ -var _48=this.getValue(); -if(this.lastValue!=_48){ -this.callback(this.element,_48); -this.lastValue=_48; +var _50=this.getValue(); +if(this.lastValue!=_50){ +this.callback(this.element,_50); +this.lastValue=_50; } }}; Form.Element.Observer=Class.create(); @@ -400,9 +536,9 @@ return Form.serialize(this.element); }}); Abstract.EventObserver=function(){ }; -Abstract.EventObserver.prototype={initialize:function(_49,_50){ -this.element=$(_49); -this.callback=_50; +Abstract.EventObserver.prototype={initialize:function(_51,_52){ +this.element=$(_51); +this.callback=_52; this.lastValue=this.getValue(); if(this.element.tagName.toLowerCase()=="form"){ this.registerFormCallbacks(); @@ -410,39 +546,29 @@ this.registerFormCallbacks(); this.registerCallback(this.element); } },onElementEvent:function(){ -var _51=this.getValue(); -if(this.lastValue!=_51){ -this.callback(this.element,_51); -this.lastValue=_51; +var _53=this.getValue(); +if(this.lastValue!=_53){ +this.callback(this.element,_53); +this.lastValue=_53; } },registerFormCallbacks:function(){ -var _52=Form.getElements(this.element); -for(var i=0;i<_52.length;i++){ -this.registerCallback(_52[i]); +var _54=Form.getElements(this.element); +for(var i=0;i<_54.length;i++){ +this.registerCallback(_54[i]); } -},registerCallback:function(_53){ -if(_53.type){ -switch(_53.type.toLowerCase()){ +},registerCallback:function(_55){ +if(_55.type){ +switch(_55.type.toLowerCase()){ case "checkbox": case "radio": -_53.target=this; -_53.prev_onclick=_53.onclick||Prototype.emptyFunction; -_53.onclick=function(){ -this.prev_onclick(); -this.target.onElementEvent(); -}; +Event.observe(_55,"click",this.onElementEvent.bind(this)); break; case "password": case "text": case "textarea": case "select-one": case "select-multiple": -_53.target=this; -_53.prev_onchange=_53.onchange||Prototype.emptyFunction; -_53.onchange=function(){ -this.prev_onchange(); -this.target.onElementEvent(); -}; +Event.observe(_55,"change",this.onElementEvent.bind(this)); break; } } @@ -857,9 +983,7 @@ return _4; var Behaviour={list:new Array,register:function(_1){ Behaviour.list.push(_1); },start:function(){ -Behaviour.addLoadEvent(function(){ -Behaviour.apply(); -}); +Event.OnLoad(Behaviour.apply); },apply:function(){ for(h=0;sheet=Behaviour.list[h];h++){ for(selector in sheet){ @@ -872,16 +996,6 @@ sheet[selector](element); } } } -},addLoadEvent:function(_2){ -var _3=window.onload; -if(typeof window.onload!="function"){ -window.onload=_2; -}else{ -window.onload=function(){ -_3(); -_2(); -}; -} }}; Behaviour.start(); diff --git a/framework/Web/Javascripts/js/logger.js b/framework/Web/Javascripts/js/logger.js index 0c617bd7..46233a50 100644 --- a/framework/Web/Javascripts/js/logger.js +++ b/framework/Web/Javascripts/js/logger.js @@ -288,47 +288,91 @@ this.commandIndex=0; } } }}; -Event.observe(window,"load",function(){ +var logConsole; +Event.OnLoad(function(){ logConsole=new LogConsole(); }); -function inspect(_47,_48,_49){ -var _50=[]; -var _51=[]; -for(var _52 in _47){ -if(_52=="______array"){ -continue; -} -try{ -if(_47[_52] instanceof Function){ -if(_49){ -_51.push(_52+":\t"+_47[_52]); -} +function inspect(o){ +var _48=typeof (o); +if(_48=="undefined"){ +return "undefined"; }else{ -if(_47[_52] instanceof Object){ -_51.push(_52+":\t"+inspect(_47[_52],_48,_49)); +if(_48=="number"||_48=="boolean"){ +return o+""; }else{ -if(!_48){ -_50.push(_52+":\t"+_47[_52]); +if(o===null){ +return "null"; } } } +try{ +var _49=(o+""); } catch(e){ -Logger.error("Excetion thrown while inspecting object.",e); +return "["+typeof (o)+"]"; +} +if(typeof (o)=="function"){ +o=_49.replace(/^\s+/,""); +var idx=o.indexOf("{"); +if(idx!=-1){ +o=o.substr(0,idx)+"{...}"; +} +return o; +} +var _51=function(o){ +return ("\""+o.replace(/(["\\])/g,"\\$1")+"\"").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r"); +}; +if(_48=="string"){ +return _51(o); +} +var me=arguments.callee; +var _53; +if(typeof (o.__json__)=="function"){ +_53=o.__json__(); +if(o!==_53){ +return me(_53); +} +} +if(typeof (o.json)=="function"){ +_53=o.json(); +if(o!==_53){ +return me(_53); +} } +if(_48!="function"&&typeof (o.length)=="number"){ +var res=[]; +for(var i=0;i<o.length;i++){ +var val=me(o[i]); +if(typeof (val)!="string"){ +val="undefined"; } -_50.sort(); -_51.sort(); -var _53=_50.concat(_51); -var _54=""; -for(var i=0;i<_53.length;i++){ -_54+=(_53[i]+"\n"); +res.push(val); } -return _54; +return "["+res.join(", ")+"]"; } -Array.prototype.contains=function(_55){ +res=[]; +for(var k in o){ +var _57; +if(typeof (k)=="number"){ +_57="\""+k+"\""; +}else{ +if(typeof (k)=="string"){ +_57=_51(k); +}else{ +continue; +} +} +val=me(o[k]); +if(typeof (val)!="string"){ +continue; +} +res.push(_57+":"+val); +} +return "{"+res.join(", ")+"}"; +} +Array.prototype.contains=function(_58){ for(var i=0;i<this.length;i++){ -if(_55==this[i]){ +if(_58==this[i]){ return true; } } @@ -340,79 +384,86 @@ return Logger.log(arguments[0],arguments[1]); if(typeof Prado=="undefined"){ var Prado={}; } -Prado.Inspector={d:document,types:new Array(),objs:new Array(),hidden:new Array(),opera:window.opera,displaying:"",format:function(str){ +Prado.Inspector={d:document,types:new Array(),objs:new Array(),hidden:new Array(),opera:window.opera,displaying:"",nameList:new Array(),format:function(str){ +if(typeof (str)!="string"){ +return str; +} str=str.replace(/</g,"<"); str=str.replace(/>/g,">"); return str; },parseJS:function(obj){ -var _58; +var _61; if(typeof obj=="string"){ -_58=obj; +_61=obj; obj=eval(obj); } win=typeof obj=="undefined"?window:obj; -this.displaying=_58?_58:win.toString(); +this.displaying=_61?_61:win.toString(); for(js in win){ try{ -if(win[js]&&js.toString().indexOf("Inspector")==-1&&win[js].toString().indexOf("[native code]")==-1){ +if(win[js]&&js.toString().indexOf("Inspector")==-1&&(win[js]+"").indexOf("[native code]")==-1){ t=typeof (win[js]); if(!this.objs[t.toString()]){ this.types[this.types.length]=t; -this.objs[t]=new Array(); +this.objs[t]={}; +this.nameList[t]=new Array(); } -index=this.objs[t].length; -this.objs[t][index]=new Array(); -this.objs[t][index][0]=js; -this.objs[t][index][1]=this.format(win[js].toString()); +this.nameList[t].push(js); +this.objs[t][js]=this.format(win[js]+""); } } catch(err){ } } -},show:function(_59){ -this.d.getElementById(_59).style.display=this.hidden[_59]?"none":"block"; -this.hidden[_59]=this.hidden[_59]?0:1; -},changeSpan:function(_60){ -if(this.d.getElementById(_60).innerHTML.indexOf("+")>-1){ -this.d.getElementById(_60).innerHTML="[-]"; +for(i=0;i<this.types.length;i++){ +this.nameList[this.types[i]].sort(); +} +},show:function(_62){ +this.d.getElementById(_62).style.display=this.hidden[_62]?"none":"block"; +this.hidden[_62]=this.hidden[_62]?0:1; +},changeSpan:function(_63){ +if(this.d.getElementById(_63).innerHTML.indexOf("+")>-1){ +this.d.getElementById(_63).innerHTML="[-]"; }else{ -this.d.getElementById(_60).innerHTML="[+]"; +this.d.getElementById(_63).innerHTML="[+]"; } },buildInspectionLevel:function(){ -var _61=this.displaying; -var _62=_61.split("."); -var _63=["<a href=\"javascript:var_dump()\">[object Window]</a>"]; -var _64=""; -if(_61.indexOf("[object ")>=0){ -return _63.join("."); -} -for(var i=0;i<_62.length;i++){ -_64+=(_64.length?".":"")+_62[i]; -_63[i+1]="<a href=\"javascript:var_dump('"+_64+"')\">"+_62[i]+"</a>"; -} -return _63.join("."); +var _64=this.displaying; +var _65=_64.split("."); +var _66=["<a href=\"javascript:var_dump()\">[object Window]</a>"]; +var _67=""; +if(_64.indexOf("[object ")>=0){ +return _66.join("."); +} +for(var i=0;i<_65.length;i++){ +_67+=(_67.length?".":"")+_65[i]; +_66[i+1]="<a href=\"javascript:var_dump('"+_67+"')\">"+_65[i]+"</a>"; +} +return _66.join("."); },buildTree:function(){ mHTML="<div>Inspecting "+this.buildInspectionLevel()+"</div>"; mHTML+="<ul class=\"topLevel\">"; this.types.sort(); -var _65=0; +var _68=0; for(i=0;i<this.types.length;i++){ -mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('ul"+i+"');Prado.Inspector.changeSpan('sp"+i+"')\"><span id=\"sp"+i+"\">[+]</span><b>"+this.types[i]+"</b> ("+this.objs[this.types[i]].length+")</li><ul style=\"display:none;\" id=\"ul"+i+"\">"; +mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('ul"+i+"');Prado.Inspector.changeSpan('sp"+i+"')\"><span id=\"sp"+i+"\">[+]</span><b>"+this.types[i]+"</b> ("+this.nameList[this.types[i]].length+")</li><ul style=\"display:none;\" id=\"ul"+i+"\">"; this.hidden["ul"+i]=0; -for(e=0;e<this.objs[this.types[i]].length;e++){ -var _66=""; -if(this.objs[this.types[i]][e][1].indexOf("[object ")>=0&&/^[a-zA-Z_]/.test(this.objs[this.types[i]][e][0][0])){ +for(e=0;e<this.nameList[this.types[i]].length;e++){ +var _69=this.nameList[this.types[i]][e]; +var _70=this.objs[this.types[i]][_69]; +var _71=""; +if(_70.indexOf("[object ")>=0&&/^[a-zA-Z_]/.test(_69)){ if(this.displaying.indexOf("[object ")<0){ -_66=" <a href=\"javascript:var_dump('"+this.displaying+"."+this.objs[this.types[i]][e][0]+"')\"><b>more</b></a>"; +_71=" <a href=\"javascript:var_dump('"+this.displaying+"."+_69+"')\"><b>more</b></a>"; }else{ if(this.displaying.indexOf("[object Window]")>=0){ -_66=" <a href=\"javascript:var_dump('"+this.objs[this.types[i]][e][0]+"')\"><b>more</b></a>"; +_71=" <a href=\"javascript:var_dump('"+_69+"')\"><b>more</b></a>"; } } } -mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('mul"+_65+"');Prado.Inspector.changeSpan('sk"+_65+"')\"><span id=\"sk"+_65+"\">[+]</span>"+this.objs[this.types[i]][e][0]+"</li><ul id=\"mul"+_65+"\" style=\"display:none;\"><li style=\"list-style-type:none;\"><pre>"+this.objs[this.types[i]][e][1]+_66+"</pre></li></ul>"; -this.hidden["mul"+_65]=0; -_65++; +mHTML+="<li style=\"cursor:pointer;\" onclick=\"Prado.Inspector.show('mul"+_68+"');Prado.Inspector.changeSpan('sk"+_68+"')\"><span id=\"sk"+_68+"\">[+]</span>"+_69+"</li><ul id=\"mul"+_68+"\" style=\"display:none;\"><li style=\"list-style-type:none;\"><pre>"+_70+_71+"</pre></li></ul>"; +this.hidden["mul"+_68]=0; +_68++; } mHTML+="</ul>"; } @@ -458,4 +509,5 @@ window.scrollTo(0,0); function var_dump(obj){ Prado.Inspector.inspect(obj); } +var print_r=inspect; diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js index 7e81feea..6f347756 100644 --- a/framework/Web/Javascripts/js/validator.js +++ b/framework/Web/Javascripts/js/validator.js @@ -83,7 +83,7 @@ return (isObject(_27)&&y==_27.getFullYear()&&m==_27.getMonth()&&d==_27.getDate() return null; }; Prado.Validation.Util.trim=function(_28){ -if(undef(_28)){ +if(!isString(_28)){ return ""; } return _28.replace(/^\s+|\s+$/g,""); @@ -101,7 +101,7 @@ Prado.Validation.validators=[]; Prado.Validation.forms=[]; Prado.Validation.summaries=[]; Prado.Validation.groups=[]; -Prado.Validation.TargetGroups=[]; +Prado.Validation.TargetGroups={}; Prado.Validation.CurrentTargetGroup=null; Prado.Validation.HasTargetGroup=false; Prado.Validation.ActiveTarget=null; @@ -330,7 +330,6 @@ _63[i].show(_62); } }; Prado.Validation.OnSubmit=function(ev){ -Logger.info("submit"); if(typeof tinyMCE!="undefined"){ tinyMCE.triggerSave(); } @@ -355,14 +354,14 @@ if(_1=="file"){ return true; }else{ var _2=Prado.Validation.Util.trim; -var a=_2(Form.Element.getValue(this.control)); +var a=_2($F(this.control)); var b=_2(this.attr.initialvalue); return (a!=b); } }; Prado.Validation.TRegularExpressionValidator=function(){ var _5=Prado.Validation.Util.trim; -var _6=_5(Form.Element.getValue(this.control)); +var _6=_5($F(this.control)); if(_6==""){ return true; } @@ -372,77 +371,73 @@ return (_8!=null&&_6==_8[0]); }; Prado.Validation.TEmailAddressValidator=Prado.Validation.TRegularExpressionValidator; Prado.Validation.TCustomValidator=function(){ -var _9=Prado.Validation.Util.trim; -var _10=isNull(this.control)?"":_9(Form.Element.getValue(this.control)); -var _11=true; -var _12=this.attr.clientvalidationfunction; -if(isString(_12)&&_12!=""){ -eval("valid = ("+_12+"(this, value) != false);"); -} -return _11; +var _9=isNull(this.control)?null:$F(this.control); +var _10=this.attr.clientvalidationfunction; +eval("var validate = "+_10); +return validate&&isFunction(validate)?validate(this,_9):true; }; Prado.Validation.TRangeValidator=function(){ -var _13=Prado.Validation.Util.trim; -var _14=_13(Form.Element.getValue(this.control)); -if(_14==""){ +var _11=Prado.Validation.Util.trim; +var _12=_11($F(this.control)); +if(_12==""){ return true; } -var _15=this.attr.minimumvalue; -var _16=this.attr.maximumvalue; -if(undef(_15)&&undef(_16)){ +var _13=this.attr.minimumvalue; +var _14=this.attr.maximumvalue; +if(undef(_13)&&undef(_14)){ return true; } -if(_15==""){ -_15=0; +if(_13==""){ +_13=0; } -if(_16==""){ -_16=0; +if(_14==""){ +_14=0; } -var _17=this.attr.type; -if(undef(_17)){ -return (parseFloat(_14)>=parseFloat(_15))&&(parseFloat(_14)<=parseFloat(_16)); +var _15=this.attr.type; +if(undef(_15)){ +return (parseFloat(_12)>=parseFloat(_13))&&(parseFloat(_12)<=parseFloat(_14)); } -var min=this.convert(_17,_15); -var max=this.convert(_17,_16); -_14=this.convert(_17,_14); -return _14>=min&&_14<=max; +var min=this.convert(_15,_13); +var max=this.convert(_15,_14); +_12=this.convert(_15,_12); +return _12>=min&&_12<=max; }; Prado.Validation.TCompareValidator=function(){ -var _20=Prado.Validation.Util.trim; -var _21=_20(Form.Element.getValue(this.control)); -if(_21.length==0){ +var _18=Prado.Validation.Util.trim; +var _19=_18($F(this.control)); +if(_19.length==0){ return true; } -var _22; -var _23=$(this.attr.controlhookup); -if(_23){ -_22=_20(Form.Element.getValue(_23)); +var _20; +var _21=$(this.attr.controlhookup); +if(_21){ +_20=_18($F(_21)); }else{ -_22=isString(this.attr.valuetocompare)?this.attr.valuetocompare:""; +_20=isString(this.attr.valuetocompare)?this.attr.valuetocompare:""; } -var _24=Prado.Validation.TCompareValidator.compare; -var _25=_24.bind(this)(_21,_22); -if(_23){ -var _26=this.attr.controlcssclass; -if(isString(_26)&&_26.length>0){ -Element.condClassName(_23,_26,!_25); +var _22=Prado.Validation.TCompareValidator.compare; +var _23=_22.bind(this)(_19,_20); +if(_21){ +var _24=this.attr.controlcssclass; +if(isString(_24)&&_24.length>0){ +Element.condClassName(_21,_24,!_23); } if(undef(this.observingComparee)){ -Event.observe(_23,"change",this.validate.bind(this)); +Event.observe(_21,"change",this.validate.bind(this)); this.observingComparee=true; } } -return _25; +return _23; }; -Prado.Validation.TCompareValidator.compare=function(_27,_28){ +Prado.Validation.TCompareValidator.compare=function(_25,_26){ var op1,op2; -if((op1=this.convert(this.attr.type,_27))==null){ +if((op1=this.convert(this.attr.type,_25))==null){ return false; } if(this.attr.operator=="DataTypeCheck"){ return true; } -if((op2=this.convert(this.attr.type,_28))==null){ +if((op2=this.convert(this.attr.type,_26))==null){ return true; } switch(this.attr.operator){ @@ -463,75 +458,75 @@ return (op1==op2); Prado.Validation.TRequiredListValidator=function(){ var min=undef(this.attr.min)?Number.NEGATIVE_INFINITY:parseInt(this.attr.min); var max=undef(this.attr.max)?Number.POSITIVE_INFINITY:parseInt(this.attr.max); -var _30=document.getElementsByName(this.attr.selector); -if(_30.length<=0){ -_30=document.getElementsBySelector(this.attr.selector); +var _28=document.getElementsByName(this.attr.selector); +if(_28.length<=0){ +_28=document.getElementsBySelector(this.attr.selector); } -if(_30.length<=0){ +if(_28.length<=0){ return true; } -var _31=new Array(); +var _29=new Array(); if(isString(this.attr.required)&&this.attr.required.length>0){ -_31=this.attr.required.split(/,\s* /); +_29=this.attr.required.split(/,\s* /); } -var _32=true; -var _33=Prado.Validation.TRequiredListValidator; -switch(_30[0].type){ +var _30=true; +var _31=Prado.Validation.TRequiredListValidator; +switch(_28[0].type){ case "radio": case "checkbox": -_32=_33.IsValidRadioList(_30,min,max,_31); +_30=_31.IsValidRadioList(_28,min,max,_29); break; case "select-multiple": -_32=_33.IsValidSelectMultipleList(_30,min,max,_31); +_30=_31.IsValidSelectMultipleList(_28,min,max,_29); break; } -var _34=this.attr.elementcssclass; -if(isString(_34)&&_34.length>0){ -map(_30,function(_35){ -condClass(_35,_34,!_32); +var _32=this.attr.elementcssclass; +if(isString(_32)&&_32.length>0){ +map(_28,function(_33){ +condClass(_33,_32,!_30); }); } if(undef(this.observingRequiredList)){ -Event.observe(_30,"change",this.validate.bind(this)); +Event.observe(_28,"change",this.validate.bind(this)); this.observingRequiredList=true; } -return _32; +return _30; }; -Prado.Validation.TRequiredListValidator.IsValidRadioList=function(_36,min,max,_37){ -var _38=0; -var _39=new Array(); -for(var i=0;i<_36.length;i++){ -if(_36[i].checked){ -_38++; -_39.push(_36[i].value); +Prado.Validation.TRequiredListValidator.IsValidRadioList=function(_34,min,max,_35){ +var _36=0; +var _37=new Array(); +for(var i=0;i<_34.length;i++){ +if(_34[i].checked){ +_36++; +_37.push(_34[i].value); } } -return Prado.Validation.TRequiredListValidator.IsValidList(_38,_39,min,max,_37); +return Prado.Validation.TRequiredListValidator.IsValidList(_36,_37,min,max,_35); }; -Prado.Validation.TRequiredListValidator.IsValidSelectMultipleList=function(_41,min,max,_42){ -var _43=0; -var _44=new Array(); -for(var i=0;i<_41.length;i++){ -var _45=_41[i]; -for(var j=0;j<_45.options.length;j++){ -if(_45.options[j].selected){ -_43++; -_44.push(_45.options[j].value); +Prado.Validation.TRequiredListValidator.IsValidSelectMultipleList=function(_39,min,max,_40){ +var _41=0; +var _42=new Array(); +for(var i=0;i<_39.length;i++){ +var _43=_39[i]; +for(var j=0;j<_43.options.length;j++){ +if(_43.options[j].selected){ +_41++; +_42.push(_43.options[j].value); } } } -return Prado.Validation.TRequiredListValidator.IsValidList(_43,_44,min,max,_42); +return Prado.Validation.TRequiredListValidator.IsValidList(_41,_42,min,max,_40); }; -Prado.Validation.TRequiredListValidator.IsValidList=function(_47,_48,min,max,_49){ -var _50=true; -if(_49.length>0){ -if(_48.length<_49.length){ +Prado.Validation.TRequiredListValidator.IsValidList=function(_45,_46,min,max,_47){ +var _48=true; +if(_47.length>0){ +if(_46.length<_47.length){ return false; } -for(var k=0;k<_49.length;k++){ -_50=_50&&_48.contains(_49[k]); +for(var k=0;k<_47.length;k++){ +_48=_48&&_46.contains(_47[k]); } } -return _50&&_47>=min&&_47<=max; +return _48&&_45>=min&&_45<=max; }; diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index f8bfc28b..fb6cca06 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -127,13 +127,13 @@ abstract class TBaseValidator extends TLabel implements IValidator */ protected function getClientScriptOptions() { - $options['ID'] = $this->getClientID(); - $options['Display'] = $this->getDisplay(); - $options['ErrorMessage'] = $this->getErrorMessage(); - $options['FocusOnError'] = $this->getFocusOnError(); - $options['FocusElementID'] = $this->getFocusElementID(); - $options['ValidationGroup'] = $this->getValidationGroup(); - $options['ControlToValidate'] = $this->getValidationTarget()->getClientID(); + $options['id'] = $this->getClientID(); + $options['display'] = $this->getDisplay(); + $options['errormessage'] = $this->getErrorMessage(); + $options['focusonerror'] = $this->getFocusOnError(); + $options['focuselementid'] = $this->getFocusElementID(); + $options['validationgroup'] = $this->getValidationGroup(); + $options['controltovalidate'] = $this->getValidationTarget()->getClientID(); return $options; } @@ -146,7 +146,7 @@ abstract class TBaseValidator extends TLabel implements IValidator protected function onPreRender($param) { $scripts = $this->getPage()->getClientScript(); - $scriptKey = "prado:".get_class($this); + $scriptKey = "TBaseValidator"; if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) { $scripts->registerPradoScript('validator'); @@ -234,7 +234,8 @@ abstract class TBaseValidator extends TLabel implements IValidator */ public function getErrorMessage() { - return $this->getViewState('ErrorMessage',''); + return $this->getText(); + //return $this->getViewState('ErrorMessage',''); } /** @@ -243,7 +244,8 @@ abstract class TBaseValidator extends TLabel implements IValidator */ public function setErrorMessage($value) { - $this->setViewState('ErrorMessage',$value,''); + $this->setText($value); + //$this->setViewState('ErrorMessage',$value,''); } /** @@ -364,7 +366,8 @@ abstract class TBaseValidator extends TLabel implements IValidator $this->setIsValid(true); $control=$this->getValidationTarget(); if($control && $this->getVisible(true) && $this->getEnabled()) - $valid=$this->evaluateIsValid(); + $this->setIsValid($this->evaluateIsValid()); + return $this->getIsValid(); } /** diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index 7109bca4..e03bc676 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -75,11 +75,15 @@ class TButton extends TWebControl implements IPostBackEventHandler $writer->addAttribute('name',$uniqueID);
$writer->addAttribute('value',$this->getText());
if($this->getEnabled(true))
- {
+ {
$scripts = $this->getPage()->getClientScript();
- $options = $this->getPostBackOptions();
- $postback = $scripts->getPostBackEventReference($this, '', $options, false);
- $scripts->registerClientEvent($this, "click", $postback);
+ if($scripts->isEndScriptRegistered("TBaseValidator"))
+ {
+ $group = $this->getValidationGroup();
+ $group = strlen($group) ? ",'".$group."'" : '';
+ $script = "Prado.Validation.AddTarget('{$uniqueID}'{$group});";
+ $scripts->registerEndScript("{$uniqueID}:target", $script);
+ }
}
else if($this->getEnabled()) // in this case, parent will not render 'disabled'
$writer->addAttribute('disabled','disabled');
|