Subversion Repositories wimsdev

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.         DynAPI Distribution
  3.         DataSource Class
  4.  
  5.         The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
  6.  
  7.         requires: dynapi.util.IOElement
  8. */
  9.  
  10. DataSource = function(url,method,ioelement){
  11.        
  12.         this.EventObject=EventObject;
  13.         this.EventObject();
  14.        
  15.         this.clsid=dynapi.functions.getGUID();
  16.         DataSource.all[this.clsid]=this;
  17.        
  18.         this.src=null; 
  19.         this.dataobjects={};
  20.        
  21.         this._resetProperties();
  22.  
  23.         this.setSource(url,method,ioelement);
  24. };
  25.  
  26. /* Prototype */
  27. var p = dynapi.setPrototype('DataSource','EventObject');
  28.  
  29. // Private Methods
  30. p._boundObject = function(o,f){
  31.         if(!f || !o) return;
  32.         if(!o._clsid) o._clsid=DataSource.increment();
  33.         this.dataobjects[o._clsid]=f;
  34.         o.__iDataSource=this;
  35.         DataSource.allDataObjects[o._clsid]=o;
  36. };
  37. p._fieldManager = function(mode,fld,value){
  38.         var i,rt,con,fldname;
  39.         // set or get field values from local recordset or bound object
  40.         if(mode=='GET' && !this._modRec && this.record) return this.record[fld];
  41.         else {
  42.                 if(mode=='SET' && this.record) this.record[fld]=value; 
  43.                 for(i in this.dataobjects){
  44.                         if (!fld||fld==this.dataobjects[i]){
  45.                                 fldname=this.dataobjects[i];
  46.                                 con=DataSource.allDataObjects[i];
  47.                                 if(con) {
  48.                                         if(mode=='SET' && con._setDSValue) {
  49.                                                 con._setDSValue(value,fldname);
  50.                                         }else if(mode=='GET' && con._getDSValue) {
  51.                                                 return con._getDSValue();
  52.                                         }
  53.  
  54.                                 }
  55.                         }
  56.                 }      
  57.         }
  58. };
  59. p._resetProperties=function(){
  60.         this.record=null;
  61.         this.recordSet=[];
  62.         this.rowCount=0;                        // total records
  63.         this.rowIndex=-1;                       // current record index(0 to rowCount)
  64.         this.pageSize=1;                        // number of recordSet per page
  65.         this.pageCount=0;                       // total pages
  66.         this.pageNumber=0;                      // current page number (1 to pageCount)
  67.         this.pageRIS=-1;                        // starting index for a page
  68.         this.pageRIE=-1;                        // ending index for a page
  69.         this.isConnected=false;
  70. };
  71. p._send = function(act,data,params){
  72.         var r,fn,cargo={id:this.clsid,action:act,data:data};;
  73.         params =(params)? params:{};
  74.         if(!this.src||!this.isConnected) {
  75.                 this.invokeEvent('alert',null,'DataSource: Connection failed.');
  76.                 return;
  77.         }
  78.         this.invokeEvent('request');
  79.         if(this.webservice && !this.wsSync) {
  80.                 // Web Service - Async
  81.                 fn=DataSource.fnSODAResponse;
  82.                 if(this._ticket) this.ioelement.cancel(this._ticket); // cancel any previous requests
  83.                 if(act=='fetchpage') this._ticket=this.webservice.call(act,[this.pageNumber,this.pageSize,params.pageType],fn,cargo);
  84.                 else this._ticket=this.webservice.call(act,[this.rowIndex,data],fn,cargo);
  85.         }
  86.         else if(this.webservice && this.wsSync) {
  87.                 // Web Service - Sync
  88.                 if(act=='fetchpage') r=this.webservice.call(act,[this.pageNumber,this.pageSize,params.pageType],false);
  89.                 else r=this.webservice.call(act,[this.rowIndex,data],false);
  90.                 if(r.error) this.invokeEvent('alert',null,'DataSource: '+r.error.text);
  91.                 else {
  92.                         data=r.value;
  93.                         if(!data) return;
  94.                         DataSource.fnProcessResponse(cargo,data);
  95.                 }
  96.         }
  97.         else {
  98.                 // HTTP GET & POST - Async
  99.                 fn=DataSource.fnGETPOSTResponse;               
  100.                 data=(data)? data:{};
  101.                 data.dataAction = act;
  102.                 if(act!='fetchpage') data.dataRowIndex=this.rowIndex;
  103.                 else {
  104.                         data.pageSize = this.pageSize;
  105.                         data.pageNumber = this.pageNumber;
  106.                         data.pageType=params.pageType;
  107.                 }
  108.                 if(this._ticket) this.ioelement.cancel(this._ticket); // cancel any previous requests
  109.                 if(this.method=='get') this._ticket=this.ioelement.get(this.src,data,fn,cargo);
  110.                 else this._ticket=this.ioelement.post(this.src,data,fn,cargo);
  111.         }
  112. };
  113. p._unboundObject = function(o){
  114.         if(!o._clsid) return;
  115.         delete this.dataobjects[o._clsid];
  116.         delete DataSource.allDataObjects[o._clsid];
  117. };
  118.  
  119.  
  120. // Public Methods -------------------------------
  121.  
  122. p.addRecord = function(){
  123.         this._modRec=true;
  124.         this._oldRowIndex=this.rowIndex;
  125.         this._send('addrow');
  126. };
  127. p.cancelAction = function(norefresh){
  128.         if (this._cancelAct=='waiting') this._cancelAct=true; // cancel submit()
  129.         else {
  130.                 // cancel either editRecord() or addRecord() operation
  131.                 this._cancelAct=true;
  132.                 if (this._modRec && this._oldRowIndex!=this.rowIndex) this.rowIndex=this._oldRowIndex;
  133.                 this._oldRowIndex=null;
  134.                 this._modRec=false;
  135.                 if(!norefresh) this.refresh();
  136.         }
  137. };
  138. p.connect = function(fn,useWebService,useSync,uid,pwd){ // connects to the data source using the SODA web service
  139.         this.ws_uid=uid; this.ws_pwd=pwd;
  140.         this.wsSync=useSync;
  141.         this._resetProperties();
  142.         if(!useWebService) {
  143.                 if(typeof(fn)!='function') return;
  144.                 this.isConnected=true;
  145.                 fn(this,true);
  146.         }else if(IOElement.SODA){
  147.                 this._callback=fn;
  148.                 if(typeof(useWebService)=='string') {                  
  149.                         // use an existing web service
  150.                         var s,et;
  151.                         this.webservice=this.ioelement[useWebService];
  152.                         if (this.webservice && this.webservice.isConnected) {
  153.                                 this.isConnected=true;
  154.                                 s=true; et='';
  155.                         }else{
  156.                                 this.webservice=null;
  157.                                 s=false; et='Service not found';
  158.                         }
  159.                         this._callback(this,s,et);
  160.                 }else{
  161.                         // create a new web service
  162.                         var me=this;           
  163.                         var cbFn=function(ws,s,et){
  164.                                 if(s==true) {
  165.                                         me.webservice=ws;
  166.                                         me.isConnected=true;
  167.                                 }
  168.                                 // notify caller of connection
  169.                                 me._callback(me,s,et);
  170.                         }
  171.                         this.ioelement.createWebService(this.clsid,this.src,cbFn,useSync,uid,pwd,this.method);
  172.                 }
  173.         }
  174. };
  175. p.deleteRecord=function(){
  176.         this._send('deleterow');
  177. };
  178. p.editRecord = function(){
  179.         if(this._modRec) return;
  180.         this._modRec=true;
  181.         this._oldRowIndex=this.rowIndex;
  182. };
  183. p.getField = function(fld){return this._fieldManager('GET',fld)};
  184. p.getAbsolutePage = function() {return this.pageNumber};
  185. p.getRecordPosition = function(){return this.rowIndex};
  186. p.getPageCount = function() {return this.pageCount};
  187. p.getPageSize = function() {return this.pageSize};
  188. p.getPageStart = function(){return this.pageRIS};
  189. p.getPageEnd = function(){return this.pageRIE};
  190. p.getRecordCount = function(){return this.rowCount};
  191. p.getRecord = function(n){
  192.         var i, data={};
  193.         if(!this._modRec || (n!=null && n!=this.rowIndex)) data=(n==null)?this.record:this.recordSet[n];
  194.         else {
  195.                 for (i in this.dataobjects){
  196.                         f=this.dataobjects[i];
  197.                         con=DataSource.allDataObjects[i];
  198.                         data[f]=con._getDSValue();
  199.                 }
  200.         }
  201.         return data;
  202. };
  203. p.isEditMode = function(){return this._modRec};
  204. p.moveFirst = function(){
  205.         if(this._modRec) this.cancelAction(true);
  206.         if(this.pageSize<=1) this._send('movefirst');
  207.         else{
  208.                 var r,cp=this.pageNumber; //current page
  209.                 var fetch=(cp!=1 || !this.recordSet.length);
  210.                 this.rowIndex=0;               
  211.                 this.pageNumber=1;
  212.                 if (fetch) this._send('fetchpage',null,{pageType:'firstpage'});
  213.                 else {
  214.                         r=this.recordSet[0];
  215.                         this.setRecord(r);
  216.                 }
  217.         }
  218. };
  219. p.moveLast = function(){
  220.         if(this._modRec) this.cancelAction(true);
  221.         if(this.pageSize<=1) this._send('movelast');
  222.         else{
  223.                 var cp=this.pageNumber;         //current page
  224.                 var lp=this.pageCount;  // last page
  225.                 var fetch=(lp!=cp || !this.recordSet.length);
  226.                 this.pageNumber=lp;
  227.                 this.rowIndex=this.rowCount-1;
  228.                 if (fetch) {
  229.                         this.rowIndex=-2;       // force rowIndex to be set to pageRIE
  230.                         this._send('fetchpage',null,{pageType:'lastpage'});
  231.                 }else {
  232.                         r=this.recordSet[this.rowIndex];
  233.                         this.setRecord(r);
  234.                 }
  235.         }
  236. };
  237. p.moveNext = function(){
  238.         if(this._modRec) this.cancelAction(true);
  239.         this._modRec=false;
  240.         if(this.pageSize<=1) this._send('movenext');
  241.         else{
  242.                 var ps,cp,np,fetch;
  243.                 var r=(this.rowIndex+1);
  244.                 ps=this.pageSize;
  245.                 cp=this.pageNumber; //current page
  246.                 if(r<1) np=1;           // new page
  247.                 else np=this.pageNumber=parseInt(r/ps)+1;
  248.                 fetch=(np!=cp || np>this.pageCount || !this.recordSet.length);
  249.                 if(r>=this.rowCount) {r=this.rowCount-1; fetch=true;}
  250.                 this.rowIndex=r;
  251.                 if (fetch) this._send('fetchpage',null,{pageType:'normalpage'});
  252.                 else {
  253.                         r=this.recordSet[r];
  254.                         this.setRecord(r);
  255.                 }
  256.         }
  257. };
  258. p.movePrev = function(){
  259.         if(this._modRec) this.cancelAction(true);
  260.         if(this.pageSize<=1) this._send('moveprev');
  261.         else{
  262.                 var ps,cp,np,fetch;
  263.                 var r=(this.rowIndex-1);
  264.                 ps=this.pageSize;
  265.                 cp=this.pageNumber; //current page
  266.                 if(r<1) np=1;   // new page
  267.                 else np=this.pageNumber=parseInt(r/ps)+1;
  268.                 fetch=(np!=cp || np<1 || !this.recordSet.length);
  269.                 if(r<0) {r=0; fetch=true;}
  270.                 this.rowIndex=r;
  271.                 if (fetch) this._send('fetchpage',null,{pageType:'normalpage'});
  272.                 else {
  273.                         r=this.recordSet[r];
  274.                         this.setRecord(r);
  275.                 }
  276.         }
  277. };
  278. p.retry = function() {
  279.         if(this._ticket) this.ioelement.retry(this._ticket);
  280.         else if(!this.isConnected) this.ioelement.retry();
  281. };
  282. p.refresh = function(fld){
  283.         var record=this.record;
  284.         if(!fld||!record) this.setRecordPosition(this.rowIndex);
  285.         else if(record){
  286.                 // refresh field from local cached data record
  287.                 this._fieldManager('SET',fld,record[fld]);
  288.         }
  289. };
  290. p.setAbsolutePage = function(n) {
  291.         var cp=this.pageNumber;
  292.         var np=parseInt(n);    
  293.         if(np>0 && np!=cp) {
  294.                 this.rowIndex=-1; // force rowIndex to be set on the new page
  295.                 this.pageNumber=np;
  296.                 this._send('fetchpage');
  297.         }
  298. };
  299. p.setField = function(fld,value){
  300.         this._fieldManager('SET',fld,value);
  301. };
  302. p.setPageSize = function(n) {
  303.         this.pageSize=parseInt(n);
  304.         if(this.pageSize<1) this.pageSize=1;
  305.         this.pageNumber=0; // this will force moveFirst() to reload page
  306.         this.moveFirst();
  307. };
  308. p.setRecord = function(data){
  309.         var vl,con,i,fld;
  310.         if(!data) return;
  311.         this.recordSet[this.rowIndex] = this.record = data;
  312.         for(i in this.dataobjects){
  313.                 fld=this.dataobjects[i];
  314.                 con=DataSource.allDataObjects[i];
  315.                 if(con){
  316.                         vl=data[fld];
  317.                         con._setDSValue(vl);
  318.                 }
  319.         };
  320.         this.invokeEvent('recordchange');
  321. };
  322. p.setRecordPosition = function(n) {
  323.         this.rowIndex=parseInt(n);
  324.         if(this._modRec) this.cancelAction(true);
  325.         if(this.pageSize<=1) this._send('moveto');
  326.         else {
  327.                 var ps,cp,np,fetch;
  328.                 var r=this.rowIndex;
  329.                 ps=this.pageSize;
  330.                 cp=this.pageNumber; //current page
  331.                 if(r<1) np=1;           // new page
  332.                 else np=this.pageNumber=parseInt(r/ps)+1;
  333.                 fetch=(np!=cp || np>this.pageCount || !this.recordSet.length);
  334.                 if(r>=this.rowCount) {r=this.rowCount-1; fetch=true;}
  335.                 this.rowIndex=r;
  336.                 if (fetch) this._send('fetchpage',null,{pageType:'normalpage'});
  337.                 else {
  338.                         r=this.recordSet[r];
  339.                         this.setRecord(r);
  340.                 }
  341.         }
  342. };
  343. p.setSource = function(url,method,ioelement){
  344.         this.src=url;
  345.         if(method) method=(method+'').toLowerCase();
  346.         if(method || !this.method) this.method=(method=='post'||method=='get')? method:'post';
  347.         if(ioelement) this.ioelement=ioelement;
  348.         else if(!this.ioelement) this.ioelement=IOElement.getSharedIO();               
  349. };
  350. p.submit = function(){
  351.         if (!this._modRec) this.invokeEvent('alert',null,'DataSource: Submit action canceled');
  352.         else {
  353.                 var data = this.getRecord();
  354.                 this._cancelAct='waiting';
  355.                 this.invokeEvent('validate',null,data);
  356.                 if(this._cancelAct==true) return;
  357.                 this._cancelAct=false;
  358.                 this._send('submitrow',data);
  359.         }
  360. };
  361.  
  362.  
  363. /* Non-Prototype */
  364. DataSource._cnt=0;
  365. DataSource.all={};
  366. DataSource.allDataObjects={};
  367. DataSource.increment = function(){return 'dsObject'+(this._cnt++)};
  368. DataSource._getFORMInput = function(){return this.value};
  369. DataSource._setFORMInput = function(d){this.value=d};
  370. DataSource._getFORMImage = function(){return this.src};
  371. DataSource._setFORMImage = function(d){if(this.src) this.src=d;};
  372. DataSource._getFORMSelect = function(){
  373.         var i,d=[];
  374.         for(i=0;i<this.options.length;i++) {
  375.                 if(this.options[i].selected) d[d.length]=this.options[i].value;
  376.         };
  377.         return d.join(',');
  378. };
  379. DataSource._setFORMSelect = function(d){
  380.         var i,a,o,ov={};
  381.         if (typeof(d)=='object'){
  382.                 // clear <select> menu and display name/value pairs
  383.                 while(this.length>0) this.remove(0)
  384.                 for(i in d){
  385.                         this.add(new Option(i,d[i]));
  386.                 }
  387.         }else {
  388.                 // select values from <select> menu
  389.                 a=(d+'').split(',');
  390.                 for(i=0;i<a.length;i++) ov[a[i]]=true;
  391.                 for(i=0;i<this.options.length;i++) {
  392.                         o=this.options[i];
  393.                         if(ov[o.value]) o.selected=true;
  394.                         else  o.selected=false;
  395.                 };
  396.         }
  397. };
  398. DataSource._getFORMCheckBox = function(){
  399.         if (!this.length) {
  400.                 if(this.checked) return this.value;
  401.         }else {
  402.                 var i,chkv=[];
  403.                 for(i=0;i<this.length;i++) {
  404.                         if(this[i].checked) chkv[chkv.length]=this[i].value;
  405.                 };     
  406.                 return chkv.join(',');
  407.         }
  408. };
  409. DataSource._setFORMCheckBox = function(d){
  410.         if (!this.length) {
  411.                 if(d==this.value) this.checked=true;
  412.                 else this.checked=false;
  413.         }else {
  414.                 var i,chk,chkv={};
  415.                 var a=(d+'').split(',');
  416.                 for(i=0;i<a.length;i++) chkv[a[i]]=true;
  417.                 for(i=0;i<this.length;i++) {
  418.                         chk=this[i];
  419.                         if(chkv[chk.value]) chk.checked=true;
  420.                         else  chk.checked=false;
  421.                 };     
  422.         }
  423. };
  424. DataSource._getFORMRadio= function(){
  425.         if (!this.length) {
  426.                 if(this.checked) return this.value;
  427.         }else {
  428.                 for(var i=0;i<this.length;i++) {
  429.                         if(this[i].checked) return this[i].value;
  430.                 };     
  431.         }
  432. };
  433. DataSource._setFORMRadio= function(d){
  434.         if (!this.length) {
  435.                 if(d==this.value) this.checked=true;
  436.                 else this.checked=false;
  437.         }else{
  438.                 var i,rb;
  439.                 for(i=0;i<this.length;i++) {           
  440.                         rb=this[i];
  441.                         if(d==rb.value) rb.checked=true;
  442.                         else rb.checked=false;
  443.                 };     
  444.         }
  445. };
  446. DataSource._GetDataSource = function(){ return this.__iDataSource};
  447. DataSource._SetDataSource = function(ds,field){
  448.         if(ds && ds._boundObject) ds._boundObject(this,field);
  449. };
  450. DataSource.IsFormElm=function(o){
  451.         var ot,type=(o && o.type)? o.type+'':'';
  452.         ot=type.replace(/hidden|textarea|text|button|submit|image|select|checkbox|radio/,'');
  453.         if(type && ot!=type) return true;
  454.         else return false;
  455. };
  456. DataSource.createBoundObject = function(o,getfn,setfn){
  457.         if (typeof(o)=='object'){
  458.                 if(!getfn && !setfn && this.IsFormElm(o)){      // check if form element                       
  459.                         var tp=(o.type+'').toLowerCase();
  460.                         if(tp=='image') {
  461.                                 getfn=this._getFORMImage;
  462.                                 setfn=this._setFORMImage;
  463.                         }else if(tp.indexOf('select')==0) {
  464.                                 getfn=this._getFORMSelect;
  465.                                 setfn=this._setFORMSelect;
  466.                         }else if(tp=='checkbox') {
  467.                                 getfn=this._getFORMCheckBox;
  468.                                 setfn=this._setFORMCheckBox;
  469.                         }else if(tp=='radio') {
  470.                                 getfn=this._getFORMRadio;
  471.                                 setfn=this._setFORMRadio;                      
  472.                         }else if (tp=='text'||tp=='textarea'||tp=='hidden'||tp=='button'||tp=='submit'){
  473.                                 getfn=this._getFORMInput;
  474.                                 setfn=this._setFORMInput;
  475.                         }
  476.                 }else if(o.src && !getfn && !setfn) { // check if image object
  477.                         getfn=this._getFORMImage;
  478.                         setfn=this._setFORMImage;
  479.                 }
  480.                 if(getfn && setfn){
  481.                         o._getDSValue = getfn;
  482.                         o._setDSValue = setfn;
  483.                         o.getDataSource = DataSource._GetDataSource;
  484.                         o.setDataSource = DataSource._SetDataSource;
  485.                 }
  486.         }
  487.         return o;
  488. };
  489. DataSource.boundFormElements = function(frm,ds){
  490.         var i,elm,elmName,elmType,il={};
  491.         for (i=0;i<frm.elements.length;i++){
  492.                 elm=frm.elements[i];
  493.                 elmName=elm.name;
  494.                 elmType=elm.type;
  495.                 if(!il[elmName]){                      
  496.                         fld=(elm.fieldname)? elm.fieldname:elmName;
  497.                         if(frm[elmName].length && (elmType=='radio'||elmType=='checkbox')) {
  498.                                 il[elmName]=true;
  499.                                 elm=frm[elmName];
  500.                                 if(!elm.type) elm.type=elmType;
  501.                         }
  502.                         elm=DataSource.createBoundObject(elm);
  503.                         elm.setDataSource(ds,fld);
  504.                 }
  505.         }
  506. };
  507.  
  508. // CallBack Functions
  509. DataSource.fnProcessResponse = function(cargo,data){
  510.         var ds=DataSource.all[cargo.id];       
  511.         if(!ds) return;
  512.         ds._ticket=null;
  513.         if(cargo.action=='submitrow'){
  514.                 // data should be set to true if all went well
  515.                 if(data) ds.recordSet[ds.rowIndex]=cargo.data;
  516.                 ds.invokeEvent('submit',null,data);
  517.                 ds.invokeEvent('response');
  518.         }else if(cargo.action=='fetchpage'){
  519.                 var rowStart=data.dataRowIndex;
  520.                 var fieldnames=data.fieldnames;
  521.                 var fieldvalues=data.fieldvalues;
  522.                 if(!fieldnames||!fieldvalues) return;
  523.                 ds.pageCount=0;
  524.                 ds.pageRIS=rowStart;
  525.                 ds.pageRIE=rowStart+(ds.pageSize-1);
  526.                 ds.pageNumber=parseInt(ds.pageRIS/ds.pageSize)+1
  527.                 ds.rowCount=data.dataRowCount;
  528.                 if(ds.pageRIE>=ds.rowCount) ds.pageRIE=ds.rowCount-1;
  529.                 if(ds.rowCount==null) ds.rowCount=0;
  530.                 if(ds.rowCount>0) ds.pageCount=parseInt((ds.rowCount-1)/ds.pageSize)+1;
  531.                 if(ds.rowIndex==-2) ds.rowIndex=ds.pageRIE; // set rowIndex to RIS if -2 or to RIE if <0 or >=rowCount
  532.                 else if(ds.rowIndex<0||ds.rowIndex>=data.dataRowCount) ds.rowIndex=ds.pageRIS;
  533.                 var r,c,record;
  534.                 for(r=0;r<fieldvalues.length;r++){
  535.                         if(fieldvalues[r]){
  536.                                 record={}
  537.                                 for(c=0;c<fieldnames.length;c++){
  538.                                         record[fieldnames[c]]=fieldvalues[r][c];
  539.                                 }
  540.                                 ds.recordSet[r+rowStart]=record;
  541.                         }
  542.                 }
  543.                 ds.setRecord(ds.recordSet[ds.rowIndex]);
  544.                 ds.invokeEvent('response');
  545.         }else {
  546.                 // after a deleterow reload the current page
  547.                 if(cargo.action=='deleterow' && ds.pageSize>1) ds._send('fetchpage');
  548.                 else{
  549.                         ds.rowCount = ds.pageCount = data.dataRowCount;
  550.                         ds.rowIndex = ds.pageRIS = ds.pageRIE = data.dataRowIndex;
  551.                         if(ds.rowCount==null) ds.rowCount=-1;
  552.                         ds.setRecord(data);
  553.                         ds.invokeEvent('response');
  554.                 }
  555.         }
  556. };
  557. DataSource.fnGETPOSTResponse = function(e,s){
  558.         var ds,data,cargo;
  559.         var o=e.getSource();
  560.         if(!s){
  561.                 cargo=o.getCargo(true);
  562.                 ds=DataSource.all[cargo.id];   
  563.                 ds.invokeEvent('alert',null,'DataSource: Server Timeout');
  564.                 return;                
  565.         }
  566.         cargo=o.getCargo();
  567.         data = o.getVariable('record');
  568.         if(!data) return;
  569.         DataSource.fnProcessResponse(cargo,data);
  570. };
  571. DataSource.fnSODAResponse = function(e){
  572.         var ds,data,cargo;
  573.         var o=e.getSource();
  574.         var r=o.getResponse();
  575.         if (r.error) {
  576.                 cargo=o.getCargo(true);
  577.                 ds=DataSource.all[cargo.id];   
  578.                 ds.invokeEvent('alert',null,'DataSource: Server Timeout - '+r.error.text);
  579.                 return;
  580.         }
  581.         cargo=o.getCargo();
  582.         data=r.value;
  583.         if(!data) return;
  584.         DataSource.fnProcessResponse(cargo,data);
  585. };
  586.  
  587. // Data source functions for DynLayer
  588. DynLayer.prototype._getDSValue = function(){return this.getHTML()};
  589. DynLayer.prototype._setDSValue = function(d){
  590.         this.setHTML(d);
  591. };
  592. DynLayer.prototype.getDataSource = DataSource._GetDataSource;
  593. DynLayer.prototype.setDataSource = function(ds,field){
  594.         if(ds && ds._boundObject) {
  595.                 this._clsid=this.id;
  596.                 ds._boundObject(this,field);
  597.         }
  598. };
  599.