| 1 | // SpryData.js - version 0.41 - Spry Pre-Release 1.6 |
|---|
| 2 | // |
|---|
| 3 | // Copyright (c) 2007. Adobe Systems Incorporated. |
|---|
| 4 | // All rights reserved. |
|---|
| 5 | // |
|---|
| 6 | // Redistribution and use in source and binary forms, with or without |
|---|
| 7 | // modification, are permitted provided that the following conditions are met: |
|---|
| 8 | // |
|---|
| 9 | // * Redistributions of source code must retain the above copyright notice, |
|---|
| 10 | // this list of conditions and the following disclaimer. |
|---|
| 11 | // * Redistributions in binary form must reproduce the above copyright notice, |
|---|
| 12 | // this list of conditions and the following disclaimer in the documentation |
|---|
| 13 | // and/or other materials provided with the distribution. |
|---|
| 14 | // * Neither the name of Adobe Systems Incorporated nor the names of its |
|---|
| 15 | // contributors may be used to endorse or promote products derived from this |
|---|
| 16 | // software without specific prior written permission. |
|---|
| 17 | // |
|---|
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|---|
| 19 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 20 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 21 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|---|
| 22 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|---|
| 23 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 24 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|---|
| 26 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|---|
| 27 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|---|
| 28 | // POSSIBILITY OF SUCH DAMAGE. |
|---|
| 29 | |
|---|
| 30 | var Spry;if(!Spry)Spry={};if(!Spry.Utils)Spry.Utils={};Spry.Utils.msProgIDs=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0"];Spry.Utils.createXMLHttpRequest=function() |
|---|
| 31 | {var req=null;try |
|---|
| 32 | {if(window.ActiveXObject) |
|---|
| 33 | {while(!req&&Spry.Utils.msProgIDs.length) |
|---|
| 34 | {try{req=new ActiveXObject(Spry.Utils.msProgIDs[0]);}catch(e){req=null;} |
|---|
| 35 | if(!req) |
|---|
| 36 | Spry.Utils.msProgIDs.splice(0,1);}} |
|---|
| 37 | if(!req&&window.XMLHttpRequest) |
|---|
| 38 | req=new XMLHttpRequest();} |
|---|
| 39 | catch(e){req=null;} |
|---|
| 40 | if(!req) |
|---|
| 41 | Spry.Debug.reportError("Failed to create an XMLHttpRequest object!");return req;};Spry.Utils.loadURL=function(method,url,async,callback,opts) |
|---|
| 42 | {var req=new Spry.Utils.loadURL.Request();req.method=method;req.url=url;req.async=async;req.successCallback=callback;Spry.Utils.setOptions(req,opts);try |
|---|
| 43 | {req.xhRequest=Spry.Utils.createXMLHttpRequest();if(!req.xhRequest) |
|---|
| 44 | return null;if(req.async) |
|---|
| 45 | req.xhRequest.onreadystatechange=function(){Spry.Utils.loadURL.callback(req);};req.xhRequest.open(req.method,req.url,req.async,req.username,req.password);if(req.headers) |
|---|
| 46 | {for(var name in req.headers) |
|---|
| 47 | req.xhRequest.setRequestHeader(name,req.headers[name]);} |
|---|
| 48 | req.xhRequest.send(req.postData);if(!req.async) |
|---|
| 49 | Spry.Utils.loadURL.callback(req);} |
|---|
| 50 | catch(e) |
|---|
| 51 | {if(req.errorCallback) |
|---|
| 52 | req.errorCallback(req);else |
|---|
| 53 | Spry.Debug.reportError("Exception caught while loading "+url+": "+e);req=null;} |
|---|
| 54 | return req;};Spry.Utils.loadURL.callback=function(req) |
|---|
| 55 | {if(!req||req.xhRequest.readyState!=4) |
|---|
| 56 | return;if(req.successCallback&&(req.xhRequest.status==200||req.xhRequest.status==0)) |
|---|
| 57 | req.successCallback(req);else if(req.errorCallback) |
|---|
| 58 | req.errorCallback(req);};Spry.Utils.loadURL.Request=function() |
|---|
| 59 | {var props=Spry.Utils.loadURL.Request.props;var numProps=props.length;for(var i=0;i<numProps;i++) |
|---|
| 60 | this[props[i]]=null;this.method="GET";this.async=true;this.headers={};};Spry.Utils.loadURL.Request.props=["method","url","async","username","password","postData","successCallback","errorCallback","headers","userData","xhRequest"];Spry.Utils.loadURL.Request.prototype.extractRequestOptions=function(opts,undefineRequestProps) |
|---|
| 61 | {if(!opts) |
|---|
| 62 | return;var props=Spry.Utils.loadURL.Request.props;var numProps=props.length;for(var i=0;i<numProps;i++) |
|---|
| 63 | {var prop=props[i];if(opts[prop]!=undefined) |
|---|
| 64 | {this[prop]=opts[prop];if(undefineRequestProps) |
|---|
| 65 | opts[prop]=undefined;}}};Spry.Utils.loadURL.Request.prototype.clone=function() |
|---|
| 66 | {var props=Spry.Utils.loadURL.Request.props;var numProps=props.length;var req=new Spry.Utils.loadURL.Request;for(var i=0;i<numProps;i++) |
|---|
| 67 | req[props[i]]=this[props[i]];if(this.headers) |
|---|
| 68 | {req.headers={};Spry.Utils.setOptions(req.headers,this.headers);} |
|---|
| 69 | return req;};Spry.Utils.setInnerHTML=function(ele,str,preventScripts) |
|---|
| 70 | {if(!ele) |
|---|
| 71 | return;ele=Spry.$(ele);var scriptExpr="<script[^>]*>(.|\s|\n|\r)*?</script>";ele.innerHTML=str.replace(new RegExp(scriptExpr,"img"),"");if(preventScripts) |
|---|
| 72 | return;var matches=str.match(new RegExp(scriptExpr,"img"));if(matches) |
|---|
| 73 | {var numMatches=matches.length;for(var i=0;i<numMatches;i++) |
|---|
| 74 | {var s=matches[i].replace(/<script[^>]*>[\s\r\n]*(<\!--)?|(-->)?[\s\r\n]*<\/script>/img,"");Spry.Utils.eval(s);}}};Spry.Utils.updateContent=function(ele,url,finishFunc,opts) |
|---|
| 75 | {Spry.Utils.loadURL("GET",url,true,function(req) |
|---|
| 76 | {Spry.Utils.setInnerHTML(ele,req.xhRequest.responseText);if(finishFunc) |
|---|
| 77 | finishFunc(ele,url);},opts);};if(!Spry.$$) |
|---|
| 78 | {Spry.Utils.addEventListener=function(element,eventType,handler,capture) |
|---|
| 79 | {try |
|---|
| 80 | {element=Spry.$(element);if(element.addEventListener) |
|---|
| 81 | element.addEventListener(eventType,handler,capture);else if(element.attachEvent) |
|---|
| 82 | element.attachEvent("on"+eventType,handler);} |
|---|
| 83 | catch(e){}};Spry.Utils.removeEventListener=function(element,eventType,handler,capture) |
|---|
| 84 | {try |
|---|
| 85 | {element=Spry.$(element);if(element.removeEventListener) |
|---|
| 86 | element.removeEventListener(eventType,handler,capture);else if(element.detachEvent) |
|---|
| 87 | element.detachEvent("on"+eventType,handler);} |
|---|
| 88 | catch(e){}};Spry.Utils.addLoadListener=function(handler) |
|---|
| 89 | {if(typeof window.addEventListener!='undefined') |
|---|
| 90 | window.addEventListener('load',handler,false);else if(typeof document.addEventListener!='undefined') |
|---|
| 91 | document.addEventListener('load',handler,false);else if(typeof window.attachEvent!='undefined') |
|---|
| 92 | window.attachEvent('onload',handler);};Spry.Utils.addClassName=function(ele,className) |
|---|
| 93 | {ele=Spry.$(ele);if(!ele||!className||(ele.className&&ele.className.search(new RegExp("\\b"+className+"\\b"))!=-1)) |
|---|
| 94 | return;ele.className+=(ele.className?" ":"")+className;};Spry.Utils.removeClassName=function(ele,className) |
|---|
| 95 | {ele=Spry.$(ele);if(!ele||!className||(ele.className&&ele.className.search(new RegExp("\\b"+className+"\\b"))==-1)) |
|---|
| 96 | return;ele.className=ele.className.replace(new RegExp("\\s*\\b"+className+"\\b","g"),"");};Spry.$=function(element) |
|---|
| 97 | {if(arguments.length>1) |
|---|
| 98 | {for(var i=0,elements=[],length=arguments.length;i<length;i++) |
|---|
| 99 | elements.push(Spry.$(arguments[i]));return elements;} |
|---|
| 100 | if(typeof element=='string') |
|---|
| 101 | element=document.getElementById(element);return element;};} |
|---|
| 102 | Spry.Utils.eval=function(str) |
|---|
| 103 | {return eval(str);};Spry.Utils.escapeQuotesAndLineBreaks=function(str) |
|---|
| 104 | {if(str) |
|---|
| 105 | {str=str.replace(/\\/g,"\\\\");str=str.replace(/["']/g,"\\$&");str=str.replace(/\n/g,"\\n");str=str.replace(/\r/g,"\\r");} |
|---|
| 106 | return str;};Spry.Utils.encodeEntities=function(str) |
|---|
| 107 | {if(str&&str.search(/[&<>"]/)!=-1) |
|---|
| 108 | {str=str.replace(/&/g,"&");str=str.replace(/</g,"<");str=str.replace(/>/g,">");str=str.replace(/"/g,""");} |
|---|
| 109 | return str};Spry.Utils.decodeEntities=function(str) |
|---|
| 110 | {var d=Spry.Utils.decodeEntities.div;if(!d) |
|---|
| 111 | {d=document.createElement('div');Spry.Utils.decodeEntities.div=d;if(!d)return str;} |
|---|
| 112 | d.innerHTML=str;if(d.childNodes.length==1&&d.firstChild.nodeType==3&&d.firstChild.nextSibling==null) |
|---|
| 113 | str=d.firstChild.data;else |
|---|
| 114 | {str=str.replace(/</gi,"<");str=str.replace(/>/gi,">");str=str.replace(/"/gi,"\"");str=str.replace(/&/gi,"&");} |
|---|
| 115 | return str;};Spry.Utils.fixupIETagAttributes=function(inStr) |
|---|
| 116 | {var outStr="";var tagStart=inStr.match(/^<[^\s>]+\s*/)[0];var tagEnd=inStr.match(/\s*\/?>$/)[0];var tagAttrs=inStr.replace(/^<[^\s>]+\s*|\s*\/?>/g,"");outStr+=tagStart;if(tagAttrs) |
|---|
| 117 | {var startIndex=0;var endIndex=0;while(startIndex<tagAttrs.length) |
|---|
| 118 | {while(tagAttrs.charAt(endIndex)!='='&&endIndex<tagAttrs.length) |
|---|
| 119 | ++endIndex;if(endIndex>=tagAttrs.length) |
|---|
| 120 | {outStr+=tagAttrs.substring(startIndex,endIndex);break;} |
|---|
| 121 | ++endIndex;outStr+=tagAttrs.substring(startIndex,endIndex);startIndex=endIndex;if(tagAttrs.charAt(endIndex)=='"'||tagAttrs.charAt(endIndex)=="'") |
|---|
| 122 | {var savedIndex=endIndex++;while(endIndex<tagAttrs.length) |
|---|
| 123 | {if(tagAttrs.charAt(endIndex)==tagAttrs.charAt(savedIndex)) |
|---|
| 124 | {endIndex++;break;} |
|---|
| 125 | else if(tagAttrs.charAt(endIndex)=="\\") |
|---|
| 126 | endIndex++;endIndex++;} |
|---|
| 127 | outStr+=tagAttrs.substring(startIndex,endIndex);startIndex=endIndex;} |
|---|
| 128 | else |
|---|
| 129 | {outStr+="\"";var sIndex=tagAttrs.slice(endIndex).search(/\s/);endIndex=(sIndex!=-1)?(endIndex+sIndex):tagAttrs.length;outStr+=tagAttrs.slice(startIndex,endIndex);outStr+="\"";startIndex=endIndex;}}} |
|---|
| 130 | outStr+=tagEnd;return outStr;};Spry.Utils.fixUpIEInnerHTML=function(inStr) |
|---|
| 131 | {var outStr="";var regexp=new RegExp("<\\!--|<\\!\\[CDATA\\[|<\\w+[^<>]*>|-->|\\]\\](>|\>)","g");var searchStartIndex=0;var skipFixUp=0;while(inStr.length) |
|---|
| 132 | {var results=regexp.exec(inStr);if(!results||!results[0]) |
|---|
| 133 | {outStr+=inStr.substr(searchStartIndex,inStr.length-searchStartIndex);break;} |
|---|
| 134 | if(results.index!=searchStartIndex) |
|---|
| 135 | {outStr+=inStr.substr(searchStartIndex,results.index-searchStartIndex);} |
|---|
| 136 | if(results[0]=="<!--"||results[0]=="<![CDATA[") |
|---|
| 137 | {++skipFixUp;outStr+=results[0];} |
|---|
| 138 | else if(results[0]=="-->"||results[0]=="]]>"||(skipFixUp&&results[0]=="]]>")) |
|---|
| 139 | {--skipFixUp;outStr+=results[0];} |
|---|
| 140 | else if(!skipFixUp&&results[0].charAt(0)=='<') |
|---|
| 141 | outStr+=Spry.Utils.fixupIETagAttributes(results[0]);else |
|---|
| 142 | outStr+=results[0];searchStartIndex=regexp.lastIndex;} |
|---|
| 143 | return outStr;};Spry.Utils.stringToXMLDoc=function(str) |
|---|
| 144 | {var xmlDoc=null;try |
|---|
| 145 | {var xmlDOMObj=new ActiveXObject("Microsoft.XMLDOM");xmlDOMObj.async=false;xmlDOMObj.loadXML(str);xmlDoc=xmlDOMObj;} |
|---|
| 146 | catch(e) |
|---|
| 147 | {try |
|---|
| 148 | {var domParser=new DOMParser;xmlDoc=domParser.parseFromString(str,'text/xml');} |
|---|
| 149 | catch(e) |
|---|
| 150 | {Spry.Debug.reportError("Caught exception in Spry.Utils.stringToXMLDoc(): "+e+"\n");xmlDoc=null;}} |
|---|
| 151 | return xmlDoc;};Spry.Utils.serializeObject=function(obj) |
|---|
| 152 | {var str="";var firstItem=true;if(obj==null||obj==undefined) |
|---|
| 153 | return str+obj;var objType=typeof obj;if(objType=="number"||objType=="boolean") |
|---|
| 154 | str+=obj;else if(objType=="string") |
|---|
| 155 | str+="\""+Spry.Utils.escapeQuotesAndLineBreaks(obj)+"\"";else if(obj.constructor==Array) |
|---|
| 156 | {str+="[";for(var i=0;i<obj.length;i++) |
|---|
| 157 | {if(!firstItem) |
|---|
| 158 | str+=", ";str+=Spry.Utils.serializeObject(obj[i]);firstItem=false;} |
|---|
| 159 | str+="]";} |
|---|
| 160 | else if(objType=="object") |
|---|
| 161 | {str+="{";for(var p in obj) |
|---|
| 162 | {if(!firstItem) |
|---|
| 163 | str+=", ";str+="\""+p+"\": "+Spry.Utils.serializeObject(obj[p]);firstItem=false;} |
|---|
| 164 | str+="}";} |
|---|
| 165 | return str;};Spry.Utils.getNodesByFunc=function(root,func) |
|---|
| 166 | {var nodeStack=new Array;var resultArr=new Array;var node=root;while(node) |
|---|
| 167 | {if(func(node)) |
|---|
| 168 | resultArr.push(node);if(node.hasChildNodes()) |
|---|
| 169 | {nodeStack.push(node);node=node.firstChild;} |
|---|
| 170 | else |
|---|
| 171 | {if(node==root) |
|---|
| 172 | node=null;else |
|---|
| 173 | try{node=node.nextSibling;}catch(e){node=null;};} |
|---|
| 174 | while(!node&&nodeStack.length>0) |
|---|
| 175 | {node=nodeStack.pop();if(node==root) |
|---|
| 176 | node=null;else |
|---|
| 177 | try{node=node.nextSibling;}catch(e){node=null;}}} |
|---|
| 178 | if(nodeStack&&nodeStack.length>0) |
|---|
| 179 | Spry.Debug.trace("-- WARNING: Spry.Utils.getNodesByFunc() failed to traverse all nodes!\n");return resultArr;};Spry.Utils.getFirstChildWithNodeName=function(node,nodeName) |
|---|
| 180 | {var child=node.firstChild;while(child) |
|---|
| 181 | {if(child.nodeName==nodeName) |
|---|
| 182 | return child;child=child.nextSibling;} |
|---|
| 183 | return null;};Spry.Utils.setOptions=function(obj,optionsObj,ignoreUndefinedProps) |
|---|
| 184 | {if(!optionsObj) |
|---|
| 185 | return;for(var optionName in optionsObj) |
|---|
| 186 | {if(ignoreUndefinedProps&&optionsObj[optionName]==undefined) |
|---|
| 187 | continue;obj[optionName]=optionsObj[optionName];}};Spry.Utils.SelectionManager={};Spry.Utils.SelectionManager.selectionGroups=new Object;Spry.Utils.SelectionManager.SelectionGroup=function() |
|---|
| 188 | {this.selectedElements=new Array;};Spry.Utils.SelectionManager.SelectionGroup.prototype.select=function(element,className,multiSelect) |
|---|
| 189 | {var selObj=null;if(!multiSelect) |
|---|
| 190 | {this.clearSelection();} |
|---|
| 191 | else |
|---|
| 192 | {for(var i=0;i<this.selectedElements.length;i++) |
|---|
| 193 | {selObj=this.selectedElements[i].element;if(selObj.element==element) |
|---|
| 194 | {if(selObj.className!=className) |
|---|
| 195 | {Spry.Utils.removeClassName(element,selObj.className);Spry.Utils.addClassName(element,className);} |
|---|
| 196 | return;}}} |
|---|
| 197 | selObj=new Object;selObj.element=element;selObj.className=className;this.selectedElements.push(selObj);Spry.Utils.addClassName(element,className);};Spry.Utils.SelectionManager.SelectionGroup.prototype.unSelect=function(element) |
|---|
| 198 | {for(var i=0;i<this.selectedElements.length;i++) |
|---|
| 199 | {var selObj=this.selectedElements[i].element;if(selObj.element==element) |
|---|
| 200 | {Spry.Utils.removeClassName(selObj.element,selObj.className);return;}}};Spry.Utils.SelectionManager.SelectionGroup.prototype.clearSelection=function() |
|---|
| 201 | {var selObj=null;do |
|---|
| 202 | {selObj=this.selectedElements.shift();if(selObj) |
|---|
| 203 | Spry.Utils.removeClassName(selObj.element,selObj.className);} |
|---|
| 204 | while(selObj);};Spry.Utils.SelectionManager.getSelectionGroup=function(selectionGroupName) |
|---|
| 205 | {if(!selectionGroupName) |
|---|
| 206 | return null;var groupObj=Spry.Utils.SelectionManager.selectionGroups[selectionGroupName];if(!groupObj) |
|---|
| 207 | {groupObj=new Spry.Utils.SelectionManager.SelectionGroup();Spry.Utils.SelectionManager.selectionGroups[selectionGroupName]=groupObj;} |
|---|
| 208 | return groupObj;};Spry.Utils.SelectionManager.select=function(selectionGroupName,element,className,multiSelect) |
|---|
| 209 | {var groupObj=Spry.Utils.SelectionManager.getSelectionGroup(selectionGroupName);if(!groupObj) |
|---|
| 210 | return;groupObj.select(element,className,multiSelect);};Spry.Utils.SelectionManager.unSelect=function(selectionGroupName,element) |
|---|
| 211 | {var groupObj=Spry.Utils.SelectionManager.getSelectionGroup(selectionGroupName);if(!groupObj) |
|---|
| 212 | return;groupObj.unSelect(element,className);};Spry.Utils.SelectionManager.clearSelection=function(selectionGroupName) |
|---|
| 213 | {var groupObj=Spry.Utils.SelectionManager.getSelectionGroup(selectionGroupName);if(!groupObj) |
|---|
| 214 | return;groupObj.clearSelection();};Spry.Utils.Notifier=function() |
|---|
| 215 | {this.observers=[];this.suppressNotifications=0;};Spry.Utils.Notifier.prototype.addObserver=function(observer) |
|---|
| 216 | {if(!observer) |
|---|
| 217 | return;var len=this.observers.length;for(var i=0;i<len;i++) |
|---|
| 218 | {if(this.observers[i]==observer) |
|---|
| 219 | return;} |
|---|
| 220 | this.observers[len]=observer;};Spry.Utils.Notifier.prototype.removeObserver=function(observer) |
|---|
| 221 | {if(!observer) |
|---|
| 222 | return;for(var i=0;i<this.observers.length;i++) |
|---|
| 223 | {if(this.observers[i]==observer) |
|---|
| 224 | {this.observers.splice(i,1);break;}}};Spry.Utils.Notifier.prototype.notifyObservers=function(methodName,data) |
|---|
| 225 | {if(!methodName) |
|---|
| 226 | return;if(!this.suppressNotifications) |
|---|
| 227 | {var len=this.observers.length;for(var i=0;i<len;i++) |
|---|
| 228 | {var obs=this.observers[i];if(obs) |
|---|
| 229 | {if(typeof obs=="function") |
|---|
| 230 | obs(methodName,this,data);else if(obs[methodName]) |
|---|
| 231 | obs[methodName](this,data);}}}};Spry.Utils.Notifier.prototype.enableNotifications=function() |
|---|
| 232 | {if(--this.suppressNotifications<0) |
|---|
| 233 | {this.suppressNotifications=0;Spry.Debug.reportError("Unbalanced enableNotifications() call!\n");}};Spry.Utils.Notifier.prototype.disableNotifications=function() |
|---|
| 234 | {++this.suppressNotifications;};Spry.Debug={};Spry.Debug.enableTrace=true;Spry.Debug.debugWindow=null;Spry.Debug.onloadDidFire=false;Spry.Utils.addLoadListener(function(){Spry.Debug.onloadDidFire=true;Spry.Debug.flushQueuedMessages();});Spry.Debug.flushQueuedMessages=function() |
|---|
| 235 | {if(Spry.Debug.flushQueuedMessages.msgs) |
|---|
| 236 | {var msgs=Spry.Debug.flushQueuedMessages.msgs;for(var i=0;i<msgs.length;i++) |
|---|
| 237 | Spry.Debug.debugOut(msgs[i].msg,msgs[i].color);Spry.Debug.flushQueuedMessages.msgs=null;}};Spry.Debug.createDebugWindow=function() |
|---|
| 238 | {if(!Spry.Debug.enableTrace||Spry.Debug.debugWindow||!Spry.Debug.onloadDidFire) |
|---|
| 239 | return;try |
|---|
| 240 | {Spry.Debug.debugWindow=document.createElement("div");var div=Spry.Debug.debugWindow;div.style.fontSize="12px";div.style.fontFamily="console";div.style.position="absolute";div.style.width="400px";div.style.height="300px";div.style.overflow="auto";div.style.border="solid 1px black";div.style.backgroundColor="white";div.style.color="black";div.style.bottom="0px";div.style.right="0px";div.setAttribute("id","SpryDebugWindow");document.body.appendChild(Spry.Debug.debugWindow);} |
|---|
| 241 | catch(e){}};Spry.Debug.debugOut=function(str,bgColor) |
|---|
| 242 | {if(!Spry.Debug.debugWindow) |
|---|
| 243 | {Spry.Debug.createDebugWindow();if(!Spry.Debug.debugWindow) |
|---|
| 244 | {if(!Spry.Debug.flushQueuedMessages.msgs) |
|---|
| 245 | Spry.Debug.flushQueuedMessages.msgs=new Array;Spry.Debug.flushQueuedMessages.msgs.push({msg:str,color:bgColor});return;}} |
|---|
| 246 | var d=document.createElement("div");if(bgColor) |
|---|
| 247 | d.style.backgroundColor=bgColor;d.innerHTML=str;Spry.Debug.debugWindow.appendChild(d);};Spry.Debug.trace=function(str) |
|---|
| 248 | {Spry.Debug.debugOut(str);};Spry.Debug.reportError=function(str) |
|---|
| 249 | {Spry.Debug.debugOut(str,"red");};Spry.Data={};Spry.Data.regionsArray={};Spry.Data.initRegionsOnLoad=true;Spry.Data.initRegions=function(rootNode) |
|---|
| 250 | {rootNode=rootNode?Spry.$(rootNode):document.body;var lastRegionFound=null;var regions=Spry.Utils.getNodesByFunc(rootNode,function(node) |
|---|
| 251 | {try |
|---|
| 252 | {if(node.nodeType!=1) |
|---|
| 253 | return false;var attrName="spry:region";var attr=node.attributes.getNamedItem(attrName);if(!attr) |
|---|
| 254 | {attrName="spry:detailregion";attr=node.attributes.getNamedItem(attrName);} |
|---|
| 255 | if(attr) |
|---|
| 256 | {if(lastRegionFound) |
|---|
| 257 | {var parent=node.parentNode;while(parent) |
|---|
| 258 | {if(parent==lastRegionFound) |
|---|
| 259 | {Spry.Debug.reportError("Found a nested "+attrName+" in the following markup. Nested regions are currently not supported.<br/><pre>"+Spry.Utils.encodeEntities(parent.innerHTML)+"</pre>");return false;} |
|---|
| 260 | parent=parent.parentNode;}} |
|---|
| 261 | if(attr.value) |
|---|
| 262 | {attr=node.attributes.getNamedItem("id");if(!attr||!attr.value) |
|---|
| 263 | {node.setAttribute("id","spryregion"+(++Spry.Data.initRegions.nextUniqueRegionID));} |
|---|
| 264 | lastRegionFound=node;return true;} |
|---|
| 265 | else |
|---|
| 266 | Spry.Debug.reportError(attrName+" attributes require one or more data set names as values!");}} |
|---|
| 267 | catch(e){} |
|---|
| 268 | return false;});var name,dataSets,i;var newRegions=[];for(i=0;i<regions.length;i++) |
|---|
| 269 | {var rgn=regions[i];var isDetailRegion=false;name=rgn.attributes.getNamedItem("id").value;attr=rgn.attributes.getNamedItem("spry:region");if(!attr) |
|---|
| 270 | {attr=rgn.attributes.getNamedItem("spry:detailregion");isDetailRegion=true;} |
|---|
| 271 | if(!attr.value) |
|---|
| 272 | {Spry.Debug.reportError("spry:region and spry:detailregion attributes require one or more data set names as values!");continue;} |
|---|
| 273 | rgn.attributes.removeNamedItem(attr.nodeName);Spry.Utils.removeClassName(rgn,Spry.Data.Region.hiddenRegionClassName);dataSets=Spry.Data.Region.strToDataSetsArray(attr.value);if(!dataSets.length) |
|---|
| 274 | {Spry.Debug.reportError("spry:region or spry:detailregion attribute has no data set!");continue;} |
|---|
| 275 | var hasBehaviorAttributes=false;var hasSpryContent=false;var dataStr="";var parent=null;var regionStates={};var regionStateMap={};attr=rgn.attributes.getNamedItem("spry:readystate");if(attr&&attr.value) |
|---|
| 276 | regionStateMap["ready"]=attr.value;attr=rgn.attributes.getNamedItem("spry:errorstate");if(attr&&attr.value) |
|---|
| 277 | regionStateMap["error"]=attr.value;attr=rgn.attributes.getNamedItem("spry:loadingstate");if(attr&&attr.value) |
|---|
| 278 | regionStateMap["loading"]=attr.value;attr=rgn.attributes.getNamedItem("spry:expiredstate");if(attr&&attr.value) |
|---|
| 279 | regionStateMap["expired"]=attr.value;var piRegions=Spry.Utils.getNodesByFunc(rgn,function(node) |
|---|
| 280 | {try |
|---|
| 281 | {if(node.nodeType==1) |
|---|
| 282 | {var attributes=node.attributes;var numPI=Spry.Data.Region.PI.orderedInstructions.length;var lastStartComment=null;var lastEndComment=null;for(var i=0;i<numPI;i++) |
|---|
| 283 | {var piName=Spry.Data.Region.PI.orderedInstructions[i];var attr=attributes.getNamedItem(piName);if(!attr) |
|---|
| 284 | continue;var piDesc=Spry.Data.Region.PI.instructions[piName];var childrenOnly=(node==rgn)?true:piDesc.childrenOnly;var openTag=piDesc.getOpenTag(node,piName);var closeTag=piDesc.getCloseTag(node,piName);if(childrenOnly) |
|---|
| 285 | {var oComment=document.createComment(openTag);var cComment=document.createComment(closeTag);if(!lastStartComment) |
|---|
| 286 | node.insertBefore(oComment,node.firstChild);else |
|---|
| 287 | node.insertBefore(oComment,lastStartComment.nextSibling);lastStartComment=oComment;if(!lastEndComment) |
|---|
| 288 | node.appendChild(cComment);else |
|---|
| 289 | node.insertBefore(cComment,lastEndComment);lastEndComment=cComment;} |
|---|
| 290 | else |
|---|
| 291 | {var parent=node.parentNode;parent.insertBefore(document.createComment(openTag),node);parent.insertBefore(document.createComment(closeTag),node.nextSibling);} |
|---|
| 292 | if(piName=="spry:state") |
|---|
| 293 | regionStates[attr.value]=true;node.removeAttribute(piName);} |
|---|
| 294 | if(Spry.Data.Region.enableBehaviorAttributes) |
|---|
| 295 | {var bAttrs=Spry.Data.Region.behaviorAttrs;for(var behaviorAttrName in bAttrs) |
|---|
| 296 | {var bAttr=attributes.getNamedItem(behaviorAttrName);if(bAttr) |
|---|
| 297 | {hasBehaviorAttributes=true;if(bAttrs[behaviorAttrName].setup) |
|---|
| 298 | bAttrs[behaviorAttrName].setup(node,bAttr.value);}}}}} |
|---|
| 299 | catch(e){} |
|---|
| 300 | return false;});dataStr=rgn.innerHTML;if(window.ActiveXObject&&!Spry.Data.Region.disableIEInnerHTMLFixUp&&dataStr.search(/=\{/)!=-1) |
|---|
| 301 | {if(Spry.Data.Region.debug) |
|---|
| 302 | Spry.Debug.trace("<hr />Performing IE innerHTML fix up of Region: "+name+"<br /><br />"+Spry.Utils.encodeEntities(dataStr));dataStr=Spry.Utils.fixUpIEInnerHTML(dataStr);} |
|---|
| 303 | if(Spry.Data.Region.debug) |
|---|
| 304 | Spry.Debug.trace("<hr />Region template markup for '"+name+"':<br /><br />"+Spry.Utils.encodeEntities(dataStr));if(!hasSpryContent) |
|---|
| 305 | {rgn.innerHTML="";} |
|---|
| 306 | var region=new Spry.Data.Region(rgn,name,isDetailRegion,dataStr,dataSets,regionStates,regionStateMap,hasBehaviorAttributes);Spry.Data.regionsArray[region.name]=region;newRegions.push(region);} |
|---|
| 307 | for(var i=0;i<newRegions.length;i++) |
|---|
| 308 | newRegions[i].updateContent();};Spry.Data.initRegions.nextUniqueRegionID=0;Spry.Data.updateRegion=function(regionName) |
|---|
| 309 | {if(!regionName||!Spry.Data.regionsArray||!Spry.Data.regionsArray[regionName]) |
|---|
| 310 | return;try{Spry.Data.regionsArray[regionName].updateContent();} |
|---|
| 311 | catch(e){Spry.Debug.reportError("Spry.Data.updateRegion("+regionName+") caught an exception: "+e+"\n");}};Spry.Data.getRegion=function(regionName) |
|---|
| 312 | {return Spry.Data.regionsArray[regionName];};Spry.Data.updateAllRegions=function() |
|---|
| 313 | {if(!Spry.Data.regionsArray) |
|---|
| 314 | return;for(var regionName in Spry.Data.regionsArray) |
|---|
| 315 | Spry.Data.updateRegion(regionName);};Spry.Data.getDataSetByName=function(dataSetName) |
|---|
| 316 | {var ds=window[dataSetName];if(typeof ds!="object"||!ds.getData||!ds.filter) |
|---|
| 317 | return null;return ds;};Spry.Data.DataSet=function(options) |
|---|
| 318 | {Spry.Utils.Notifier.call(this);this.name="";this.internalID=Spry.Data.DataSet.nextDataSetID++;this.curRowID=0;this.data=[];this.unfilteredData=null;this.dataHash={};this.columnTypes={};this.filterFunc=null;this.filterDataFunc=null;this.distinctOnLoad=false;this.distinctFieldsOnLoad=null;this.sortOnLoad=null;this.sortOrderOnLoad="ascending";this.keepSorted=false;this.dataWasLoaded=false;this.pendingRequest=null;this.lastSortColumns=[];this.lastSortOrder="";this.loadIntervalID=0;Spry.Utils.setOptions(this,options);};Spry.Data.DataSet.prototype=new Spry.Utils.Notifier();Spry.Data.DataSet.prototype.constructor=Spry.Data.DataSet;Spry.Data.DataSet.prototype.getData=function(unfiltered) |
|---|
| 319 | {return(unfiltered&&this.unfilteredData)?this.unfilteredData:this.data;};Spry.Data.DataSet.prototype.getUnfilteredData=function() |
|---|
| 320 | {return this.getData(true);};Spry.Data.DataSet.prototype.getLoadDataRequestIsPending=function() |
|---|
| 321 | {return this.pendingRequest!=null;};Spry.Data.DataSet.prototype.getDataWasLoaded=function() |
|---|
| 322 | {return this.dataWasLoaded;};Spry.Data.DataSet.prototype.setDataFromArray=function(arr,fireSyncLoad) |
|---|
| 323 | {this.notifyObservers("onPreLoad");this.unfilteredData=null;this.filteredData=null;this.data=[];this.dataHash={};var arrLen=arr.length;for(var i=0;i<arrLen;i++) |
|---|
| 324 | {var row=arr[i];if(row.ds_RowID==undefined) |
|---|
| 325 | row.ds_RowID=i;this.dataHash[row.ds_RowID]=row;this.data.push(row);} |
|---|
| 326 | this.loadData(fireSyncLoad);};Spry.Data.DataSet.prototype.loadData=function(syncLoad) |
|---|
| 327 | {var self=this;this.pendingRequest=new Object;this.dataWasLoaded=false;var loadCallbackFunc=function() |
|---|
| 328 | {self.pendingRequest=null;self.dataWasLoaded=true;self.applyColumnTypes();self.disableNotifications();self.filterAndSortData();self.enableNotifications();self.notifyObservers("onPostLoad");self.notifyObservers("onDataChanged");};if(syncLoad) |
|---|
| 329 | loadCallbackFunc();else |
|---|
| 330 | this.pendingRequest.timer=setTimeout(loadCallbackFunc,0);};Spry.Data.DataSet.prototype.filterAndSortData=function() |
|---|
| 331 | {if(this.filterDataFunc) |
|---|
| 332 | this.filterData(this.filterDataFunc,true);if(this.distinctOnLoad) |
|---|
| 333 | this.distinct(this.distinctFieldsOnLoad);if(this.keepSorted&&this.getSortColumn()) |
|---|
| 334 | this.sort(this.lastSortColumns,this.lastSortOrder);else if(this.sortOnLoad) |
|---|
| 335 | this.sort(this.sortOnLoad,this.sortOrderOnLoad);if(this.filterFunc) |
|---|
| 336 | this.filter(this.filterFunc,true);if(this.data&&this.data.length>0) |
|---|
| 337 | this.curRowID=this.data[0]['ds_RowID'];else |
|---|
| 338 | this.curRowID=0;};Spry.Data.DataSet.prototype.cancelLoadData=function() |
|---|
| 339 | {if(this.pendingRequest&&this.pendingRequest.timer) |
|---|
| 340 | clearTimeout(this.pendingRequest.timer);this.pendingRequest=null;};Spry.Data.DataSet.prototype.getRowCount=function(unfiltered) |
|---|
| 341 | {var rows=this.getData(unfiltered);return rows?rows.length:0;};Spry.Data.DataSet.prototype.getRowByID=function(rowID) |
|---|
| 342 | {if(!this.data) |
|---|
| 343 | return null;return this.dataHash[rowID];};Spry.Data.DataSet.prototype.getRowByRowNumber=function(rowNumber,unfiltered) |
|---|
| 344 | {var rows=this.getData(unfiltered);if(rows&&rowNumber>=0&&rowNumber<rows.length) |
|---|
| 345 | return rows[rowNumber];return null;};Spry.Data.DataSet.prototype.getCurrentRow=function() |
|---|
| 346 | {return this.getRowByID(this.curRowID);};Spry.Data.DataSet.prototype.setCurrentRow=function(rowID) |
|---|
| 347 | {if(this.curRowID==rowID) |
|---|
| 348 | return;var nData={oldRowID:this.curRowID,newRowID:rowID};this.curRowID=rowID;this.notifyObservers("onCurrentRowChanged",nData);};Spry.Data.DataSet.prototype.getRowNumber=function(row,unfiltered) |
|---|
| 349 | {if(row) |
|---|
| 350 | {var rows=this.getData(unfiltered);if(rows&&rows.length) |
|---|
| 351 | {var numRows=rows.length;for(var i=0;i<numRows;i++) |
|---|
| 352 | {if(rows[i]==row) |
|---|
| 353 | return i;}}} |
|---|
| 354 | return-1;};Spry.Data.DataSet.prototype.getCurrentRowNumber=function() |
|---|
| 355 | {return this.getRowNumber(this.getCurrentRow());};Spry.Data.DataSet.prototype.getCurrentRowID=function() |
|---|
| 356 | {return this.curRowID;};Spry.Data.DataSet.prototype.setCurrentRowNumber=function(rowNumber) |
|---|
| 357 | {if(!this.data||rowNumber>=this.data.length) |
|---|
| 358 | {Spry.Debug.trace("Invalid row number: "+rowNumber+"\n");return;} |
|---|
| 359 | var rowID=this.data[rowNumber]["ds_RowID"];if(rowID==undefined||this.curRowID==rowID) |
|---|
| 360 | return;this.setCurrentRow(rowID);};Spry.Data.DataSet.prototype.findRowsWithColumnValues=function(valueObj,firstMatchOnly,unfiltered) |
|---|
| 361 | {var results=[];var rows=this.getData(unfiltered);if(rows) |
|---|
| 362 | {var numRows=rows.length;for(var i=0;i<numRows;i++) |
|---|
| 363 | {var row=rows[i];var matched=true;for(var colName in valueObj) |
|---|
| 364 | {if(valueObj[colName]!=row[colName]) |
|---|
| 365 | {matched=false;break;}} |
|---|
| 366 | if(matched) |
|---|
| 367 | {if(firstMatchOnly) |
|---|
| 368 | return row;results.push(row);}}} |
|---|
| 369 | return firstMatchOnly?null:results;};Spry.Data.DataSet.prototype.setColumnType=function(columnNames,columnType) |
|---|
| 370 | {if(columnNames) |
|---|
| 371 | {if(typeof columnNames=="string") |
|---|
| 372 | columnNames=[columnNames];for(var i=0;i<columnNames.length;i++) |
|---|
| 373 | this.columnTypes[columnNames[i]]=columnType;}};Spry.Data.DataSet.prototype.getColumnType=function(columnName) |
|---|
| 374 | {if(this.columnTypes[columnName]) |
|---|
| 375 | return this.columnTypes[columnName];return"string";};Spry.Data.DataSet.prototype.applyColumnTypes=function() |
|---|
| 376 | {var rows=this.getData(true);var numRows=rows.length;var colNames=[];if(numRows<1) |
|---|
| 377 | return;for(var cname in this.columnTypes) |
|---|
| 378 | {var ctype=this.columnTypes[cname];if(ctype!="string") |
|---|
| 379 | {for(var i=0;i<numRows;i++) |
|---|
| 380 | {var row=rows[i];var val=row[cname];if(val!=undefined) |
|---|
| 381 | {if(ctype=="number") |
|---|
| 382 | row[cname]=new Number(val);else if(ctype=="html") |
|---|
| 383 | row[cname]=Spry.Utils.decodeEntities(val);}}}}};Spry.Data.DataSet.prototype.distinct=function(columnNames) |
|---|
| 384 | {if(this.data) |
|---|
| 385 | {var oldData=this.data;this.data=[];this.dataHash={};var dataChanged=false;var alreadySeenHash={};var i=0;var keys=[];if(typeof columnNames=="string") |
|---|
| 386 | keys=[columnNames];else if(columnNames) |
|---|
| 387 | keys=columnNames;else |
|---|
| 388 | for(var recField in oldData[0]) |
|---|
| 389 | keys[i++]=recField;for(var i=0;i<oldData.length;i++) |
|---|
| 390 | {var rec=oldData[i];var hashStr="";for(var j=0;j<keys.length;j++) |
|---|
| 391 | {recField=keys[j];if(recField!="ds_RowID") |
|---|
| 392 | {if(hashStr) |
|---|
| 393 | hashStr+=",";hashStr+=recField+":"+"\""+rec[recField]+"\"";}} |
|---|
| 394 | if(!alreadySeenHash[hashStr]) |
|---|
| 395 | {this.data.push(rec);this.dataHash[rec['ds_RowID']]=rec;alreadySeenHash[hashStr]=true;} |
|---|
| 396 | else |
|---|
| 397 | dataChanged=true;} |
|---|
| 398 | if(dataChanged) |
|---|
| 399 | this.notifyObservers('onDataChanged');}};Spry.Data.DataSet.prototype.getSortColumn=function(){return(this.lastSortColumns&&this.lastSortColumns.length>0)?this.lastSortColumns[0]:"";};Spry.Data.DataSet.prototype.getSortOrder=function(){return this.lastSortOrder?this.lastSortOrder:"";};Spry.Data.DataSet.prototype.sort=function(columnNames,sortOrder) |
|---|
| 400 | {if(!columnNames) |
|---|
| 401 | return;if(typeof columnNames=="string") |
|---|
| 402 | columnNames=[columnNames,"ds_RowID"];else if(columnNames.length<2&&columnNames[0]!="ds_RowID") |
|---|
| 403 | columnNames.push("ds_RowID");if(!sortOrder) |
|---|
| 404 | sortOrder="toggle";if(sortOrder=="toggle") |
|---|
| 405 | {if(this.lastSortColumns.length>0&&this.lastSortColumns[0]==columnNames[0]&&this.lastSortOrder=="ascending") |
|---|
| 406 | sortOrder="descending";else |
|---|
| 407 | sortOrder="ascending";} |
|---|
| 408 | if(sortOrder!="ascending"&&sortOrder!="descending") |
|---|
| 409 | {Spry.Debug.reportError("Invalid sort order type specified: "+sortOrder+"\n");return;} |
|---|
| 410 | var nData={oldSortColumns:this.lastSortColumns,oldSortOrder:this.lastSortOrder,newSortColumns:columnNames,newSortOrder:sortOrder};this.notifyObservers("onPreSort",nData);var cname=columnNames[columnNames.length-1];var sortfunc=Spry.Data.DataSet.prototype.sort.getSortFunc(cname,this.getColumnType(cname),sortOrder);for(var i=columnNames.length-2;i>=0;i--) |
|---|
| 411 | {cname=columnNames[i];sortfunc=Spry.Data.DataSet.prototype.sort.buildSecondarySortFunc(Spry.Data.DataSet.prototype.sort.getSortFunc(cname,this.getColumnType(cname),sortOrder),sortfunc);} |
|---|
| 412 | if(this.unfilteredData) |
|---|
| 413 | {this.unfilteredData.sort(sortfunc);if(this.filterFunc) |
|---|
| 414 | this.filter(this.filterFunc,true);} |
|---|
| 415 | else |
|---|
| 416 | this.data.sort(sortfunc);this.lastSortColumns=columnNames.slice(0);this.lastSortOrder=sortOrder;this.notifyObservers("onPostSort",nData);};Spry.Data.DataSet.prototype.sort.getSortFunc=function(prop,type,order) |
|---|
| 417 | {var sortfunc=null;if(type=="number") |
|---|
| 418 | {if(order=="ascending") |
|---|
| 419 | sortfunc=function(a,b) |
|---|
| 420 | {a=a[prop];b=b[prop];if(a==undefined||b==undefined) |
|---|
| 421 | return(a==b)?0:(a?1:-1);return a-b;};else |
|---|
| 422 | sortfunc=function(a,b) |
|---|
| 423 | {a=a[prop];b=b[prop];if(a==undefined||b==undefined) |
|---|
| 424 | return(a==b)?0:(a?-1:1);return b-a;};} |
|---|
| 425 | else if(type=="date") |
|---|
| 426 | {if(order=="ascending") |
|---|
| 427 | sortfunc=function(a,b) |
|---|
| 428 | {var dA=a[prop];var dB=b[prop];dA=dA?(new Date(dA)):0;dB=dB?(new Date(dB)):0;return dA-dB;};else |
|---|
| 429 | sortfunc=function(a,b) |
|---|
| 430 | {var dA=a[prop];var dB=b[prop];dA=dA?(new Date(dA)):0;dB=dB?(new Date(dB)):0;return dB-dA;};} |
|---|
| 431 | else |
|---|
| 432 | {if(order=="ascending") |
|---|
| 433 | sortfunc=function(a,b){a=a[prop];b=b[prop];if(a==undefined||b==undefined) |
|---|
| 434 | return(a==b)?0:(a?1:-1);var tA=a.toString();var tB=b.toString();var tA_l=tA.toLowerCase();var tB_l=tB.toLowerCase();var min_len=tA.length>tB.length?tB.length:tA.length;for(var i=0;i<min_len;i++) |
|---|
| 435 | {var a_l_c=tA_l.charAt(i);var b_l_c=tB_l.charAt(i);var a_c=tA.charAt(i);var b_c=tB.charAt(i);if(a_l_c>b_l_c) |
|---|
| 436 | return 1;else if(a_l_c<b_l_c) |
|---|
| 437 | return-1;else if(a_c>b_c) |
|---|
| 438 | return 1;else if(a_c<b_c) |
|---|
| 439 | return-1;} |
|---|
| 440 | if(tA.length==tB.length) |
|---|
| 441 | return 0;else if(tA.length>tB.length) |
|---|
| 442 | return 1;return-1;};else |
|---|
| 443 | sortfunc=function(a,b){a=a[prop];b=b[prop];if(a==undefined||b==undefined) |
|---|
| 444 | return(a==b)?0:(a?-1:1);var tA=a.toString();var tB=b.toString();var tA_l=tA.toLowerCase();var tB_l=tB.toLowerCase();var min_len=tA.length>tB.length?tB.length:tA.length;for(var i=0;i<min_len;i++) |
|---|
| 445 | {var a_l_c=tA_l.charAt(i);var b_l_c=tB_l.charAt(i);var a_c=tA.charAt(i);var b_c=tB.charAt(i);if(a_l_c>b_l_c) |
|---|
| 446 | return-1;else if(a_l_c<b_l_c) |
|---|
| 447 | return 1;else if(a_c>b_c) |
|---|
| 448 | return-1;else if(a_c<b_c) |
|---|
| 449 | return 1;} |
|---|
| 450 | if(tA.length==tB.length) |
|---|
| 451 | return 0;else if(tA.length>tB.length) |
|---|
| 452 | return-1;return 1;};} |
|---|
| 453 | return sortfunc;};Spry.Data.DataSet.prototype.sort.buildSecondarySortFunc=function(funcA,funcB) |
|---|
| 454 | {return function(a,b) |
|---|
| 455 | {var ret=funcA(a,b);if(ret==0) |
|---|
| 456 | ret=funcB(a,b);return ret;};};Spry.Data.DataSet.prototype.filterData=function(filterFunc,filterOnly) |
|---|
| 457 | {var dataChanged=false;if(!filterFunc) |
|---|
| 458 | {this.filterDataFunc=null;dataChanged=true;} |
|---|
| 459 | else |
|---|
| 460 | {this.filterDataFunc=filterFunc;if(this.dataWasLoaded&&((this.unfilteredData&&this.unfilteredData.length)||(this.data&&this.data.length))) |
|---|
| 461 | {if(this.unfilteredData) |
|---|
| 462 | {this.data=this.unfilteredData;this.unfilteredData=null;} |
|---|
| 463 | var oldData=this.data;this.data=[];this.dataHash={};for(var i=0;i<oldData.length;i++) |
|---|
| 464 | {var newRow=filterFunc(this,oldData[i],i);if(newRow) |
|---|
| 465 | {this.data.push(newRow);this.dataHash[newRow["ds_RowID"]]=newRow;}} |
|---|
| 466 | dataChanged=true;}} |
|---|
| 467 | if(dataChanged) |
|---|
| 468 | {if(!filterOnly) |
|---|
| 469 | {this.disableNotifications();if(this.filterFunc) |
|---|
| 470 | this.filter(this.filterFunc,true);this.enableNotifications();} |
|---|
| 471 | this.notifyObservers("onDataChanged");}};Spry.Data.DataSet.prototype.filter=function(filterFunc,filterOnly) |
|---|
| 472 | {var dataChanged=false;if(!filterFunc) |
|---|
| 473 | {if(this.filterFunc&&this.unfilteredData) |
|---|
| 474 | {this.data=this.unfilteredData;this.unfilteredData=null;this.filterFunc=null;dataChanged=true;}} |
|---|
| 475 | else |
|---|
| 476 | {this.filterFunc=filterFunc;if(this.dataWasLoaded&&(this.unfilteredData||(this.data&&this.data.length))) |
|---|
| 477 | {if(!this.unfilteredData) |
|---|
| 478 | this.unfilteredData=this.data;var udata=this.unfilteredData;this.data=[];for(var i=0;i<udata.length;i++) |
|---|
| 479 | {var newRow=filterFunc(this,udata[i],i);if(newRow) |
|---|
| 480 | this.data.push(newRow);} |
|---|
| 481 | dataChanged=true;}} |
|---|
| 482 | if(dataChanged) |
|---|
| 483 | this.notifyObservers("onDataChanged");};Spry.Data.DataSet.prototype.startLoadInterval=function(interval) |
|---|
| 484 | {this.stopLoadInterval();if(interval>0) |
|---|
| 485 | {var self=this;this.loadInterval=interval;this.loadIntervalID=setInterval(function(){self.loadData();},interval);}};Spry.Data.DataSet.prototype.stopLoadInterval=function() |
|---|
| 486 | {if(this.loadIntervalID) |
|---|
| 487 | clearInterval(this.loadIntervalID);this.loadInterval=0;this.loadIntervalID=null;};Spry.Data.DataSet.nextDataSetID=0;Spry.Data.HTTPSourceDataSet=function(dataSetURL,dataSetOptions) |
|---|
| 488 | {Spry.Data.DataSet.call(this);this.url=dataSetURL;this.dataSetsForDataRefStrings=new Array;this.hasDataRefStrings=false;this.useCache=true;this.setRequestInfo(dataSetOptions,true);Spry.Utils.setOptions(this,dataSetOptions,true);this.recalculateDataSetDependencies();if(this.loadInterval>0) |
|---|
| 489 | this.startLoadInterval(this.loadInterval);};Spry.Data.HTTPSourceDataSet.prototype=new Spry.Data.DataSet();Spry.Data.HTTPSourceDataSet.prototype.constructor=Spry.Data.HTTPSourceDataSet;Spry.Data.HTTPSourceDataSet.prototype.setRequestInfo=function(requestInfo,undefineRequestProps) |
|---|
| 490 | {this.requestInfo=new Spry.Utils.loadURL.Request();this.requestInfo.extractRequestOptions(requestInfo,undefineRequestProps);if(this.requestInfo.method=="POST") |
|---|
| 491 | {if(!this.requestInfo.headers) |
|---|
| 492 | this.requestInfo.headers={};if(!this.requestInfo.headers['Content-Type']) |
|---|
| 493 | this.requestInfo.headers['Content-Type']="application/x-www-form-urlencoded; charset=UTF-8";}};Spry.Data.HTTPSourceDataSet.prototype.recalculateDataSetDependencies=function() |
|---|
| 494 | {this.hasDataRefStrings=false;var i=0;for(i=0;i<this.dataSetsForDataRefStrings.length;i++) |
|---|
| 495 | {var ds=this.dataSetsForDataRefStrings[i];if(ds) |
|---|
| 496 | ds.removeObserver(this);} |
|---|
| 497 | this.dataSetsForDataRefStrings=new Array();var regionStrs=this.getDataRefStrings();var dsCount=0;for(var n=0;n<regionStrs.length;n++) |
|---|
| 498 | {var tokens=Spry.Data.Region.getTokensFromStr(regionStrs[n]);for(i=0;tokens&&i<tokens.length;i++) |
|---|
| 499 | {if(tokens[i].search(/{[^}:]+::[^}]+}/)!=-1) |
|---|
| 500 | {var dsName=tokens[i].replace(/^\{|::.*\}/g,"");var ds=null;if(!this.dataSetsForDataRefStrings[dsName]) |
|---|
| 501 | {ds=Spry.Data.getDataSetByName(dsName);if(dsName&&ds) |
|---|
| 502 | {this.dataSetsForDataRefStrings[dsName]=ds;this.dataSetsForDataRefStrings[dsCount++]=ds;this.hasDataRefStrings=true;}}}}} |
|---|
| 503 | for(i=0;i<this.dataSetsForDataRefStrings.length;i++) |
|---|
| 504 | {var ds=this.dataSetsForDataRefStrings[i];ds.addObserver(this);}};Spry.Data.HTTPSourceDataSet.prototype.getDataRefStrings=function() |
|---|
| 505 | {var strArr=[];if(this.url)strArr.push(this.url);if(this.requestInfo&&this.requestInfo.postData)strArr.push(this.requestInfo.postData);return strArr;};Spry.Data.HTTPSourceDataSet.prototype.attemptLoadData=function() |
|---|
| 506 | {for(var i=0;i<this.dataSetsForDataRefStrings.length;i++) |
|---|
| 507 | {var ds=this.dataSetsForDataRefStrings[i];if(ds.getLoadDataRequestIsPending()||!ds.getDataWasLoaded()) |
|---|
| 508 | return;} |
|---|
| 509 | this.loadData();};Spry.Data.HTTPSourceDataSet.prototype.onCurrentRowChanged=function(ds,data) |
|---|
| 510 | {this.attemptLoadData();};Spry.Data.HTTPSourceDataSet.prototype.onPostSort=function(ds,data) |
|---|
| 511 | {this.attemptLoadData();};Spry.Data.HTTPSourceDataSet.prototype.onDataChanged=function(ds,data) |
|---|
| 512 | {this.attemptLoadData();};Spry.Data.HTTPSourceDataSet.prototype.loadData=function() |
|---|
| 513 | {if(!this.url) |
|---|
| 514 | return;this.cancelLoadData();var url=this.url;var postData=this.requestInfo.postData;if(this.hasDataRefStrings) |
|---|
| 515 | {var allDataSetsReady=true;for(var i=0;i<this.dataSetsForDataRefStrings.length;i++) |
|---|
| 516 | {var ds=this.dataSetsForDataRefStrings[i];if(ds.getLoadDataRequestIsPending()) |
|---|
| 517 | allDataSetsReady=false;else if(!ds.getDataWasLoaded()) |
|---|
| 518 | {ds.loadData();allDataSetsReady=false;}} |
|---|
| 519 | if(!allDataSetsReady) |
|---|
| 520 | return;url=Spry.Data.Region.processDataRefString(null,this.url,this.dataSetsForDataRefStrings);if(!url) |
|---|
| 521 | return;if(postData&&(typeof postData)=="string") |
|---|
| 522 | postData=Spry.Data.Region.processDataRefString(null,postData,this.dataSetsForDataRefStrings);} |
|---|
| 523 | this.notifyObservers("onPreLoad");this.data=null;this.dataWasLoaded=false;this.unfilteredData=null;this.dataHash=null;this.curRowID=0;var req=this.requestInfo.clone();req.url=url;req.postData=postData;this.pendingRequest=new Object;this.pendingRequest.data=Spry.Data.HTTPSourceDataSet.LoadManager.loadData(req,this,this.useCache);};Spry.Data.HTTPSourceDataSet.prototype.cancelLoadData=function() |
|---|
| 524 | {if(this.pendingRequest) |
|---|
| 525 | {Spry.Data.HTTPSourceDataSet.LoadManager.cancelLoadData(this.pendingRequest.data,this);this.pendingRequest=null;}};Spry.Data.HTTPSourceDataSet.prototype.getURL=function(){return this.url;};Spry.Data.HTTPSourceDataSet.prototype.setURL=function(url,requestOptions) |
|---|
| 526 | {if(this.url==url) |
|---|
| 527 | {if(!requestOptions||(this.requestInfo.method==requestOptions.method&&(requestOptions.method!="POST"||this.requestInfo.postData==requestOptions.postData))) |
|---|
| 528 | return;} |
|---|
| 529 | this.url=url;this.setRequestInfo(requestOptions);this.cancelLoadData();this.recalculateDataSetDependencies();this.dataWasLoaded=false;};Spry.Data.HTTPSourceDataSet.prototype.setDataFromDoc=function(rawDataDoc) |
|---|
| 530 | {this.pendingRequest=null;this.loadDataIntoDataSet(rawDataDoc);this.applyColumnTypes();this.disableNotifications();this.filterAndSortData();this.enableNotifications();this.notifyObservers("onPostLoad");this.notifyObservers("onDataChanged");};Spry.Data.HTTPSourceDataSet.prototype.loadDataIntoDataSet=function(rawDataDoc) |
|---|
| 531 | {this.dataHash=new Object;this.data=new Array;this.dataWasLoaded=true;};Spry.Data.HTTPSourceDataSet.prototype.xhRequestProcessor=function(xhRequest) |
|---|
| 532 | {var resp=xhRequest.responseText;if(xhRequest.status==200||xhRequest.status==0) |
|---|
| 533 | return resp;return null;};Spry.Data.HTTPSourceDataSet.prototype.sessionExpiredChecker=function(req) |
|---|
| 534 | {if(req.xhRequest.responseText=='session expired') |
|---|
| 535 | return true;return false;};Spry.Data.HTTPSourceDataSet.prototype.setSessionExpiredChecker=function(checker) |
|---|
| 536 | {this.sessionExpiredChecker=checker;};Spry.Data.HTTPSourceDataSet.prototype.onRequestResponse=function(cachedRequest,req) |
|---|
| 537 | {this.setDataFromDoc(cachedRequest.rawData);};Spry.Data.HTTPSourceDataSet.prototype.onRequestError=function(cachedRequest,req) |
|---|
| 538 | {this.notifyObservers("onLoadError",req);};Spry.Data.HTTPSourceDataSet.prototype.onRequestSessionExpired=function(cachedRequest,req) |
|---|
| 539 | {this.notifyObservers("onSessionExpired",req);};Spry.Data.HTTPSourceDataSet.LoadManager={};Spry.Data.HTTPSourceDataSet.LoadManager.cache=[];Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest=function(reqInfo,xhRequestProcessor,sessionExpiredChecker) |
|---|
| 540 | {Spry.Utils.Notifier.call(this);this.reqInfo=reqInfo;this.rawData=null;this.timer=null;this.state=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.NOT_LOADED;this.xhRequestProcessor=xhRequestProcessor;this.sessionExpiredChecker=sessionExpiredChecker;};Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype=new Spry.Utils.Notifier();Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.constructor=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest;Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.NOT_LOADED=1;Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_REQUESTED=2;Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_FAILED=3;Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_SUCCESSFUL=4;Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.loadDataCallback=function(req) |
|---|
| 541 | {if(req.xhRequest.readyState!=4) |
|---|
| 542 | return;var rawData=null;if(this.xhRequestProcessor)rawData=this.xhRequestProcessor(req.xhRequest);if(this.sessionExpiredChecker) |
|---|
| 543 | {Spry.Utils.setOptions(req,{'rawData':rawData},false);if(this.sessionExpiredChecker(req)) |
|---|
| 544 | {this.state=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_FAILED;this.notifyObservers("onRequestSessionExpired",req);this.observers.length=0;return;}} |
|---|
| 545 | if(!rawData) |
|---|
| 546 | {this.state=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_FAILED;this.notifyObservers("onRequestError",req);this.observers.length=0;return;} |
|---|
| 547 | this.rawData=rawData;this.state=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_SUCCESSFUL;this.notifyObservers("onRequestResponse",req);this.observers.length=0;};Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.loadData=function() |
|---|
| 548 | {var self=this;this.cancelLoadData();this.rawData=null;this.state=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_REQUESTED;var reqInfo=this.reqInfo.clone();reqInfo.successCallback=function(req){self.loadDataCallback(req);};reqInfo.errorCallback=reqInfo.successCallback;this.timer=setTimeout(function() |
|---|
| 549 | {self.timer=null;Spry.Utils.loadURL(reqInfo.method,reqInfo.url,reqInfo.async,reqInfo.successCallback,reqInfo);},0);};Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.prototype.cancelLoadData=function() |
|---|
| 550 | {if(this.state==Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_REQUESTED) |
|---|
| 551 | {if(this.timer) |
|---|
| 552 | {this.timer.clearTimeout();this.timer=null;} |
|---|
| 553 | this.rawData=null;this.state=Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.NOT_LOADED;}};Spry.Data.HTTPSourceDataSet.LoadManager.getCacheKey=function(reqInfo) |
|---|
| 554 | {return reqInfo.method+"::"+reqInfo.url+"::"+reqInfo.postData+"::"+reqInfo.username;};Spry.Data.HTTPSourceDataSet.LoadManager.loadData=function(reqInfo,ds,useCache) |
|---|
| 555 | {if(!reqInfo) |
|---|
| 556 | return null;var cacheObj=null;var cacheKey=null;if(useCache) |
|---|
| 557 | {cacheKey=Spry.Data.HTTPSourceDataSet.LoadManager.getCacheKey(reqInfo);cacheObj=Spry.Data.HTTPSourceDataSet.LoadManager.cache[cacheKey];} |
|---|
| 558 | if(cacheObj) |
|---|
| 559 | {if(cacheObj.state==Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_REQUESTED) |
|---|
| 560 | {if(ds) |
|---|
| 561 | cacheObj.addObserver(ds);return cacheObj;} |
|---|
| 562 | else if(cacheObj.state==Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest.LOAD_SUCCESSFUL) |
|---|
| 563 | {if(ds) |
|---|
| 564 | setTimeout(function(){ds.setDataFromDoc(cacheObj.rawData);},0);return cacheObj;}} |
|---|
| 565 | if(!cacheObj) |
|---|
| 566 | {cacheObj=new Spry.Data.HTTPSourceDataSet.LoadManager.CachedRequest(reqInfo,(ds?ds.xhRequestProcessor:null),(ds?ds.sessionExpiredChecker:null));if(useCache) |
|---|
| 567 | {Spry.Data.HTTPSourceDataSet.LoadManager.cache[cacheKey]=cacheObj;cacheObj.addObserver({onRequestError:function(){Spry.Data.HTTPSourceDataSet.LoadManager.cache[cacheKey]=undefined;}});}} |
|---|
| 568 | if(ds) |
|---|
| 569 | cacheObj.addObserver(ds);cacheObj.loadData();return cacheObj;};Spry.Data.HTTPSourceDataSet.LoadManager.cancelLoadData=function(cacheObj,ds) |
|---|
| 570 | {if(cacheObj) |
|---|
| 571 | {if(ds) |
|---|
| 572 | cacheObj.removeObserver(ds);else |
|---|
| 573 | cacheObj.cancelLoadData();}};Spry.Data.XMLDataSet=function(dataSetURL,dataSetPath,dataSetOptions) |
|---|
| 574 | {this.xpath=dataSetPath;this.doc=null;this.subPaths=[];this.entityEncodeStrings=true;Spry.Data.HTTPSourceDataSet.call(this,dataSetURL,dataSetOptions);var jwType=typeof this.subPaths;if(jwType=="string"||(jwType=="object"&&this.subPaths.constructor!=Array)) |
|---|
| 575 | this.subPaths=[this.subPaths];};Spry.Data.XMLDataSet.prototype=new Spry.Data.HTTPSourceDataSet();Spry.Data.XMLDataSet.prototype.constructor=Spry.Data.XMLDataSet;Spry.Data.XMLDataSet.prototype.getDataRefStrings=function() |
|---|
| 576 | {var strArr=[];if(this.url)strArr.push(this.url);if(this.xpath)strArr.push(this.xpath);if(this.requestInfo&&this.requestInfo.postData)strArr.push(this.requestInfo.postData);return strArr;};Spry.Data.XMLDataSet.prototype.getDocument=function(){return this.doc;};Spry.Data.XMLDataSet.prototype.getXPath=function(){return this.xpath;};Spry.Data.XMLDataSet.prototype.setXPath=function(path) |
|---|
| 577 | {if(this.xpath!=path) |
|---|
| 578 | {this.xpath=path;if(this.dataWasLoaded&&this.doc) |
|---|
| 579 | {this.notifyObservers("onPreLoad");this.setDataFromDoc(this.doc);}}};Spry.Data.XMLDataSet.nodeContainsElementNode=function(node) |
|---|
| 580 | {if(node) |
|---|
| 581 | {node=node.firstChild;while(node) |
|---|
| 582 | {if(node.nodeType==1) |
|---|
| 583 | return true;node=node.nextSibling;}} |
|---|
| 584 | return false;};Spry.Data.XMLDataSet.getNodeText=function(node,encodeText,encodeCData) |
|---|
| 585 | {var txt="";if(!node) |
|---|
| 586 | return;try |
|---|
| 587 | {var child=node.firstChild;while(child) |
|---|
| 588 | {try |
|---|
| 589 | {if(child.nodeType==3) |
|---|
| 590 | txt+=encodeText?Spry.Utils.encodeEntities(child.data):child.data;else if(child.nodeType==4) |
|---|
| 591 | txt+=encodeCData?Spry.Utils.encodeEntities(child.data):child.data;}catch(e){Spry.Debug.reportError("Spry.Data.XMLDataSet.getNodeText() exception caught: "+e+"\n");} |
|---|
| 592 | child=child.nextSibling;}} |
|---|
| 593 | catch(e){Spry.Debug.reportError("Spry.Data.XMLDataSet.getNodeText() exception caught: "+e+"\n");} |
|---|
| 594 | return txt;};Spry.Data.XMLDataSet.createObjectForNode=function(node,encodeText,encodeCData) |
|---|
| 595 | {if(!node) |
|---|
| 596 | return null;var obj=new Object();var i=0;var attr=null;try |
|---|
| 597 | {for(i=0;i<node.attributes.length;i++) |
|---|
| 598 | {attr=node.attributes[i];if(attr&&attr.nodeType==2) |
|---|
| 599 | obj["@"+attr.name]=attr.value;}} |
|---|
| 600 | catch(e) |
|---|
| 601 | {Spry.Debug.reportError("Spry.Data.XMLDataSet.createObjectForNode() caught exception while accessing attributes: "+e+"\n");} |
|---|
| 602 | var child=node.firstChild;if(child&&!child.nextSibling&&child.nodeType!=1) |
|---|
| 603 | {obj[node.nodeName]=Spry.Data.XMLDataSet.getNodeText(node,encodeText,encodeCData);} |
|---|
| 604 | while(child) |
|---|
| 605 | {if(child.nodeType==1) |
|---|
| 606 | {if(!Spry.Data.XMLDataSet.nodeContainsElementNode(child)) |
|---|
| 607 | {obj[child.nodeName]=Spry.Data.XMLDataSet.getNodeText(child,encodeText,encodeCData);try |
|---|
| 608 | {var namePrefix=child.nodeName+"/@";for(i=0;i<child.attributes.length;i++) |
|---|
| 609 | {attr=child.attributes[i];if(attr&&attr.nodeType==2) |
|---|
| 610 | obj[namePrefix+attr.name]=attr.value;}} |
|---|
| 611 | catch(e) |
|---|
| 612 | {Spry.Debug.reportError("Spry.Data.XMLDataSet.createObjectForNode() caught exception while accessing attributes: "+e+"\n");}}} |
|---|
| 613 | child=child.nextSibling;} |
|---|
| 614 | return obj;};Spry.Data.XMLDataSet.getRecordSetFromXMLDoc=function(xmlDoc,path,suppressColumns,entityEncodeStrings) |
|---|
| 615 | {if(!xmlDoc||!path) |
|---|
| 616 | return null;var recordSet=new Object();recordSet.xmlDoc=xmlDoc;recordSet.xmlPath=path;recordSet.dataHash=new Object;recordSet.data=new Array;recordSet.getData=function(){return this.data;};var ctx=new ExprContext(xmlDoc);var pathExpr=xpathParse(path);var e=pathExpr.evaluate(ctx);var nodeArray=e.nodeSetValue();var isDOMNodeArray=true;if(nodeArray&&nodeArray.length>0) |
|---|
| 617 | isDOMNodeArray=nodeArray[0].nodeType!=2;var nextID=0;var encodeText=true;var encodeCData=false;if(typeof entityEncodeStrings=="boolean") |
|---|
| 618 | encodeText=encodeCData=entityEncodeStrings;for(var i=0;i<nodeArray.length;i++) |
|---|
| 619 | {var rowObj=null;if(suppressColumns) |
|---|
| 620 | rowObj=new Object;else |
|---|
| 621 | {if(isDOMNodeArray) |
|---|
| 622 | rowObj=Spry.Data.XMLDataSet.createObjectForNode(nodeArray[i],encodeText,encodeCData);else |
|---|
| 623 | {rowObj=new Object;rowObj["@"+nodeArray[i].name]=nodeArray[i].value;}} |
|---|
| 624 | if(rowObj) |
|---|
| 625 | {rowObj['ds_RowID']=nextID++;rowObj['ds_XMLNode']=nodeArray[i];recordSet.dataHash[rowObj['ds_RowID']]=rowObj;recordSet.data.push(rowObj);}} |
|---|
| 626 | return recordSet;};Spry.Data.XMLDataSet.PathNode=function(path) |
|---|
| 627 | {this.path=path;this.subPaths=[];this.xpath="";};Spry.Data.XMLDataSet.PathNode.prototype.addSubPath=function(path) |
|---|
| 628 | {var node=this.findSubPath(path);if(!node) |
|---|
| 629 | {node=new Spry.Data.XMLDataSet.PathNode(path);this.subPaths.push(node);} |
|---|
| 630 | return node;};Spry.Data.XMLDataSet.PathNode.prototype.findSubPath=function(path) |
|---|
| 631 | {var numSubPaths=this.subPaths.length;for(var i=0;i<numSubPaths;i++) |
|---|
| 632 | {var subPath=this.subPaths[i];if(path==subPath.path) |
|---|
| 633 | return subPath;} |
|---|
| 634 | return null;};Spry.Data.XMLDataSet.PathNode.prototype.consolidate=function() |
|---|
| 635 | {var numSubPaths=this.subPaths.length;if(!this.xpath&&numSubPaths==1) |
|---|
| 636 | {var subPath=this.subPaths[0];this.path+=((subPath[0]!="/")?"/":"")+subPath.path;this.xpath=subPath.xpath;this.subPaths=subPath.subPaths;this.consolidate();return;} |
|---|
| 637 | for(var i=0;i<numSubPaths;i++) |
|---|
| 638 | this.subPaths[i].consolidate();};Spry.Data.XMLDataSet.prototype.convertXPathsToPathTree=function(xpathArray) |
|---|
| 639 | {var xpaLen=xpathArray.length;var root=new Spry.Data.XMLDataSet.PathNode("");for(var i=0;i<xpaLen;i++) |
|---|
| 640 | {var xpath=xpathArray[i];var cleanXPath=xpath.replace(/\/\//g,"/__SPRYDS__");cleanXPath=cleanXPath.replace(/^\//,"");var pathItems=cleanXPath.split(/\//);var pathItemsLen=pathItems.length;var node=root;for(var j=0;j<pathItemsLen;j++) |
|---|
| 641 | {var path=pathItems[j].replace(/__SPRYDS__/,"//");node=node.addSubPath(path);} |
|---|
| 642 | node.xpath=xpath;} |
|---|
| 643 | root.consolidate();return root;};Spry.Data.XMLDataSet.prototype.flattenSubPaths=function(rs,subPaths) |
|---|
| 644 | {if(!rs||!subPaths) |
|---|
| 645 | return;var numSubPaths=subPaths.length;if(numSubPaths<1) |
|---|
| 646 | return;var data=rs.data;var dataHash={};var xpathArray=[];var cleanedXPathArray=[];for(var i=0;i<numSubPaths;i++) |
|---|
| 647 | {var subPath=subPaths[i];if(typeof subPath=="object") |
|---|
| 648 | subPath=subPath.path;if(!subPath) |
|---|
| 649 | subPath="";xpathArray[i]=Spry.Data.Region.processDataRefString(null,subPath,this.dataSetsForDataRefStrings);cleanedXPathArray[i]=xpathArray[i].replace(/\[.*\]/g,"");} |
|---|
| 650 | var row;var numRows=data.length;var newData=[];for(var i=0;i<numRows;i++) |
|---|
| 651 | {row=data[i];var newRows=[row];for(var j=0;j<numSubPaths;j++) |
|---|
| 652 | {var newRS=Spry.Data.XMLDataSet.getRecordSetFromXMLDoc(row.ds_XMLNode,xpathArray[j],(subPaths[j].xpath?false:true),this.entityEncodeStrings);if(newRS&&newRS.data&&newRS.data.length) |
|---|
| 653 | {if(typeof subPaths[j]=="object"&&subPaths[j].subPaths) |
|---|
| 654 | {var sp=subPaths[j].subPaths;spType=typeof sp;if(spType=="string") |
|---|
| 655 | sp=[sp];else if(spType=="object"&&spType.constructor==Object) |
|---|
| 656 | sp=[sp];this.flattenSubPaths(newRS,sp);} |
|---|
| 657 | var newRSData=newRS.data;var numRSRows=newRSData.length;var cleanedXPath=cleanedXPathArray[j]+"/";var numNewRows=newRows.length;var joinedRows=[];for(var k=0;k<numNewRows;k++) |
|---|
| 658 | {var newRow=newRows[k];for(var l=0;l<numRSRows;l++) |
|---|
| 659 | {var newRowObj=new Object;var newRSRow=newRSData[l];for(prop in newRow) |
|---|
| 660 | newRowObj[prop]=newRow[prop];for(var prop in newRSRow) |
|---|
| 661 | {var newPropName=cleanedXPath+prop;if(cleanedXPath==(prop+"/")||cleanedXPath.search(new RegExp("\\/"+prop+"\\/$"))!=-1) |
|---|
| 662 | newPropName=cleanedXPathArray[j];newRowObj[newPropName]=newRSRow[prop];} |
|---|
| 663 | joinedRows.push(newRowObj);}} |
|---|
| 664 | newRows=joinedRows;}} |
|---|
| 665 | newData=newData.concat(newRows);} |
|---|
| 666 | data=newData;numRows=data.length;for(i=0;i<numRows;i++) |
|---|
| 667 | {row=data[i];row.ds_RowID=i;dataHash[row.ds_RowID]=row;} |
|---|
| 668 | rs.data=data;rs.dataHash=dataHash;};Spry.Data.XMLDataSet.prototype.loadDataIntoDataSet=function(rawDataDoc) |
|---|
| 669 | {var rs=null;var mainXPath=Spry.Data.Region.processDataRefString(null,this.xpath,this.dataSetsForDataRefStrings);var subPaths=this.subPaths;var suppressColumns=false;if(this.subPaths&&this.subPaths.length>0) |
|---|
| 670 | {var processedSubPaths=[];var numSubPaths=subPaths.length;for(var i=0;i<numSubPaths;i++) |
|---|
| 671 | {var subPathStr=Spry.Data.Region.processDataRefString(null,subPaths[i],this.dataSetsForDataRefStrings);if(subPathStr.charAt(0)!='/') |
|---|
| 672 | subPathStr=mainXPath+"/"+subPathStr;processedSubPaths.push(subPathStr);} |
|---|
| 673 | processedSubPaths.unshift(mainXPath);var commonParent=this.convertXPathsToPathTree(processedSubPaths);mainXPath=commonParent.path;subPaths=commonParent.subPaths;suppressColumns=commonParent.xpath?false:true;} |
|---|
| 674 | rs=Spry.Data.XMLDataSet.getRecordSetFromXMLDoc(rawDataDoc,mainXPath,suppressColumns,this.entityEncodeStrings);if(!rs) |
|---|
| 675 | {Spry.Debug.reportError("Spry.Data.XMLDataSet.loadDataIntoDataSet() failed to create dataSet '"+this.name+"'for '"+this.xpath+"' - "+this.url+"\n");return;} |
|---|
| 676 | this.flattenSubPaths(rs,subPaths);this.doc=rs.xmlDoc;this.data=rs.data;this.dataHash=rs.dataHash;this.dataWasLoaded=(this.doc!=null);};Spry.Data.XMLDataSet.prototype.xhRequestProcessor=function(xhRequest) |
|---|
| 677 | {var resp=xhRequest.responseXML;var manualParseRequired=false;if(xhRequest.status!=200) |
|---|
| 678 | {if(xhRequest.status==0) |
|---|
| 679 | {if(xhRequest.responseText&&(!resp||!resp.firstChild)) |
|---|
| 680 | manualParseRequired=true;}} |
|---|
| 681 | else if(!resp) |
|---|
| 682 | {manualParseRequired=true;} |
|---|
| 683 | if(manualParseRequired) |
|---|
| 684 | resp=Spry.Utils.stringToXMLDoc(xhRequest.responseText);if(!resp||!resp.firstChild||resp.firstChild.nodeName=="parsererror") |
|---|
| 685 | return null;return resp;};Spry.Data.XMLDataSet.prototype.sessionExpiredChecker=function(req) |
|---|
| 686 | {if(req.xhRequest.responseText=='session expired') |
|---|
| 687 | return true;else |
|---|
| 688 | {if(req.rawData) |
|---|
| 689 | {var firstChild=req.rawData.documentElement.firstChild;if(firstChild&&firstChild.nodeValue=="session expired") |
|---|
| 690 | return true;}} |
|---|
| 691 | return false;};Spry.Data.Region=function(regionNode,name,isDetailRegion,data,dataSets,regionStates,regionStateMap,hasBehaviorAttributes) |
|---|
| 692 | {this.regionNode=regionNode;this.name=name;this.isDetailRegion=isDetailRegion;this.data=data;this.dataSets=dataSets;this.hasBehaviorAttributes=hasBehaviorAttributes;this.tokens=null;this.currentState=null;this.states={ready:true};this.stateMap={};Spry.Utils.setOptions(this.states,regionStates);Spry.Utils.setOptions(this.stateMap,regionStateMap);for(var i=0;i<this.dataSets.length;i++) |
|---|
| 693 | {var ds=this.dataSets[i];try |
|---|
| 694 | {if(ds) |
|---|
| 695 | ds.addObserver(this);} |
|---|
| 696 | catch(e){Spry.Debug.reportError("Failed to add '"+this.name+"' as a dataSet observer!\n");}}};Spry.Data.Region.hiddenRegionClassName="SpryHiddenRegion";Spry.Data.Region.evenRowClassName="even";Spry.Data.Region.oddRowClassName="odd";Spry.Data.Region.notifiers={};Spry.Data.Region.evalScripts=true;Spry.Data.Region.addObserver=function(regionID,observer) |
|---|
| 697 | {var n=Spry.Data.Region.notifiers[regionID];if(!n) |
|---|
| 698 | {n=new Spry.Utils.Notifier();Spry.Data.Region.notifiers[regionID]=n;} |
|---|
| 699 | n.addObserver(observer);};Spry.Data.Region.removeObserver=function(regionID,observer) |
|---|
| 700 | {var n=Spry.Data.Region.notifiers[regionID];if(n) |
|---|
| 701 | n.removeObserver(observer);};Spry.Data.Region.notifyObservers=function(methodName,region,data) |
|---|
| 702 | {var n=Spry.Data.Region.notifiers[region.name];if(n) |
|---|
| 703 | {var dataObj={};if(data&&typeof data=="object") |
|---|
| 704 | dataObj=data;else |
|---|
| 705 | dataObj.data=data;dataObj.region=region;dataObj.regionID=region.name;dataObj.regionNode=region.regionNode;n.notifyObservers(methodName,dataObj);}};Spry.Data.Region.RS_Error=0x01;Spry.Data.Region.RS_LoadingData=0x02;Spry.Data.Region.RS_PreUpdate=0x04;Spry.Data.Region.RS_PostUpdate=0x08;Spry.Data.Region.prototype.getState=function() |
|---|
| 706 | {return this.currentState;};Spry.Data.Region.prototype.mapState=function(stateName,newStateName) |
|---|
| 707 | {this.stateMap[stateName]=newStateName;};Spry.Data.Region.prototype.getMappedState=function(stateName) |
|---|
| 708 | {var mappedState=this.stateMap[stateName];return mappedState?mappedState:stateName;};Spry.Data.Region.prototype.setState=function(stateName,suppressNotfications) |
|---|
| 709 | {var stateObj={state:stateName,mappedState:this.getMappedState(stateName)};if(!suppressNotfications) |
|---|
| 710 | Spry.Data.Region.notifyObservers("onPreStateChange",this,stateObj);this.currentState=stateObj.mappedState?stateObj.mappedState:stateName;if(this.states[stateName]) |
|---|
| 711 | {var notificationData={state:this.currentState};if(!suppressNotfications) |
|---|
| 712 | Spry.Data.Region.notifyObservers("onPreUpdate",this,notificationData);var str=this.transform();if(Spry.Data.Region.debug) |
|---|
| 713 | Spry.Debug.trace("<hr />Generated region markup for '"+this.name+"':<br /><br />"+Spry.Utils.encodeEntities(str));Spry.Utils.setInnerHTML(this.regionNode,str,!Spry.Data.Region.evalScripts);if(this.hasBehaviorAttributes) |
|---|
| 714 | this.attachBehaviors();if(!suppressNotfications) |
|---|
| 715 | Spry.Data.Region.notifyObservers("onPostUpdate",this,notificationData);} |
|---|
| 716 | if(!suppressNotfications) |
|---|
| 717 | Spry.Data.Region.notifyObservers("onPostStateChange",this,stateObj);};Spry.Data.Region.prototype.getDataSets=function() |
|---|
| 718 | {return this.dataSets;};Spry.Data.Region.prototype.addDataSet=function(aDataSet) |
|---|
| 719 | {if(!aDataSet) |
|---|
| 720 | return;if(!this.dataSets) |
|---|
| 721 | this.dataSets=new Array;for(var i=0;i<this.dataSets.length;i++) |
|---|
| 722 | {if(this.dataSets[i]==aDataSet) |
|---|
| 723 | return;} |
|---|
| 724 | this.dataSets.push(aDataSet);aDataSet.addObserver(this);};Spry.Data.Region.prototype.removeDataSet=function(aDataSet) |
|---|
| 725 | {if(!aDataSet||this.dataSets) |
|---|
| 726 | return;for(var i=0;i<this.dataSets.length;i++) |
|---|
| 727 | {if(this.dataSets[i]==aDataSet) |
|---|
| 728 | {this.dataSets.splice(i,1);aDataSet.removeObserver(this);return;}}};Spry.Data.Region.prototype.onPreLoad=function(dataSet) |
|---|
| 729 | {if(this.currentState!="loading") |
|---|
| 730 | this.setState("loading");};Spry.Data.Region.prototype.onLoadError=function(dataSet) |
|---|
| 731 | {if(this.currentState!="error") |
|---|
| 732 | this.setState("error");Spry.Data.Region.notifyObservers("onError",this);};Spry.Data.Region.prototype.onSessionExpired=function(dataSet) |
|---|
| 733 | {if(this.currentState!="expired") |
|---|
| 734 | this.setState("expired");Spry.Data.Region.notifyObservers("onExpired",this);};Spry.Data.Region.prototype.onCurrentRowChanged=function(dataSet,data) |
|---|
| 735 | {if(this.isDetailRegion) |
|---|
| 736 | this.updateContent();};Spry.Data.Region.prototype.onPostSort=function(dataSet,data) |
|---|
| 737 | {this.updateContent();};Spry.Data.Region.prototype.onDataChanged=function(dataSet,data) |
|---|
| 738 | {this.updateContent();};Spry.Data.Region.enableBehaviorAttributes=true;Spry.Data.Region.behaviorAttrs={};Spry.Data.Region.behaviorAttrs["spry:select"]={attach:function(rgn,node,value) |
|---|
| 739 | {var selectGroupName=null;try{selectGroupName=node.attributes.getNamedItem("spry:selectgroup").value;}catch(e){} |
|---|
| 740 | if(!selectGroupName) |
|---|
| 741 | selectGroupName="default";Spry.Utils.addEventListener(node,"click",function(event){Spry.Utils.SelectionManager.select(selectGroupName,node,value);},false);if(node.attributes.getNamedItem("spry:selected")) |
|---|
| 742 | Spry.Utils.SelectionManager.select(selectGroupName,node,value);}};Spry.Data.Region.behaviorAttrs["spry:hover"]={attach:function(rgn,node,value) |
|---|
| 743 | {Spry.Utils.addEventListener(node,"mouseover",function(event){Spry.Utils.addClassName(node,value);},false);Spry.Utils.addEventListener(node,"mouseout",function(event){Spry.Utils.removeClassName(node,value);},false);}};Spry.Data.Region.setUpRowNumberForEvenOddAttr=function(node,attr,value,rowNumAttrName) |
|---|
| 744 | {if(!value) |
|---|
| 745 | {Spry.Debug.showError("The "+attr+" attribute requires a CSS class name as its value!");node.attributes.removeNamedItem(attr);return;} |
|---|
| 746 | var dsName="";var valArr=value.split(/\s/);if(valArr.length>1) |
|---|
| 747 | {dsName=valArr[0];node.setAttribute(attr,valArr[1]);} |
|---|
| 748 | node.setAttribute(rowNumAttrName,"{"+(dsName?(dsName+"::"):"")+"ds_RowNumber}");};Spry.Data.Region.behaviorAttrs["spry:even"]={setup:function(node,value) |
|---|
| 749 | {Spry.Data.Region.setUpRowNumberForEvenOddAttr(node,"spry:even",value,"spryevenrownumber");},attach:function(rgn,node,value) |
|---|
| 750 | {if(value) |
|---|
| 751 | {rowNumAttr=node.attributes.getNamedItem("spryevenrownumber");if(rowNumAttr&&rowNumAttr.value) |
|---|
| 752 | {var rowNum=parseInt(rowNumAttr.value);if(rowNum%2) |
|---|
| 753 | Spry.Utils.addClassName(node,value);}} |
|---|
| 754 | node.removeAttribute("spry:even");node.removeAttribute("spryevenrownumber");}};Spry.Data.Region.behaviorAttrs["spry:odd"]={setup:function(node,value) |
|---|
| 755 | {Spry.Data.Region.setUpRowNumberForEvenOddAttr(node,"spry:odd",value,"spryoddrownumber");},attach:function(rgn,node,value) |
|---|
| 756 | {if(value) |
|---|
| 757 | {rowNumAttr=node.attributes.getNamedItem("spryoddrownumber");if(rowNumAttr&&rowNumAttr.value) |
|---|
| 758 | {var rowNum=parseInt(rowNumAttr.value);if(rowNum%2==0) |
|---|
| 759 | Spry.Utils.addClassName(node,value);}} |
|---|
| 760 | node.removeAttribute("spry:odd");node.removeAttribute("spryoddrownumber");}};Spry.Data.Region.setRowAttrClickHandler=function(node,dsName,rowAttr,funcName) |
|---|
| 761 | {if(dsName) |
|---|
| 762 | {var ds=Spry.Data.getDataSetByName(dsName);if(ds) |
|---|
| 763 | {rowIDAttr=node.attributes.getNamedItem(rowAttr);if(rowIDAttr) |
|---|
| 764 | {var rowAttrVal=rowIDAttr.value;if(rowAttrVal) |
|---|
| 765 | Spry.Utils.addEventListener(node,"click",function(event){ds[funcName](rowAttrVal);},false);}}}};Spry.Data.Region.behaviorAttrs["spry:setrow"]={setup:function(node,value) |
|---|
| 766 | {if(!value) |
|---|
| 767 | {Spry.Debug.reportError("The spry:setrow attribute requires a data set name as its value!");node.removeAttribute("spry:setrow");return;} |
|---|
| 768 | node.setAttribute("spryrowid","{"+value+"::ds_RowID}");},attach:function(rgn,node,value) |
|---|
| 769 | {Spry.Data.Region.setRowAttrClickHandler(node,value,"spryrowid","setCurrentRow");node.removeAttribute("spry:setrow");node.removeAttribute("spryrowid");}};Spry.Data.Region.behaviorAttrs["spry:setrownumber"]={setup:function(node,value) |
|---|
| 770 | {if(!value) |
|---|
| 771 | {Spry.Debug.reportError("The spry:setrownumber attribute requires a data set name as its value!");node.removeAttribute("spry:setrownumber");return;} |
|---|
| 772 | node.setAttribute("spryrownumber","{"+value+"::ds_RowID}");},attach:function(rgn,node,value) |
|---|
| 773 | {Spry.Data.Region.setRowAttrClickHandler(node,value,"spryrownumber","setCurrentRowNumber");node.removeAttribute("spry:setrownumber");node.removeAttribute("spryrownumber");}};Spry.Data.Region.behaviorAttrs["spry:sort"]={attach:function(rgn,node,value) |
|---|
| 774 | {if(!value) |
|---|
| 775 | return;var ds=rgn.getDataSets()[0];var sortOrder="toggle";var colArray=value.split(/\s/);if(colArray.length>1) |
|---|
| 776 | {var specifiedDS=Spry.Data.getDataSetByName(colArray[0]);if(specifiedDS) |
|---|
| 777 | {ds=specifiedDS;colArray.shift();} |
|---|
| 778 | if(colArray.length>1) |
|---|
| 779 | {var str=colArray[colArray.length-1];if(str=="ascending"||str=="descending"||str=="toggle") |
|---|
| 780 | {sortOrder=str;colArray.pop();}}} |
|---|
| 781 | if(ds&&colArray.length>0) |
|---|
| 782 | Spry.Utils.addEventListener(node,"click",function(event){ds.sort(colArray,sortOrder);},false);node.removeAttribute("spry:sort");}};Spry.Data.Region.prototype.attachBehaviors=function() |
|---|
| 783 | {var rgn=this;Spry.Utils.getNodesByFunc(this.regionNode,function(node) |
|---|
| 784 | {if(!node||node.nodeType!=1) |
|---|
| 785 | return false;try |
|---|
| 786 | {var bAttrs=Spry.Data.Region.behaviorAttrs;for(var bAttrName in bAttrs) |
|---|
| 787 | {var attr=node.attributes.getNamedItem(bAttrName);if(attr) |
|---|
| 788 | {var behavior=bAttrs[bAttrName];if(behavior&&behavior.attach) |
|---|
| 789 | behavior.attach(rgn,node,attr.value);}}}catch(e){} |
|---|
| 790 | return false;});};Spry.Data.Region.prototype.updateContent=function() |
|---|
| 791 | {var allDataSetsReady=true;var dsArray=this.getDataSets();if(!dsArray||dsArray.length<1) |
|---|
| 792 | {Spry.Debug.reportError("updateContent(): Region '"+this.name+"' has no data set!\n");return;} |
|---|
| 793 | for(var i=0;i<dsArray.length;i++) |
|---|
| 794 | {var ds=dsArray[i];if(ds) |
|---|
| 795 | {if(ds.getLoadDataRequestIsPending()) |
|---|
| 796 | allDataSetsReady=false;else if(!ds.getDataWasLoaded()) |
|---|
| 797 | {ds.loadData();allDataSetsReady=false;}}} |
|---|
| 798 | if(!allDataSetsReady) |
|---|
| 799 | {Spry.Data.Region.notifyObservers("onLoadingData",this);return;} |
|---|
| 800 | this.setState("ready");};Spry.Data.Region.prototype.clearContent=function() |
|---|
| 801 | {this.regionNode.innerHTML="";};Spry.Data.Region.processContentPI=function(inStr) |
|---|
| 802 | {var outStr="";var regexp=/<!--\s*<\/?spry:content\s*[^>]*>\s*-->/mg;var searchStartIndex=0;var processingContentTag=0;while(inStr.length) |
|---|
| 803 | {var results=regexp.exec(inStr);if(!results||!results[0]) |
|---|
| 804 | {outStr+=inStr.substr(searchStartIndex,inStr.length-searchStartIndex);break;} |
|---|
| 805 | if(!processingContentTag&&results.index!=searchStartIndex) |
|---|
| 806 | {outStr+=inStr.substr(searchStartIndex,results.index-searchStartIndex);} |
|---|
| 807 | if(results[0].search(/<\//)!=-1) |
|---|
| 808 | {--processingContentTag;if(processingContentTag) |
|---|
| 809 | Spry.Debug.reportError("Nested spry:content regions are not allowed!\n");} |
|---|
| 810 | else |
|---|
| 811 | {++processingContentTag;var dataRefStr=results[0].replace(/.*\bdataref="/,"");outStr+=dataRefStr.replace(/".*$/,"");} |
|---|
| 812 | searchStartIndex=regexp.lastIndex;} |
|---|
| 813 | return outStr;};Spry.Data.Region.prototype.tokenizeData=function(dataStr) |
|---|
| 814 | {if(!dataStr) |
|---|
| 815 | return null;var rootToken=new Spry.Data.Region.Token(Spry.Data.Region.Token.LIST_TOKEN,null,null,null);var tokenStack=new Array;var parseStr=Spry.Data.Region.processContentPI(dataStr);tokenStack.push(rootToken);var regexp=/((<!--\s*){0,1}<\/{0,1}spry:[^>]+>(\s*-->){0,1})|((\{|%7[bB])[^\}\s%]+(\}|%7[dD]))/mg;var searchStartIndex=0;while(parseStr.length) |
|---|
| 816 | {var results=regexp.exec(parseStr);var token=null;if(!results||!results[0]) |
|---|
| 817 | {var str=parseStr.substr(searchStartIndex,parseStr.length-searchStartIndex);token=new Spry.Data.Region.Token(Spry.Data.Region.Token.STRING_TOKEN,null,str,str);tokenStack[tokenStack.length-1].addChild(token);break;} |
|---|
| 818 | if(results.index!=searchStartIndex) |
|---|
| 819 | {var str=parseStr.substr(searchStartIndex,results.index-searchStartIndex);token=new Spry.Data.Region.Token(Spry.Data.Region.Token.STRING_TOKEN,null,str,str);tokenStack[tokenStack.length-1].addChild(token);} |
|---|
| 820 | if(results[0].search(/^({|%7[bB])/)!=-1) |
|---|
| 821 | {var valueName=results[0];var regionStr=results[0];valueName=valueName.replace(/^({|%7[bB])/,"");valueName=valueName.replace(/(}|%7[dD])$/,"");var dataSetName=null;var splitArray=valueName.split(/::/);if(splitArray.length>1) |
|---|
| 822 | {dataSetName=splitArray[0];valueName=splitArray[1];} |
|---|
| 823 | regionStr=regionStr.replace(/^%7[bB]/,"{");regionStr=regionStr.replace(/%7[dD]$/,"}");token=new Spry.Data.Region.Token(Spry.Data.Region.Token.VALUE_TOKEN,dataSetName,valueName,new String(regionStr));tokenStack[tokenStack.length-1].addChild(token);} |
|---|
| 824 | else if(results[0].charAt(0)=='<') |
|---|
| 825 | {var piName=results[0].replace(/^(<!--\s*){0,1}<\/?/,"");piName=piName.replace(/>(\s*-->){0,1}|\s.*$/,"");if(results[0].search(/<\//)!=-1) |
|---|
| 826 | {if(tokenStack[tokenStack.length-1].tokenType!=Spry.Data.Region.Token.PROCESSING_INSTRUCTION_TOKEN) |
|---|
| 827 | {Spry.Debug.reportError("Invalid processing instruction close tag: "+piName+" -- "+results[0]+"\n");return null;} |
|---|
| 828 | tokenStack.pop();} |
|---|
| 829 | else |
|---|
| 830 | {var piDesc=Spry.Data.Region.PI.instructions[piName];if(piDesc) |
|---|
| 831 | {var dataSet=null;var selectedDataSetName="";if(results[0].search(/^.*\bselect=\"/)!=-1) |
|---|
| 832 | {selectedDataSetName=results[0].replace(/^.*\bselect=\"/,"");selectedDataSetName=selectedDataSetName.replace(/".*$/,"");if(selectedDataSetName) |
|---|
| 833 | {dataSet=Spry.Data.getDataSetByName(selectedDataSetName);if(!dataSet) |
|---|
| 834 | {Spry.Debug.reportError("Failed to retrieve data set ("+selectedDataSetName+") for "+piName+"\n");selectedDataSetName="";}}} |
|---|
| 835 | var jsExpr=null;if(results[0].search(/^.*\btest=\"/)!=-1) |
|---|
| 836 | {jsExpr=results[0].replace(/^.*\btest=\"/,"");jsExpr=jsExpr.replace(/".*$/,"");jsExpr=Spry.Utils.decodeEntities(jsExpr);} |
|---|
| 837 | var regionState=null;if(results[0].search(/^.*\bname=\"/)!=-1) |
|---|
| 838 | {regionState=results[0].replace(/^.*\bname=\"/,"");regionState=regionState.replace(/".*$/,"");regionState=Spry.Utils.decodeEntities(regionState);} |
|---|
| 839 | var piData=new Spry.Data.Region.Token.PIData(piName,selectedDataSetName,jsExpr,regionState);token=new Spry.Data.Region.Token(Spry.Data.Region.Token.PROCESSING_INSTRUCTION_TOKEN,dataSet,piData,new String(results[0]));tokenStack[tokenStack.length-1].addChild(token);tokenStack.push(token);} |
|---|
| 840 | else |
|---|
| 841 | {Spry.Debug.reportError("Unsupported region processing instruction: "+results[0]+"\n");return null;}}} |
|---|
| 842 | else |
|---|
| 843 | {Spry.Debug.reportError("Invalid region token: "+results[0]+"\n");return null;} |
|---|
| 844 | searchStartIndex=regexp.lastIndex;} |
|---|
| 845 | return rootToken;};Spry.Data.Region.prototype.processTokenChildren=function(outputArr,token,processContext) |
|---|
| 846 | {var children=token.children;var len=children.length;for(var i=0;i<len;i++) |
|---|
| 847 | this.processTokens(outputArr,children[i],processContext);};Spry.Data.Region.prototype.processTokens=function(outputArr,token,processContext) |
|---|
| 848 | {var i=0;switch(token.tokenType) |
|---|
| 849 | {case Spry.Data.Region.Token.LIST_TOKEN:this.processTokenChildren(outputArr,token,processContext);break;case Spry.Data.Region.Token.STRING_TOKEN:outputArr.push(token.data);break;case Spry.Data.Region.Token.PROCESSING_INSTRUCTION_TOKEN:if(token.data.name=="spry:repeat") |
|---|
| 850 | {var dataSet=null;if(token.dataSet) |
|---|
| 851 | dataSet=token.dataSet;else |
|---|
| 852 | dataSet=this.dataSets[0];if(dataSet) |
|---|
| 853 | {var dsContext=processContext.getDataSetContext(dataSet);if(!dsContext) |
|---|
| 854 | {Spry.Debug.reportError("processTokens() failed to get a data set context!\n");break;} |
|---|
| 855 | dsContext.pushState();var dataSetRows=dsContext.getData();var numRows=dataSetRows.length;for(i=0;i<numRows;i++) |
|---|
| 856 | {dsContext.setRowIndex(i);var testVal=true;if(token.data.jsExpr) |
|---|
| 857 | {var jsExpr=Spry.Data.Region.processDataRefString(processContext,token.data.jsExpr,null,true);try{testVal=Spry.Utils.eval(jsExpr);} |
|---|
| 858 | catch(e) |
|---|
| 859 | {Spry.Debug.trace("Caught exception in Spry.Data.Region.prototype.processTokens while evaluating: "+jsExpr+"\n Exception:"+e+"\n");testVal=true;}} |
|---|
| 860 | if(testVal) |
|---|
| 861 | this.processTokenChildren(outputArr,token,processContext);} |
|---|
| 862 | dsContext.popState();}} |
|---|
| 863 | else if(token.data.name=="spry:if") |
|---|
| 864 | {var testVal=true;if(token.data.jsExpr) |
|---|
| 865 | {var jsExpr=Spry.Data.Region.processDataRefString(processContext,token.data.jsExpr,null,true);try{testVal=Spry.Utils.eval(jsExpr);} |
|---|
| 866 | catch(e) |
|---|
| 867 | {Spry.Debug.trace("Caught exception in Spry.Data.Region.prototype.processTokens while evaluating: "+jsExpr+"\n Exception:"+e+"\n");testVal=true;}} |
|---|
| 868 | if(testVal) |
|---|
| 869 | this.processTokenChildren(outputArr,token,processContext);} |
|---|
| 870 | else if(token.data.name=="spry:choose") |
|---|
| 871 | {var defaultChild=null;var childToProcess=null;var testVal=false;var j=0;for(j=0;j<token.children.length;j++) |
|---|
| 872 | {var child=token.children[j];if(child.tokenType==Spry.Data.Region.Token.PROCESSING_INSTRUCTION_TOKEN) |
|---|
| 873 | {if(child.data.name=="spry:when") |
|---|
| 874 | {if(child.data.jsExpr) |
|---|
| 875 | {var jsExpr=Spry.Data.Region.processDataRefString(processContext,child.data.jsExpr,null,true);try{testVal=Spry.Utils.eval(jsExpr);} |
|---|
| 876 | catch(e) |
|---|
| 877 | {Spry.Debug.trace("Caught exception in Spry.Data.Region.prototype.processTokens while evaluating: "+jsExpr+"\n Exception:"+e+"\n");testVal=false;} |
|---|
| 878 | if(testVal) |
|---|
| 879 | {childToProcess=child;break;}}} |
|---|
| 880 | else if(child.data.name=="spry:default") |
|---|
| 881 | defaultChild=child;}} |
|---|
| 882 | if(!childToProcess&&defaultChild) |
|---|
| 883 | childToProcess=defaultChild;if(childToProcess) |
|---|
| 884 | this.processTokenChildren(outputArr,childToProcess,processContext);} |
|---|
| 885 | else if(token.data.name=="spry:state") |
|---|
| 886 | {var testVal=true;if(!token.data.regionState||token.data.regionState==this.currentState) |
|---|
| 887 | this.processTokenChildren(outputArr,token,processContext);} |
|---|
| 888 | else |
|---|
| 889 | {Spry.Debug.reportError("processTokens(): Unknown processing instruction: "+token.data.name+"\n");return"";} |
|---|
| 890 | break;case Spry.Data.Region.Token.VALUE_TOKEN:var dataSet=token.dataSet;if(!dataSet&&this.dataSets&&this.dataSets.length>0&&this.dataSets[0]) |
|---|
| 891 | {dataSet=this.dataSets[0];} |
|---|
| 892 | if(!dataSet) |
|---|
| 893 | {Spry.Debug.reportError("processTokens(): Value reference has no data set specified: "+token.regionStr+"\n");return"";} |
|---|
| 894 | var dsContext=processContext.getDataSetContext(dataSet);if(!dsContext) |
|---|
| 895 | {Spry.Debug.reportError("processTokens: Failed to get a data set context!\n");return"";} |
|---|
| 896 | var ds=dsContext.getDataSet();if(token.data=="ds_RowNumber") |
|---|
| 897 | outputArr.push(dsContext.getRowIndex());else if(token.data=="ds_RowNumberPlus1") |
|---|
| 898 | outputArr.push(dsContext.getRowIndex()+1);else if(token.data=="ds_RowCount") |
|---|
| 899 | outputArr.push(dsContext.getNumRows());else if(token.data=="ds_UnfilteredRowCount") |
|---|
| 900 | outputArr.push(dsContext.getNumRows(true));else if(token.data=="ds_CurrentRowNumber") |
|---|
| 901 | outputArr.push(ds.getRowNumber(ds.getCurrentRow()));else if(token.data=="ds_CurrentRowID") |
|---|
| 902 | outputArr.push(ds.getCurrentRowID());else if(token.data=="ds_EvenOddRow") |
|---|
| 903 | outputArr.push((dsContext.getRowIndex()%2)?Spry.Data.Region.evenRowClassName:Spry.Data.Region.oddRowClassName);else if(token.data=="ds_SortOrder") |
|---|
| 904 | outputArr.push(ds.getSortOrder());else if(token.data=="ds_SortColumn") |
|---|
| 905 | outputArr.push(ds.getSortColumn());else |
|---|
| 906 | {var curDataSetRow=dsContext.getCurrentRow();if(curDataSetRow) |
|---|
| 907 | outputArr.push(curDataSetRow[token.data]);} |
|---|
| 908 | break;default:Spry.Debug.reportError("processTokens(): Invalid token type: "+token.regionStr+"\n");break;}};Spry.Data.Region.prototype.transform=function() |
|---|
| 909 | {if(this.data&&!this.tokens) |
|---|
| 910 | this.tokens=this.tokenizeData(this.data);if(!this.tokens) |
|---|
| 911 | return"";processContext=new Spry.Data.Region.ProcessingContext(this);if(!processContext) |
|---|
| 912 | return"";var outputArr=[""];this.processTokens(outputArr,this.tokens,processContext);return outputArr.join("");};Spry.Data.Region.PI={};Spry.Data.Region.PI.instructions={};Spry.Data.Region.PI.buildOpenTagForValueAttr=function(ele,piName,attrName) |
|---|
| 913 | {if(!ele||!piName) |
|---|
| 914 | return"";var jsExpr="";try |
|---|
| 915 | {var testAttr=ele.attributes.getNamedItem(piName);if(testAttr&&testAttr.value) |
|---|
| 916 | jsExpr=Spry.Utils.encodeEntities(testAttr.value);} |
|---|
| 917 | catch(e){jsExpr="";} |
|---|
| 918 | if(!jsExpr) |
|---|
| 919 | {Spry.Debug.reportError(piName+" attribute requires a JavaScript expression that returns true or false!\n");return"";} |
|---|
| 920 | return"<"+Spry.Data.Region.PI.instructions[piName].tagName+" "+attrName+"=\""+jsExpr+"\">";};Spry.Data.Region.PI.buildOpenTagForTest=function(ele,piName) |
|---|
| 921 | {return Spry.Data.Region.PI.buildOpenTagForValueAttr(ele,piName,"test");};Spry.Data.Region.PI.buildOpenTagForState=function(ele,piName) |
|---|
| 922 | {return Spry.Data.Region.PI.buildOpenTagForValueAttr(ele,piName,"name");};Spry.Data.Region.PI.buildOpenTagForRepeat=function(ele,piName) |
|---|
| 923 | {if(!ele||!piName) |
|---|
| 924 | return"";var selectAttrStr="";try |
|---|
| 925 | {var selectAttr=ele.attributes.getNamedItem(piName);if(selectAttr&&selectAttr.value) |
|---|
| 926 | {selectAttrStr=selectAttr.value;selectAttrStr=selectAttrStr.replace(/\s/g,"");}} |
|---|
| 927 | catch(e){selectAttrStr="";} |
|---|
| 928 | if(!selectAttrStr) |
|---|
| 929 | {Spry.Debug.reportError(piName+" attribute requires a data set name!\n");return"";} |
|---|
| 930 | var testAttrStr="";try |
|---|
| 931 | {var testAttr=ele.attributes.getNamedItem("spry:test");if(testAttr) |
|---|
| 932 | {if(testAttr.value) |
|---|
| 933 | testAttrStr=" test=\""+Spry.Utils.encodeEntities(testAttr.value)+"\"";ele.attributes.removeNamedItem(testAttr.nodeName);}} |
|---|
| 934 | catch(e){testAttrStr="";} |
|---|
| 935 | return"<"+Spry.Data.Region.PI.instructions[piName].tagName+" select=\""+selectAttrStr+"\""+testAttrStr+">";};Spry.Data.Region.PI.buildOpenTagForContent=function(ele,piName) |
|---|
| 936 | {if(!ele||!piName) |
|---|
| 937 | return"";var dataRefStr="";try |
|---|
| 938 | {var contentAttr=ele.attributes.getNamedItem(piName);if(contentAttr&&contentAttr.value) |
|---|
| 939 | dataRefStr=Spry.Utils.encodeEntities(contentAttr.value);} |
|---|
| 940 | catch(e){dataRefStr="";} |
|---|
| 941 | if(!dataRefStr) |
|---|
| 942 | {Spry.Debug.reportError(piName+" attribute requires a data reference!\n");return"";} |
|---|
| 943 | return"<"+Spry.Data.Region.PI.instructions[piName].tagName+" dataref=\""+dataRefStr+"\">";};Spry.Data.Region.PI.buildOpenTag=function(ele,piName) |
|---|
| 944 | {return"<"+Spry.Data.Region.PI.instructions[piName].tagName+">";};Spry.Data.Region.PI.buildCloseTag=function(ele,piName) |
|---|
| 945 | {return"</"+Spry.Data.Region.PI.instructions[piName].tagName+">";};Spry.Data.Region.PI.instructions["spry:state"]={tagName:"spry:state",childrenOnly:false,getOpenTag:Spry.Data.Region.PI.buildOpenTagForState,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:if"]={tagName:"spry:if",childrenOnly:false,getOpenTag:Spry.Data.Region.PI.buildOpenTagForTest,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:repeat"]={tagName:"spry:repeat",childrenOnly:false,getOpenTag:Spry.Data.Region.PI.buildOpenTagForRepeat,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:repeatchildren"]={tagName:"spry:repeat",childrenOnly:true,getOpenTag:Spry.Data.Region.PI.buildOpenTagForRepeat,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:choose"]={tagName:"spry:choose",childrenOnly:true,getOpenTag:Spry.Data.Region.PI.buildOpenTag,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:when"]={tagName:"spry:when",childrenOnly:false,getOpenTag:Spry.Data.Region.PI.buildOpenTagForTest,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:default"]={tagName:"spry:default",childrenOnly:false,getOpenTag:Spry.Data.Region.PI.buildOpenTag,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.instructions["spry:content"]={tagName:"spry:content",childrenOnly:true,getOpenTag:Spry.Data.Region.PI.buildOpenTagForContent,getCloseTag:Spry.Data.Region.PI.buildCloseTag};Spry.Data.Region.PI.orderedInstructions=["spry:state","spry:if","spry:repeat","spry:repeatchildren","spry:choose","spry:when","spry:default","spry:content"];Spry.Data.Region.getTokensFromStr=function(str) |
|---|
| 946 | {if(!str) |
|---|
| 947 | return null;return str.match(/{[^}]+}/g);};Spry.Data.Region.processDataRefString=function(processingContext,regionStr,dataSetsToUse,isJSExpr) |
|---|
| 948 | {if(!regionStr) |
|---|
| 949 | return"";if(!processingContext&&!dataSetsToUse) |
|---|
| 950 | return regionStr;var resultStr="";var re=new RegExp("\\{([^\\}:]+::)?[^\\}]+\\}","g");var startSearchIndex=0;while(startSearchIndex<regionStr.length) |
|---|
| 951 | {var reArray=re.exec(regionStr);if(!reArray||!reArray[0]) |
|---|
| 952 | {resultStr+=regionStr.substr(startSearchIndex,regionStr.length-startSearchIndex);return resultStr;} |
|---|
| 953 | if(reArray.index!=startSearchIndex) |
|---|
| 954 | resultStr+=regionStr.substr(startSearchIndex,reArray.index-startSearchIndex);var dsName="";if(reArray[0].search(/^\{[^}:]+::/)!=-1) |
|---|
| 955 | dsName=reArray[0].replace(/^\{|::.*/g,"");var fieldName=reArray[0].replace(/^\{|.*::|\}/g,"");var row=null;if(processingContext) |
|---|
| 956 | {var dsContext=processingContext.getDataSetContext(dsName);if(fieldName=="ds_RowNumber") |
|---|
| 957 | {resultStr+=dsContext.getRowIndex();row=null;} |
|---|
| 958 | else if(fieldName=="ds_RowNumberPlus1") |
|---|
| 959 | {resultStr+=(dsContext.getRowIndex()+1);row=null;} |
|---|
| 960 | else if(fieldName=="ds_RowCount") |
|---|
| 961 | {resultStr+=dsContext.getNumRows();row=null;} |
|---|
| 962 | else if(fieldName=="ds_UnfilteredRowCount") |
|---|
| 963 | {resultStr+=dsContext.getNumRows(true);row=null;} |
|---|
| 964 | else if(fieldName=="ds_CurrentRowNumber") |
|---|
| 965 | {var ds=dsContext.getDataSet();resultStr+=ds.getRowNumber(ds.getCurrentRow());row=null;} |
|---|
| 966 | else if(fieldName=="ds_CurrentRowID") |
|---|
| 967 | {var ds=dsContext.getDataSet();resultStr+=""+ds.getCurrentRowID();row=null;} |
|---|
| 968 | else if(fieldName=="ds_EvenOddRow") |
|---|
| 969 | {resultStr+=(dsContext.getRowIndex()%2)?Spry.Data.Region.evenRowClassName:Spry.Data.Region.oddRowClassName;row=null;} |
|---|
| 970 | else if(fieldName=="ds_SortOrder") |
|---|
| 971 | {resultStr+=dsContext.getDataSet().getSortOrder();row=null;} |
|---|
| 972 | else if(fieldName=="ds_SortColumn") |
|---|
| 973 | {resultStr+=dsContext.getDataSet().getSortColumn();row=null;} |
|---|
| 974 | else |
|---|
| 975 | row=processingContext.getCurrentRowForDataSet(dsName);} |
|---|
| 976 | else |
|---|
| 977 | {var ds=dsName?dataSetsToUse[dsName]:dataSetsToUse[0];if(ds) |
|---|
| 978 | row=ds.getCurrentRow();} |
|---|
| 979 | if(row) |
|---|
| 980 | resultStr+=isJSExpr?Spry.Utils.escapeQuotesAndLineBreaks(""+row[fieldName]):row[fieldName];if(startSearchIndex==re.lastIndex) |
|---|
| 981 | {var leftOverIndex=reArray.index+reArray[0].length;if(leftOverIndex<regionStr.length) |
|---|
| 982 | resultStr+=regionStr.substr(leftOverIndex);break;} |
|---|
| 983 | startSearchIndex=re.lastIndex;} |
|---|
| 984 | return resultStr;};Spry.Data.Region.strToDataSetsArray=function(str,returnRegionNames) |
|---|
| 985 | {var dataSetsArr=new Array;var foundHash={};if(!str) |
|---|
| 986 | return dataSetsArr;str=str.replace(/\s+/g," ");str=str.replace(/^\s|\s$/g,"");var arr=str.split(/ /);for(var i=0;i<arr.length;i++) |
|---|
| 987 | {if(arr[i]&&!Spry.Data.Region.PI.instructions[arr[i]]) |
|---|
| 988 | {try{var dataSet=Spry.Data.getDataSetByName(arr[i]);if(!foundHash[arr[i]]) |
|---|
| 989 | {if(returnRegionNames) |
|---|
| 990 | dataSetsArr.push(arr[i]);else |
|---|
| 991 | dataSetsArr.push(dataSet);foundHash[arr[i]]=true;}} |
|---|
| 992 | catch(e){}}} |
|---|
| 993 | return dataSetsArr;};Spry.Data.Region.DSContext=function(dataSet,processingContext) |
|---|
| 994 | {var m_dataSet=dataSet;var m_processingContext=processingContext;var m_curRowIndexArray=[{rowIndex:-1}];var m_parent=null;var m_children=[];var getInternalRowIndex=function(){return m_curRowIndexArray[m_curRowIndexArray.length-1].rowIndex;};this.resetAll=function(){m_curRowIndexArray=[{rowIndex:m_dataSet.getCurrentRow()}]};this.getDataSet=function(){return m_dataSet;};this.getNumRows=function(unfiltered) |
|---|
| 995 | {var data=this.getCurrentState().data;return data?data.length:m_dataSet.getRowCount(unfiltered);};this.getData=function() |
|---|
| 996 | {var data=this.getCurrentState().data;return data?data:m_dataSet.getData();};this.setData=function(data) |
|---|
| 997 | {this.getCurrentState().data=data;};this.getCurrentRow=function() |
|---|
| 998 | {if(m_curRowIndexArray.length<2||getInternalRowIndex()<0) |
|---|
| 999 | return m_dataSet.getCurrentRow();var data=this.getData();var curRowIndex=getInternalRowIndex();if(curRowIndex<0||curRowIndex>data.length) |
|---|
| 1000 | {Spry.Debug.reportError("Invalid index used in Spry.Data.Region.DSContext.getCurrentRow()!\n");return null;} |
|---|
| 1001 | return data[curRowIndex];};this.getRowIndex=function() |
|---|
| 1002 | {var curRowIndex=getInternalRowIndex();if(curRowIndex>=0) |
|---|
| 1003 | return curRowIndex;return m_dataSet.getRowNumber(m_dataSet.getCurrentRow());};this.setRowIndex=function(rowIndex) |
|---|
| 1004 | {this.getCurrentState().rowIndex=rowIndex;var data=this.getData();var numChildren=m_children.length;for(var i=0;i<numChildren;i++) |
|---|
| 1005 | m_children[i].syncDataWithParentRow(this,rowIndex,data);};this.syncDataWithParentRow=function(parentDSContext,rowIndex,parentData) |
|---|
| 1006 | {var row=parentData[rowIndex];if(row) |
|---|
| 1007 | {nestedDS=m_dataSet.getNestedDataSetForParentRow(row);if(nestedDS) |
|---|
| 1008 | {var currentState=this.getCurrentState();currentState.data=nestedDS.getData();currentState.rowIndex=nestedDS.getCurrentRowNumber();var numChildren=m_children.length;for(var i=0;i<numChildren;i++) |
|---|
| 1009 | m_children[i].syncDataWithParentRow(this,currentState.rowIndex,currentState.data);}}};this.pushState=function() |
|---|
| 1010 | {var curState=this.getCurrentState();var newState=new Object;newState.rowIndex=curState.rowIndex;newState.data=curState.data;m_curRowIndexArray.push(newState);var numChildren=m_children.length;for(var i=0;i<numChildren;i++) |
|---|
| 1011 | m_children[i].pushState();};this.popState=function() |
|---|
| 1012 | {if(m_curRowIndexArray.length<2) |
|---|
| 1013 | {Spry.Debug.reportError("Stack underflow in Spry.Data.Region.DSContext.popState()!\n");return;} |
|---|
| 1014 | var numChildren=m_children.length;for(var i=0;i<numChildren;i++) |
|---|
| 1015 | m_children[i].popState();m_curRowIndexArray.pop();};this.getCurrentState=function() |
|---|
| 1016 | {return m_curRowIndexArray[m_curRowIndexArray.length-1];};this.addChild=function(childDSContext) |
|---|
| 1017 | {var numChildren=m_children.length;for(var i=0;i<numChildren;i++) |
|---|
| 1018 | {if(m_children[i]==childDSContext) |
|---|
| 1019 | return;} |
|---|
| 1020 | m_children.push(childDSContext);};};Spry.Data.Region.ProcessingContext=function(region) |
|---|
| 1021 | {this.region=region;this.dataSetContexts=[];if(region&®ion.dataSets) |
|---|
| 1022 | {var dsArray=region.dataSets.slice(0);var dsArrayLen=dsArray.length;for(var i=0;i<dsArrayLen;i++) |
|---|
| 1023 | {var ds=region.dataSets[i];while(ds&&ds.getParentDataSet) |
|---|
| 1024 | {var doesExist=false;ds=ds.getParentDataSet();if(ds&&this.indexOf(dsArray,ds)==-1) |
|---|
| 1025 | dsArray.push(ds);}} |
|---|
| 1026 | for(i=0;i<dsArray.length;i++) |
|---|
| 1027 | this.dataSetContexts.push(new Spry.Data.Region.DSContext(dsArray[i],this));var dsContexts=this.dataSetContexts;var numDSContexts=dsContexts.length;for(i=0;i<numDSContexts;i++) |
|---|
| 1028 | {var dsc=dsContexts[i];var ds=dsc.getDataSet();if(ds.getParentDataSet) |
|---|
| 1029 | {var parentDS=ds.getParentDataSet();if(parentDS) |
|---|
| 1030 | {var pdsc=this.getDataSetContext(parentDS);if(pdsc)pdsc.addChild(dsc);}}}}};Spry.Data.Region.ProcessingContext.prototype.indexOf=function(arr,item) |
|---|
| 1031 | {if(arr) |
|---|
| 1032 | {var arrLen=arr.length;for(var i=0;i<arrLen;i++) |
|---|
| 1033 | if(arr[i]==item) |
|---|
| 1034 | return i;} |
|---|
| 1035 | return-1;};Spry.Data.Region.ProcessingContext.prototype.getDataSetContext=function(dataSet) |
|---|
| 1036 | {if(!dataSet) |
|---|
| 1037 | {if(this.dataSetContexts.length>0) |
|---|
| 1038 | return this.dataSetContexts[0];return null;} |
|---|
| 1039 | if(typeof dataSet=='string') |
|---|
| 1040 | {dataSet=Spry.Data.getDataSetByName(dataSet);if(!dataSet) |
|---|
| 1041 | return null;} |
|---|
| 1042 | for(var i=0;i<this.dataSetContexts.length;i++) |
|---|
| 1043 | {var dsc=this.dataSetContexts[i];if(dsc.getDataSet()==dataSet) |
|---|
| 1044 | return dsc;} |
|---|
| 1045 | return null;};Spry.Data.Region.ProcessingContext.prototype.getCurrentRowForDataSet=function(dataSet) |
|---|
| 1046 | {var dsc=this.getDataSetContext(dataSet);if(dsc) |
|---|
| 1047 | return dsc.getCurrentRow();return null;};Spry.Data.Region.Token=function(tokenType,dataSet,data,regionStr) |
|---|
| 1048 | {var self=this;this.tokenType=tokenType;this.dataSet=dataSet;this.data=data;this.regionStr=regionStr;this.parent=null;this.children=null;};Spry.Data.Region.Token.prototype.addChild=function(child) |
|---|
| 1049 | {if(!child) |
|---|
| 1050 | return;if(!this.children) |
|---|
| 1051 | this.children=new Array;this.children.push(child);child.parent=this;};Spry.Data.Region.Token.LIST_TOKEN=0;Spry.Data.Region.Token.STRING_TOKEN=1;Spry.Data.Region.Token.PROCESSING_INSTRUCTION_TOKEN=2;Spry.Data.Region.Token.VALUE_TOKEN=3;Spry.Data.Region.Token.PIData=function(piName,data,jsExpr,regionState) |
|---|
| 1052 | {var self=this;this.name=piName;this.data=data;this.jsExpr=jsExpr;this.regionState=regionState;};Spry.Utils.addLoadListener(function(){setTimeout(function(){if(Spry.Data.initRegionsOnLoad)Spry.Data.initRegions();},0);}); |
|---|