﻿
function xmlAction_updateXmlFromBinding(theObject){var binding;if(typeof(theObject)=="string"){binding=this.nodeBinding[theObject];theObject=this.field(theObject);if(!theObject){theObject=this.getElementById(theObject);}
if(!theObject){return;}}else{binding=this.nodeBinding[theObject.name];if(!binding){binding=this.nodeBinding[theObject.id];}}
if(!binding){return;}
var value;var remove=false;switch(theObject.nodeName){case"INPUT":value=theObject.value;if(theObject.type=="checkbox"){if(!theObject.checked){remove=true;}}else if(theObject.length>0){value=null;for(var i=0;i<theObject.length;i++){if(theObject[i].checked){value=theObject[i].value;break;}}
if(value==null){remove=true;}}
break;case"SELECT":value=theObject.options[theObject.selectedIndex].value;break;default:value=theObject.value;return;}
if(binding.nodeName){if(remove){var node=this.selectSingleNode(binding.nodeName+"[@"+binding.attributeName+"='"+value+"']",binding.parentNode);if(node){binding.parentNode.removeChild(node);}}else{var el=binding.parentNode.ownerDocument.createElement(binding.nodeName);el.setAttribute(binding.attributeName,value);binding.parentNode.appendChild(el);}}else if(binding.attributeName){if(binding.bitMask==1){var currentValue=binding.node.getAttribute(binding.attributeName);if(!currentValue)currentValue=0;binding.node.setAttribute(binding.attributeName,remove?currentValue&(~value):currentValue|value);}else{if(remove){binding.node.removeAttribute(binding.attributeName);}else{binding.node.setAttribute(binding.attributeName,value);}}}else{if(binding.node.nodeType==3){binding.node.nodeValue=value;}else{var textNode=this.selectSingleNode("#text",binding.node);if(textNode){textNode.nodeValue=value;}else{binding.node.appendChild(binding.node.ownerDocument.createTextNode(value));}}}}
function xmlAction_successHandler(httpResponse,options){this.hideFetching();var callbackParams=options.argument["callbackParams"];var scope=this;if(callbackParams&&callbackParams.scope){scope=callbackParams.scope;}
options.argument["successHandler"].apply(scope,[httpResponse.responseXML.documentElement,callbackParams]);}
function xmlAction_failureHandler(httpResponse,options){this.hideFetching();var callbackParams=options.argument["callbackParams"];var scope=this;if(callbackParams&&callbackParams.scope){scope=callbackParams.scope;}
if(options.argument["failureHandler"]){options.argument["failureHandler"].apply(scope,[options,callbackParams]);}else{alert("Failed - "+httpResponse.statusText);}}
function xmlAction_hideFetching(){this.fetchCount--;var fetching=this.getElementById("fetching");if(fetching){if(this.fetchCount==0){fetching.innerHTML="";fetching.style.display="none";if(this.hFetching){clearTimeout(this.hFetching);}
this.hFetching=null;document.body.style.cursor="";}}}
function xmlAction_showFetchingImg(){var fetching=this.getElementById("fetching");if(fetching){document.body.style.cursor="wait";fetching.innerHTML="<img src='/fp/shared/images/fetching.gif' width='16' height='16'/>";fetching.style.display="block";}}
function xmlAction_showFetching(immediate){var fetching=this.getElementById("fetching");if(fetching){if(immediate){this.showFetchingImg();}else{this.hFetching=setTimeout("AS("+this.id+").showFetchingImg()",400);}}
this.fetchCount++;}
function xmlAction_makeRequest(theUrl,postData,force,successHandler,failureHandler,callbackParams,immediateFetching){this.showFetching(immediateFetching);if(force){theUrl+=((theUrl.indexOf("?")>=0)?"&":"?")+"refresh="+(new Date().getTime());}
var argPkg={successHandler:successHandler,failureHandler:failureHandler,callbackParams:callbackParams};var opts={url:theUrl,success:xmlAction_successHandler,failure:xmlAction_failureHandler,scope:this,headers:{"X-XSRF":xsrf(),"Content-type":"text/xml"},argument:argPkg};if(typeof(postData)=="object"){opts.xmlData=postData;}else{opts.params=postData;}
Ext.Ajax.request(opts);}
function xmlAction(id){this.base=AspenScriptlet;this.base(id);this.makeRequest=xmlAction_makeRequest;this.showFetching=xmlAction_showFetching;this.showFetchingImg=xmlAction_showFetchingImg;this.hideFetching=xmlAction_hideFetching;this.fetchCount=0;this.updateXmlFromBinding=xmlAction_updateXmlFromBinding;this.nodeBinding=new Array();}