Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
/*
 * 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.copyFields=new Array("name","value","type","checked","selected","readOnly","disabled","alt","maxLength","class","title");dojo.mixin(this,_2);if(this.widgetModule==""){this.widgetModule=this.widgetType;}},apply:function(){if(dijit.byId(this.elementId)){dijit.byId(this.elementId).destroyRecursive(false);}var _3=dojo.byId(this.elementId);if(!_3){console.error("Could not apply "+this.widgetType+" decoration.  Element with id '"+this.elementId+"' not found in the DOM.");}else{var _4=this.widgetAttrs["datePattern"];if(_4&&this.widgetType=="dijit.form.DateTextBox"){if(!this.widgetAttrs["value"]){this.widgetAttrs["value"]=dojo.date.locale.parse(_3.value,{selector:"date",datePattern:_4});}if(!this.widgetAttrs["serialize"]){this.widgetAttrs["serialize"]=function(d,_6){return dojo.date.locale.format(d,{selector:"date",datePattern:_4});};}}for(var _7 in this.copyFields){_7=this.copyFields[_7];if(!this.widgetAttrs[_7]&&_3[_7]&&(typeof _3[_7]!="number"||(typeof _3[_7]=="number"&&_3[_7]>=0))){this.widgetAttrs[_7]=_3[_7];}}if(_3["style"]&&_3["style"].cssText){this.widgetAttrs["style"]=_3["style"].cssText;}dojo.require(this.widgetModule);var _8=dojo.eval(this.widgetType);this.widget=new _8(this.widgetAttrs,_3);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);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(){this.validationSubscription=dojo.subscribe(this.elementId+"/validation",this,"_handleValidation");this.connection=dojo.connect(dojo.byId(this.elementId),this.event,this,"submit");return this;},cleanup:function(){dojo.unsubscribe(this.validationSubscription);dojo.disconnect(this.connection);},submit:function(_12){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(_12);},_handleValidation:function(_13){if(!_13){this.allowed=false;}else{this.allowed=true;}}});dojo.declare("Spring.RemotingHandler",Spring.AbstractRemotingHandler,{constructor:function(){},submitForm:function(_14,_15,_16){var _17=new Object();for(var key in _16){_17[key]=_16[key];}var _19=dojo.byId(_14);if(_19!=null){if(_19.value!=undefined&&_19.type&&("button,submit,reset").indexOf(_19.type)<0){_17[_14]=_19.value;}else{if(_19.name!=undefined){_17[_19.name]=_19.name;}else{_17[_14]=_14;}}}if(!_17["ajaxSource"]){_17["ajaxSource"]=_14;}dojo.xhrPost({content:_17,form:_15,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError});},getLinkedResource:function(_1a,_1b,_1c){this.getResource(dojo.byId(_1a).href,_1b,_1c);},getResource:function(_1d,_1e,_1f){dojo.xhrGet({url:_1d,content:_1e,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError,modal:_1f});},handleResponse:function(_20,_21){var _22=_21.xhr.getResponseHeader("Spring-Redirect-URL");var _23=_21.xhr.getResponseHeader("Spring-Modal-View");var _24=((dojo.isString(_23)&&_23.length>0)||_21.args.modal);if(dojo.isString(_22)&&_22.length>0){if(_24){Spring.remoting.renderURLToModalDialog(_22,_21);return _20;}else{if(_22.indexOf("/")>=0){window.location=window.location.protocol+"//"+window.location.host+_22;}else{var _25=window.location.protocol+"//"+window.location.host+window.location.pathname;var _26=_25.lastIndexOf("/");_25=_25.substr(0,_26+1)+_22;if(_25==window.location){Spring.remoting.getResource(_25,_21.args.content,false);}else{window.location=_25;}}return _20;}}var _27="(?:<script(.|[\n|\r])*?>)((\n|\r|.)*?)(?:</script>)";var _28=[];var _29=new RegExp(_27,"img");var _2a=new RegExp(_27,"im");var _2b=_20.match(_29);if(_2b!=null){for(var i=0;i<_2b.length;i++){var _2d=(_2b[i].match(_2a)||["","",""])[2];_2d=_2d.replace(/<!--/mg,"").replace(/\/\/-->/mg,"").replace(/<!\[CDATA\[(\/\/>)*/mg,"").replace(/(<!)*\]\]>/mg,"");_28.push(_2d);}}_20=_20.replace(_29,"");var _2e=dojo.doc.createElement("span");_2e.id="ajaxResponse";_2e.style.visibility="hidden";document.body.appendChild(_2e);_2e.innerHTML=_20;var _2f=new dojo.NodeList(_2e);var _30=_2f.query("#ajaxResponse > *").orphan();_2f.orphan();if(_24){Spring.remoting.renderNodeListToModalDialog(_30);}else{_30.forEach(function(_31){if(_31.id!=null&&_31.id!=""){var _32=dojo.byId(_31.id);if(!_32){console.error("An existing DOM elment with id '"+_31.id+"' could not be found for replacement.");}else{_32.parentNode.replaceChild(_31,_32);}}});}dojo.forEach(_28,function(_33){dojo.eval(_33);});return _20;},handleError:function(_34,_35){dojo.require("dijit.Dialog");console.error("HTTP status code: ",_35.xhr.status);if(Spring.debug&&_35.xhr.status!=200){var _36=new dijit.Dialog({});dojo.connect(_36,"hide",_36,function(){this.destroyRecursive(false);});_36.domNode.style.width="80%";_36.domNode.style.height="80%";_36.domNode.style.textAlign="left";_36.setContent(_35.xhr.responseText);_36.show();}return _34;},renderURLToModalDialog:function(url,_38){url=url+"&"+dojo.objectToQuery(_38.args.content);Spring.remoting.getResource(url,{},true);},renderNodeListToModalDialog:function(_39){dojo.require("dijit.Dialog");var _3a=new dijit.Dialog({});_3a.setContent(_39);dojo.connect(_3a,"hide",_3a,function(){this.destroyRecursive(false);});_3a.show();}});dojo.declare("Spring.CommandLinkDecoration",[Spring.AbstractCommandLinkDecoration,Spring.DefaultEquals],{constructor:function(_3b){dojo.mixin(this,_3b);},apply:function(){var _3c=dojo.byId(this.elementId);if(!dojo.hasClass(_3c,"progressiveLink")){var _3d=new dojo.NodeList(_3c);_3d.addContent(this.linkHtml,"after").orphan("*");_3c=dojo.byId(this.elementId);}_3c.submitFormFromLink=this.submitFormFromLink;return this;},submitFormFromLink:function(_3e,_3f,_40){var _41=[];var _42=dojo.byId(_3e);var _43=document.createElement("input");_43.name=_3f;_43.value="submitted";_41.push(_43);dojo.forEach(_40,function(_44){var _45=document.createElement("input");_45.name=_44.name;_45.value=_44.value;_41.push(_45);});dojo.forEach(_41,function(_46){dojo.addClass(_46,"SpringLinkInput");dojo.place(_46,_42,"last");});if((_42.onsubmit?!_42.onsubmit():false)||!_42.submit()){dojo.forEach(_41,function(_47){_42.removeChild(_47);});}}});dojo.addOnLoad(Spring.initialize);
New to GrepCode? Check out our FAQ X