From 9f2ecd591d5be41bb9dc7b8a0fa144ac35a173bb Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 9 Jan 2006 04:39:05 +0000 Subject: TRequiredFieldValidator works now. See FunctionalTests/index.php in your browser. --- framework/Web/Javascripts/base/postback.js | 7 +- framework/Web/Javascripts/base/validation.js | 4 +- framework/Web/Javascripts/base/validators.js | 10 +- framework/Web/Javascripts/js/base.js | 192 ++++----- framework/Web/Javascripts/js/dom.js | 520 +++++++++++++++--------- framework/Web/Javascripts/js/logger.js | 184 ++++++--- framework/Web/Javascripts/js/validator.js | 177 ++++---- framework/Web/UI/WebControls/TBaseValidator.php | 25 +- framework/Web/UI/WebControls/TButton.php | 12 +- 9 files changed, 656 insertions(+), 475 deletions(-) (limited to 'framework/Web') 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:"(?:)((\n|\r|.)*?)(?:)",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]+>/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"; 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;i0;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;i0)){ 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=""+this.content+"
"; @@ -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=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/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-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=["[object Window]"]; -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]=""+_62[i]+""; -} -return _63.join("."); +var _64=this.displaying; +var _65=_64.split("."); +var _66=["[object Window]"]; +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]=""+_65[i]+""; +} +return _66.join("."); },buildTree:function(){ mHTML="
Inspecting "+this.buildInspectionLevel()+"
"; mHTML+="
    "; this.types.sort(); -var _65=0; +var _68=0; for(i=0;i[+]"+this.types[i]+" ("+this.objs[this.types[i]].length+")
      "; +mHTML+="
    • [+]"+this.types[i]+" ("+this.nameList[this.types[i]].length+")
      • "; this.hidden["ul"+i]=0; -for(e=0;e=0&&/^[a-zA-Z_]/.test(this.objs[this.types[i]][e][0][0])){ +for(e=0;e=0&&/^[a-zA-Z_]/.test(_69)){ if(this.displaying.indexOf("[object ")<0){ -_66=" more"; +_71=" more"; }else{ if(this.displaying.indexOf("[object Window]")>=0){ -_66=" more"; +_71=" more"; } } } -mHTML+="
      • [+]"+this.objs[this.types[i]][e][0]+"
        • "+this.objs[this.types[i]][e][1]+_66+"
        "; -this.hidden["mul"+_65]=0; -_65++; +mHTML+="
      • [+]"+_69+"
        • "+_70+_71+"
        "; +this.hidden["mul"+_68]=0; +_68++; } mHTML+="
      "; } @@ -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'); -- cgit v1.2.3