/*
 * Copyright 2004-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
dojo.declare("Spring.DefaultEquals",null,{equals:function(_1){if(_1.declaredClass&&_1.declaredClass==this.declaredClass){return true;}else{return false;}}});dojo.declare("Spring.ElementDecoration",[Spring.AbstractElementDecoration,Spring.DefaultEquals],{constructor:function(_2){this.widgetAttrs={};this.copyFields=new Array("name","value","type","checked","selected","readOnly","disabled","alt","maxLength","class","title");dojo.mixin(this,_2);this.element=dojo.byId(this.elementId);this.elementId=dojo.isString(this.elementId)?this.elementId:this.elementId.id;if(this.widgetModule==""){this.widgetModule=this.widgetType;}dojo.require(this.widgetModule);},apply:function(){if(dijit.byId(this.elementId)){dijit.byId(this.elementId).destroyRecursive(false);}if(!this.element){console.error("Could not apply "+this.widgetType+" decoration.  Element with id '"+this.elementId+"' not found in the DOM.");}else{var _3=this.widgetAttrs["datePattern"];if(_3&&this.widgetType=="dijit.form.DateTextBox"){if(!this.widgetAttrs["value"]){this.widgetAttrs["value"]=dojo.date.locale.parse(this.element.value,{selector:"date",datePattern:_3});}if(!this.widgetAttrs["serialize"]){this.widgetAttrs["serialize"]=function(d,_4){return dojo.date.locale.format(d,{selector:"date",datePattern:_3});};}if(!this.widgetAttrs["constraints"]){this.widgetAttrs["constraints"]={};}if(!this.widgetAttrs["constraints"].datePattern){this.widgetAttrs["constraints"].datePattern=_3;}}var _5=this.widgetAttrs["timePattern"];if(_5&&this.widgetType=="dijit.form.TimeTextBox"){if(!this.widgetAttrs["value"]){this.widgetAttrs["value"]=dojo.date.locale.parse(this.element.value,{selector:"time",timePattern:_5});}if(!this.widgetAttrs["serialize"]){this.widgetAttrs["serialize"]=function(d,_6){return dojo.date.locale.format(d,{selector:"time",timePattern:_5});};}if(!this.widgetAttrs["constraints"]){this.widgetAttrs["constraints"]={};}if(!this.widgetAttrs["constraints"].timePattern){this.widgetAttrs["constraints"].timePattern=_5;}}for(var _7 in this.copyFields){_7=this.copyFields[_7];if(!this.widgetAttrs[_7]&&this.element[_7]&&(typeof this.element[_7]!="number"||(typeof this.element[_7]=="number"&&this.element[_7]>=0))){this.widgetAttrs[_7]=this.element[_7];}}if(this.element["style"]&&this.element["style"].cssText){this.widgetAttrs["style"]=this.element["style"].cssText;}var _8=dojo.eval(this.widgetType);this.widget=new _8(this.widgetAttrs,this.element);this.widget.startup();}return this;},validate:function(){if(!this.widget.isValid){return true;}var _9=this.widget.isValid(false);if(!_9){this.widget.state="Error";this.widget._setStateClass();}return _9;}});dojo.declare("Spring.ValidateAllDecoration",[Spring.AbstractValidateAllDecoration,Spring.DefaultEquals],{constructor:function(_a){this.originalHandler=null;this.connection=null;dojo.mixin(this,_a);},apply:function(){var _b=dojo.byId(this.elementId);if(!_b){console.error("Could not apply ValidateAll decoration.  Element with id '"+this.elementId+"' not found in the DOM.");}else{this.originalHandler=_b[this.event];var _c=this;_b[this.event]=function(_d){_c.handleEvent(_d,_c);};}return this;},cleanup:function(){dojo.disconnect(this.connection);},handleEvent:function(_e,_f){if(!Spring.validateAll()){dojo.publish(this.elementId+"/validation",[false]);dojo.stopEvent(_e);}else{dojo.publish(this.elementId+"/validation",[true]);if(dojo.isFunction(_f.originalHandler)){var _10=_f.originalHandler(_e);if(_10==false){dojo.stopEvent(_e);}}}}});dojo.declare("Spring.AjaxEventDecoration",[Spring.AbstractAjaxEventDecoration,Spring.DefaultEquals],{constructor:function(_11){this.validationSubscription=null;this.connection=null;this.allowed=true;dojo.mixin(this,_11);},apply:function(){var _12=dijit.byId(this.elementId)?dijit.byId(this.elementId):dojo.byId(this.elementId);if(!_12){console.error("Could not apply AjaxEvent decoration.  Element with id '"+this.elementId+"' not found in the DOM.");}else{this.validationSubscription=dojo.subscribe(this.elementId+"/validation",this,"_handleValidation");this.connection=dojo.connect(_12,this.event,this,"submit");}return this;},cleanup:function(){dojo.unsubscribe(this.validationSubscription);dojo.disconnect(this.connection);},submit:function(_13){if(this.sourceId==""){this.sourceId=this.elementId;}if(this.formId==""){Spring.remoting.getLinkedResource(this.sourceId,this.params,this.popup);}else{if(this.allowed){Spring.remoting.submitForm(this.sourceId,this.formId,this.params);}}dojo.stopEvent(_13);},_handleValidation:function(_14){if(!_14){this.allowed=false;}else{this.allowed=true;}}});dojo.declare("Spring.RemotingHandler",Spring.AbstractRemotingHandler,{constructor:function(){},submitForm:function(_15,_16,_17){var _18=new Object();for(var key in _17){_18[key]=_17[key];}var _19=dojo.byId(_15);if(_19!=null){if(_19.value!=undefined&&_19.type&&("button,submit,reset").indexOf(_19.type)<0){_18[_15]=_19.value;}else{if(_19.name!=undefined){_18[_19.name]=_19.name;}else{_18[_15]=_15;}}}if(!_18["ajaxSource"]){_18["ajaxSource"]=_15;}var _1a=dojo.byId(_16);var _1b=dojo.string.trim(_1a.method);_1b=_1b.length>0?_1b.toUpperCase():"GET";dojo.xhr(_1b,{content:_18,form:_16,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError},_1b=="POST"?true:false);},getLinkedResource:function(_1c,_1d,_1e){this.getResource(dojo.byId(_1c).href,_1d,_1e);},getResource:function(_1f,_20,_21){dojo.xhrGet({url:_1f,content:_20,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError,modal:_21});},handleResponse:function(_22,_23){var _24=_23.xhr.getResponseHeader("Spring-Redirect-URL");var _25=_23.xhr.getResponseHeader("Spring-Modal-View");var _26=((dojo.isString(_25)&&_25.length>0)||_23.args.modal);if(dojo.isString(_24)&&_24.length>0){if(_26){Spring.remoting._renderURLToModalDialog(_24);return _22;}else{if(_24.indexOf("/")>=0){window.location=window.location.protocol+"//"+window.location.host+_24;}else{var _27=window.location.protocol+"//"+window.location.host+window.location.pathname;var _28=_27.lastIndexOf("/");_27=_27.substr(0,_28+1)+_24;if(_27==window.location){Spring.remoting.getResource(_27,_23.args.content,false);}else{window.location=_27;}}return _22;}}else{if((dojo.string.trim(_22).length==0)&&(_23.xhr.status!=204)&&(_23.xhr.status!=205)){if(Spring.debug){Spring.remoting.showError("Received empty response with no Spring redirect headers. If this is intentional set the response status code to 204 or 205.");}}}var _29="(?:<script(.|[\n|\r])*?>)((\n|\r|.)*?)(?:</script>)";var _2a=[];var _2b=new RegExp(_29,"img");var _2c=new RegExp(_29,"im");var _2d=_22.match(_2b);if(_2d!=null){for(var i=0;i<_2d.length;i++){var _2e=(_2d[i].match(_2c)||["","",""])[2];_2e=_2e.replace(/<!--/mg,"").replace(/\/\/-->/mg,"").replace(/<!\[CDATA\[(\/\/>)*/mg,"").replace(/(<!)*\]\]>/mg,"");_2a.push(_2e);}}_22=_22.replace(_2b,"<script> // Original script removed to avoid re-execution </script>");if(_26){Spring.remoting._renderResponseToModalDialog(_22);}else{var _2f=dojo.doc.createElement("span");_2f.id="ajaxResponse";_2f.style.display="none";document.body.appendChild(_2f);_2f.innerHTML=_22;var _30=new dojo.NodeList(_2f);var _31=_30.query(">").orphan();_30.orphan();_31.forEach(function(_32){if(_32.id!=null&&_32.id!=""){var _33=dijit.byId(_32.id)?dijit.byId(_32.id).domNode:dojo.byId(_32.id);if(!_33){console.error("An existing DOM elment with id '"+_32.id+"' could not be found for replacement.");}else{_33.parentNode.replaceChild(_32,_33);}}});}dojo.forEach(_2a,function(_34){dojo.eval(_34);});return _22;},handleError:function(_35,_36){dojo.require("dijit.Dialog");console.error("HTTP status code: ",_36.xhr.status);if(Spring.debug&&_36.xhr.status!=200){var _37=new dijit.Dialog({title:"Ajax Request Error"});dojo.connect(_37,"hide",_37,function(){this.destroyRecursive(false);});_37.domNode.style.overflow="auto";_37.setContent(_36.xhr.responseText);_37.show();}return _35;},showError:function(_38){dojo.require("dijit.Dialog");var _39=new dijit.Dialog({title:"Error Message"});dojo.connect(_39,"hide",_39,function(){this.destroyRecursive(false);});_39.domNode.style.width="500px";_39.setContent(_38);_39.show();},_renderURLToModalDialog:function(url){Spring.remoting.getResource(url,{},true);},_renderResponseToModalDialog:function(_3a){dojo.require("dijit.Dialog");var _3b=new dijit.Dialog({});_3b.setContent(_3a);dojo.connect(_3b,"hide",_3b,function(){this.destroyRecursive(false);});_3b.show();}});dojo.declare("Spring.CommandLinkDecoration",[Spring.AbstractCommandLinkDecoration,Spring.DefaultEquals],{constructor:function(_3c){dojo.mixin(this,_3c);},apply:function(){var _3d=dojo.byId(this.elementId);if(!dojo.hasClass(_3d,"progressiveLink")){var _3e=new dojo.NodeList(_3d);_3e.addContent(this.linkHtml,"after").orphan("*");_3d=dojo.byId(this.elementId);}_3d.submitFormFromLink=this.submitFormFromLink;return this;},submitFormFromLink:function(_3f,_40,_41){var _42=[];var _43=dojo.byId(_3f);var _44=document.createElement("input");_44.name=_40;_44.value="submitted";_42.push(_44);dojo.forEach(_41,function(_45){var _46=document.createElement("input");_46.name=_45.name;_46.value=_45.value;_42.push(_46);});dojo.forEach(_42,function(_47){dojo.addClass(_47,"SpringLinkInput");dojo.place(_47,_43,"last");});if((_43.onsubmit?!_43.onsubmit():false)||!_43.submit()){dojo.forEach(_42,function(_48){_48.parentNode.removeChild(_48);});}}});dojo.addOnLoad(Spring.initialize);
