Spry.Data.HTMLDataSet=function(_1,_2,_3){
this.sourceElementID=_2;
this.sourceElement=null;
this.sourceWasInitialized=false;
this.usesExternalFile=(_1!=null)?true:false;
this.firstRowAsHeaders=true;
this.useColumnsAsRows=false;
this.columnNames=null;
this.hideDataSourceElement=true;
this.rowSelector=null;
this.dataSelector=null;
this.removeUnbalancedRows=true;
this.tableModeEnabled=true;
Spry.Data.HTTPSourceDataSet.call(this,_1,_3);
};
Spry.Data.HTMLDataSet.prototype=new Spry.Data.HTTPSourceDataSet();
Spry.Data.HTMLDataSet.prototype.constructor=Spry.Data.HTMLDataSet;
Spry.Data.HTMLDataSet.prototype.getDataRefStrings=function(){
var _4=[];
if(this.url){
_4.push(this.url);
}
if(typeof this.sourceElementID=="string"){
_4.push(this.sourceElementID);
}
return _4;
};
Spry.Data.HTMLDataSet.prototype.setDisplay=function(_5,_6){
if(_5){
_5.style.display=_6;
}
};
Spry.Data.HTMLDataSet.prototype.initDataSource=function(_7){
if(!this.loadDependentDataSets()){
return;
}
if(!this.usesExternalFile){
this.setSourceElement();
if(this.hideDataSourceElement){
this.setDisplay(this.sourceElement,"none");
}
}
};
Spry.Data.HTMLDataSet.prototype.setSourceElement=function(_8){
this.sourceElement=null;
if(!this.sourceElementID){
if(_8){
this.sourceElement=_8;
}else{
this.hideDataSourceElement=false;
this.sourceElement=document.body;
}
return;
}
var _9=Spry.Data.Region.processDataRefString(null,this.sourceElementID,this.dataSetsForDataRefStrings);
if(!this.usesExternalFile){
this.sourceElement=Spry.$(_9);
}else{
if(_8){
var _a=false;
var _b=Spry.Utils.getNodesByFunc(_8,function(_c){
if(_a){
return false;
}
if(_c.nodeType!=1){
return false;
}
if(_c.id&&_c.id.toLowerCase()==_9.toLowerCase()){
_a=true;
return true;
}
});
this.sourceElement=_b[0];
}
}
if(!this.sourceElement){
Spry.Debug.reportError("Spry.Data.HTMLDataSet: '"+_9+"' is not a valid element ID");
}
};
Spry.Data.HTMLDataSet.prototype.getSourceElement=function(){
return this.sourceElement;
};
Spry.Data.HTMLDataSet.prototype.getSourceElementID=function(){
return this.sourceElementID;
};
Spry.Data.HTMLDataSet.prototype.setSourceElementID=function(_d){
if(this.sourceElementID!=_d){
this.sourceElementID=_d;
this.recalculateDataSetDependencies();
this.dataWasLoaded=false;
}
};
Spry.Data.HTMLDataSet.prototype.getDataSelector=function(){
return this.dataSelector;
};
Spry.Data.HTMLDataSet.prototype.setDataSelector=function(_e){
if(this.dataSelector!=_e){
this.dataSelector=_e;
this.dataWasLoaded=false;
}
};
Spry.Data.HTMLDataSet.prototype.getRowSelector=function(){
return this.rowSelector;
};
Spry.Data.HTMLDataSet.prototype.setRowSelector=function(_f){
if(this.rowSelector!=_f){
this.rowSelector=_f;
this.dataWasLoaded=false;
}
};
Spry.Data.HTMLDataSet.prototype.loadDataIntoDataSet=function(_10){
var _11=_10;
_11=Spry.Data.HTMLDataSet.cleanupSource(_11);
var div=document.createElement("div");
div.id="htmlsource"+this.internalID;
div.innerHTML=_11;
this.setSourceElement(div);
if(this.sourceElement){
var _13=this.getDataFromSourceElement();
if(_13){
this.dataHash=_13.dataHash;
this.data=_13.data;
}
}
this.dataWasLoaded=true;
div=null;
};
Spry.Data.HTMLDataSet.prototype.loadDependentDataSets=function(){
if(this.hasDataRefStrings){
var _14=true;
for(var i=0;i<this.dataSetsForDataRefStrings.length;i++){
var ds=this.dataSetsForDataRefStrings[i];
if(ds.getLoadDataRequestIsPending()){
_14=false;
}else{
if(!ds.getDataWasLoaded()){
ds.loadData();
_14=false;
}
}
}
if(!_14){
return false;
}
}
return true;
};
Spry.Data.HTMLDataSet.prototype.loadData=function(){
this.cancelLoadData();
this.initDataSource();
var _17=this;
if(!this.usesExternalFile){
this.notifyObservers("onPreLoad");
this.dataHash=new Object;
this.data=new Array;
this.dataWasLoaded=false;
this.unfilteredData=null;
this.curRowID=0;
this.pendingRequest=new Object;
this.pendingRequest.timer=setTimeout(function(){
_17.pendingRequest=null;
var _18=_17.getDataFromSourceElement();
if(_18){
_17.dataHash=_18.dataHash;
_17.data=_18.data;
}
_17.dataWasLoaded=true;
_17.disableNotifications();
_17.filterAndSortData();
_17.enableNotifications();
_17.notifyObservers("onPostLoad");
_17.notifyObservers("onDataChanged");
},0);
}else{
var url=Spry.Data.Region.processDataRefString(null,this.url,this.dataSetsForDataRefStrings);
var _1a=this.requestInfo.postData;
if(_1a&&(typeof _1a)=="string"){
_1a=Spry.Data.Region.processDataRefString(null,_1a,this.dataSetsForDataRefStrings);
}
this.notifyObservers("onPreLoad");
this.dataHash=new Object;
this.data=new Array;
this.dataWasLoaded=false;
this.unfilteredData=null;
this.curRowID=0;
var req=this.requestInfo.clone();
req.url=url;
req.postData=_1a;
this.pendingRequest=new Object;
this.pendingRequest.data=Spry.Data.HTTPSourceDataSet.LoadManager.loadData(req,this,this.useCache);
}
};
Spry.Data.HTMLDataSet.cleanupSource=function(_1c){
_1c=_1c.replace(/<(img|script|link|frame|iframe|input)([^>]+)>/gi,function(a,b,c){
return "<"+b+c.replace(/\b(src|href)\s*=/gi,function(a,b){
return "spry_"+b+"=";
})+">";
});
return _1c;
};
Spry.Data.HTMLDataSet.undoCleanupSource=function(_22){
_22=_22.replace(/<(img|script|link|frame|iframe|input)([^>]+)>/gi,function(a,b,c){
return "<"+b+c.replace(/\bspry_(src|href)\s*=/gi,function(a,b){
return b+"=";
})+">";
});
return _22;
};
Spry.Data.HTMLDataSet.normalizeColumnName=function(_28){
if(_28){
_28=_28.replace(/(?:^[\s\t]+|[\s\t]+$)/gi,"");
_28=_28.replace(/<\/?([a-z]+)([^>]+)>/gi,"");
_28=_28.replace(/[\s\t]+/gi,"_");
}
return _28;
};
Spry.Data.HTMLDataSet.prototype.getDataFromSourceElement=function(){
if(!this.sourceElement){
return null;
}
var _29;
var _2a=(this.tableModeEnabled&&this.sourceElement.nodeName.toLowerCase()=="table");
if(_2a){
_29=this.getDataFromHTMLTable();
}else{
_29=this.getDataFromNestedStructure();
}
if(!_29){
return null;
}
if(this.useColumnsAsRows){
var _2b=new Array;
for(var _2c=0;_2c<_29.length;_2c++){
var row=_29[_2c];
for(var _2e=0;_2e<row.length;_2e++){
if(!_2b[_2e]){
_2b[_2e]=new Array;
}
_2b[_2e][_2c]=row[_2e];
}
}
_29=_2b;
}
var _2f=new Object();
_2f.dataHash=new Object;
_2f.data=new Array;
if(_29.length==0){
return _2f;
}
var _30=0;
for(var i=0;i<_29.length;i++){
var len=_29[i].length;
if(_30<len){
_30=len;
}
}
var _33=new Array;
var _34=_29[0];
for(var _2e=0;_2e<_30;_2e++){
if(_2a&&this.firstRowAsHeaders){
_33[_2e]=Spry.Data.HTMLDataSet.normalizeColumnName(_34[_2e]);
}
if(!_33[_2e]){
_33[_2e]="column"+_2e;
}
}
if(this.columnNames&&this.columnNames.length){
var _35=(_30<this.columnNames.length)?_30:this.columnNames.length;
for(var i=0;i<_35;i++){
if(this.columnNames[i]){
_33[i]=this.columnNames[i];
}
}
}
var _36=0;
var _37=(_2a&&this.firstRowAsHeaders)?1:0;
for(var _2c=_37;_2c<_29.length;_2c++){
var row=_29[_2c];
if(this.removeUnbalancedRows&&_33.length!=row.length){
continue;
}
var _38={};
for(var _2e=0;_2e<_33.length;_2e++){
var _39=row[_2e];
_38[_33[_2e]]=(typeof _39=="undefined")?"":_39;
}
_38["ds_RowID"]=_36++;
_2f.dataHash[_38["ds_RowID"]]=_38;
_2f.data.push(_38);
}
return _2f;
};
Spry.Data.HTMLDataSet.getElementChildren=function(_3a){
var _3b=[];
var _3c=_3a.firstChild;
while(_3c){
if(_3c.nodeType==1){
_3b.push(_3c);
}
_3c=_3c.nextSibling;
}
return _3b;
};
Spry.Data.HTMLDataSet.prototype.getDataFromHTMLTable=function(){
var _3d=this.sourceElement.tHead;
var _3e=this.sourceElement.tBodies[0];
var _3f=[];
var _40=[];
if(_3d){
_3f=Spry.Data.HTMLDataSet.getElementChildren(_3d);
}
if(_3e){
_40=Spry.Data.HTMLDataSet.getElementChildren(_3e);
}
var _41=new Array;
var _42=_3f.concat(_40);
if(this.rowSelector){
_42=Spry.Data.HTMLDataSet.applySelector(_42,this.rowSelector);
}
for(var _43=0;_43<_42.length;_43++){
var row=_42[_43];
var _45;
if(_41[_43]){
_45=_41[_43];
}else{
_45=new Array;
}
var _46=0;
var _47=row.cells;
if(this.dataSelector){
_47=Spry.Data.HTMLDataSet.applySelector(_47,this.dataSelector);
}
for(var _48=0;_48<_47.length;_48++){
var _49=_47[_48];
var _4a=_48+_46;
while(_45[_4a]){
_46++;
_4a++;
}
var _4b=Spry.Data.HTMLDataSet.undoCleanupSource(_49.innerHTML);
_45[_4a]=_4b;
var _4c=_49.colSpan;
if(_4c==0){
_4c=1;
}
var _4d=_46;
for(var _4e=1;_4e<_4c;_4e++){
_46++;
_4a=_48+_46;
_45[_4a]=_4b;
}
var _4f=_49.rowSpan;
if(_4f==0){
_4f=1;
}
for(var _50=1;_50<_4f;_50++){
nextRowIndex=_43+_50;
var _51;
if(_41[nextRowIndex]){
_51=_41[nextRowIndex];
}else{
_51=new Array;
}
var _52=_4d;
for(var _4e=0;_4e<_4c;_4e++){
_4a=_48+_52;
_51[_4a]=_4b;
_52++;
}
_41[nextRowIndex]=_51;
}
}
_41[_43]=_45;
}
return _41;
};
Spry.Data.HTMLDataSet.prototype.getDataFromNestedStructure=function(){
var _53=new Array;
if(this.sourceElementID&&!this.rowSelector&&!this.dataSelector){
_53[0]=[Spry.Data.HTMLDataSet.undoCleanupSource(this.sourceElement.innerHTML)];
return _53;
}
var _54=this;
var _55=[];
if(!this.rowSelector){
_55=[this.sourceElement];
}else{
_55=Spry.Utils.getNodesByFunc(this.sourceElement,function(_56){
return Spry.Data.HTMLDataSet.evalSelector(_56,_54.sourceElement,_54.rowSelector);
});
}
for(var _57=0;_57<_55.length;_57++){
var row=_55[_57];
var _59=[];
if(!this.dataSelector){
_59=[row];
}else{
_59=Spry.Utils.getNodesByFunc(row,function(_5a){
return Spry.Data.HTMLDataSet.evalSelector(_5a,row,_54.dataSelector);
});
}
_53[_57]=new Array;
for(var _5b=0;_5b<_59.length;_5b++){
_53[_57][_5b]=Spry.Data.HTMLDataSet.undoCleanupSource(_59[_5b].innerHTML);
}
}
return _53;
};
Spry.Data.HTMLDataSet.applySelector=function(_5c,_5d,_5e){
var _5f=[];
for(var idx=0;idx<_5c.length;idx++){
var _61=_5c[idx];
if(Spry.Data.HTMLDataSet.evalSelector(_61,_5e?_5e:_61.parentNode,_5d)){
_5f.push(_61);
}
}
return _5f;
};
Spry.Data.HTMLDataSet.evalSelector=function(_62,_63,_64){
if(_62.nodeType!=1){
return false;
}
if(_62==_63){
return false;
}
var _65=_64.split(",");
for(var idx=0;idx<_65.length;idx++){
var _67=_65[idx].replace(/^\s+/,"").replace(/\s+$/,"");
var _68=null;
var _69=null;
var id=null;
var _6b=true;
if(_67.substring(0,1)==">"){
if(_62.parentNode!=_63){
_6b=false;
}else{
_67=_67.substring(1).replace(/^\s+/,"");
}
}
if(_6b){
_68=_67.toLowerCase();
if(_67.indexOf(".")!=-1){
var _6c=_67.split(".");
_68=_6c[0];
_69=_6c[1];
}else{
if(_67.indexOf("#")!=-1){
var _6c=_67.split("#");
_68=_6c[0];
id=_6c[1];
}
}
}
if(_6b&&_68!=""&&_68!="*"){
if(_62.nodeName.toLowerCase()!=_68){
_6b=false;
}
}
if(_6b&&id&&_62.id!=id){
_6b=false;
}
if(_6b&&_69&&_62.className.search(new RegExp("\\b"+_69+"\\b","i"))==-1){
_6b=false;
}
if(_6b){
return true;
}
}
return false;
};

