Spry.Data.NestedXMLDataSet=function(a,b,c){this.parentDataSet=a;this.xpath=b;this.nestedDataSets=[];this.nestedDataSetsHash={};this.currentDS=null;this.currentDSAncestor=null;this.options=c;this.ignoreOnDataChanged=false;this.entityEncodeStrings=a?a.entityEncodeStrings:true;Spry.Data.DataSet.call(this,c);
a.addObserver(this);};Spry.Data.NestedXMLDataSet.prototype=new Spry.Data.DataSet();Spry.Data.NestedXMLDataSet.prototype.constructor=Spry.Data.NestedXMLDataSet.prototype;Spry.Data.NestedXMLDataSet.prototype.getParentDataSet=function(){return this.parentDataSet;};Spry.Data.NestedXMLDataSet.prototype.getNestedDataSetForParentRow=function(f){var d=f.ds_XMLNode;
if(d&&this.nestedDataSets){if(this.currentDSAncestor&&this.currentDSAncestor==d){return this.currentDS;}var b=this.nestedDataSets;var a=b.length;for(var c=0;c<a;c++){var e=b[c];if(e&&d==e.ancestor){return e.dataSet;}}}return null;};Spry.Data.NestedXMLDataSet.prototype.getNestedXMLDataSetsArray=function(){var d=[];
if(this.nestedDataSets){var a=this.nestedDataSets;var b=this.nestedDataSets.length;for(var c=0;c<b;c++){d.push(a[c].dataSet);}}return d;};Spry.Data.NestedXMLDataSet.prototype.onDataChanged=function(a,b){if(!this.ignoreOnDataChanged){this.loadData();}};Spry.Data.NestedXMLDataSet.prototype.onCurrentRowChanged=function(c,d){this.notifyObservers("onPreParentContextChange");
this.currentDS=null;this.currentDSAncestor=null;var b=this.parentDataSet.getCurrentRow();if(b){var a=this.getNestedDataSetForParentRow(b);if(a){this.currentDS=a;this.currentDSAncestor=b.ds_XMLNode;}}this.notifyObservers("onDataChanged");this.notifyObservers("onPostParentContextChange");this.ignoreOnDataChanged=false;
};Spry.Data.NestedXMLDataSet.prototype.onPostParentContextChange=Spry.Data.NestedXMLDataSet.prototype.onCurrentRowChanged;Spry.Data.NestedXMLDataSet.prototype.onPreParentContextChange=function(a,b){this.ignoreOnDataChanged=true;};Spry.Data.NestedXMLDataSet.prototype.filterAndSortData=function(){if(this.filterDataFunc){this.filterData(this.filterDataFunc,true);
}if(this.distinctOnLoad){this.distinct(this.distinctFieldsOnLoad);}if(this.keepSorted&&this.getSortColumn()){this.sort(this.lastSortColumns,this.lastSortOrder);}else{if(this.sortOnLoad){this.sort(this.sortOnLoad,this.sortOrderOnLoad);}}if(this.filterFunc){this.filter(this.filterFunc,true);}};Spry.Data.NestedXMLDataSet.prototype.loadData=function(){var p=this.parentDataSet;
if(!p||p.getLoadDataRequestIsPending()||!this.xpath){return;}if(!p.getDataWasLoaded()){p.loadData();return;}this.notifyObservers("onPreLoad");this.nestedDataSets=[];this.currentDS=null;this.currentDSAncestor=null;this.data=[];this.dataHash={};var q=this;var d=[p];if(p.getNestedXMLDataSetsArray){d=p.getNestedXMLDataSetsArray();
}var c=null;var l=p.getCurrentRow();if(l){c=l.ds_XMLNode;}var n=d.length;for(var g=0;g<n;g++){var o=d[g];var e=o.getData(true);if(e){var k=e.length;for(var f=0;f<k;f++){var r=e[f];if(r&&r.ds_XMLNode){var b=new Spry.Data.DataSet(this.options);for(var h in this.columnTypes){b.setColumnType(h,this.columnTypes[h]);
}var a=Spry.Data.XMLDataSet.getRecordSetFromXMLDoc(r.ds_XMLNode,this.xpath,false,this.entityEncodeStrings);b.setDataFromArray(a.data,true);var m=new Object;m.ancestor=r.ds_XMLNode;m.dataSet=b;this.nestedDataSets.push(m);if(r.ds_XMLNode==c){this.currentDS=b;this.currentDSAncestor=this.ds_XMLNode;}b.addObserver(function(s,i,j){if(i==q.currentDS){setTimeout(function(){q.notifyObservers(s,j);
},0);}});}}}}this.pendingRequest=new Object;this.dataWasLoaded=false;this.pendingRequest.timer=setTimeout(function(){q.pendingRequest=null;q.dataWasLoaded=true;q.disableNotifications();q.filterAndSortData();q.enableNotifications();q.notifyObservers("onPostLoad");q.notifyObservers("onDataChanged");},0);
};Spry.Data.NestedXMLDataSet.prototype.getData=function(a){if(this.currentDS){return this.currentDS.getData(a);}return[];};Spry.Data.NestedXMLDataSet.prototype.getRowCount=function(a){if(this.currentDS){return this.currentDS.getRowCount(a);}return 0;};Spry.Data.NestedXMLDataSet.prototype.getRowByID=function(a){if(this.currentDS){return this.currentDS.getRowByID(a);
}return undefined;};Spry.Data.NestedXMLDataSet.prototype.getRowByRowNumber=function(a,b){if(this.currentDS){return this.currentDS.getRowByRowNumber(a,b);}return null;};Spry.Data.NestedXMLDataSet.prototype.getCurrentRow=function(){if(this.currentDS){return this.currentDS.getCurrentRow();}return null;};
Spry.Data.NestedXMLDataSet.prototype.setCurrentRow=function(a){if(this.currentDS){return this.currentDS.setCurrentRow(a);}};Spry.Data.NestedXMLDataSet.prototype.getRowNumber=function(a){if(this.currentDS){return this.currentDS.getRowNumber(a);}return 0;};Spry.Data.NestedXMLDataSet.prototype.getCurrentRowNumber=function(){if(this.currentDS){return this.currentDS.getCurrentRowNumber();
}return 0;};Spry.Data.NestedXMLDataSet.prototype.getCurrentRowID=function(){if(this.currentDS){return this.currentDS.getCurrentRowID();}return 0;};Spry.Data.NestedXMLDataSet.prototype.setCurrentRowNumber=function(a){if(this.currentDS){return this.currentDS.setCurrentRowNumber(a);}};Spry.Data.NestedXMLDataSet.prototype.findRowsWithColumnValues=function(c,b,a){if(this.currentDS){return this.currentDS.findRowsWithColumnValues(c,b,a);
}return b?null:[];};Spry.Data.NestedXMLDataSet.prototype.setColumnType=function(e,c){if(e){Spry.Data.DataSet.prototype.setColumnType.call(this,e,c);var d=this.nestedDataSets;var a=d.length;for(var b=0;b<a;b++){d[b].dataSet.setColumnType(e,c);}}};Spry.Data.NestedXMLDataSet.prototype.getColumnType=function(a){if(this.currentDS){return this.currentDS.getColumnType(a);
}return"string";};Spry.Data.NestedXMLDataSet.prototype.distinct=function(d){if(d){var c=this.nestedDataSets;var a=c.length;for(var b=0;b<a;b++){c[b].dataSet.distinct(d);}}};Spry.Data.NestedXMLDataSet.prototype.sort=function(f,c){if(f){var e=this.nestedDataSets;var a=e.length;for(var b=0;b<a;b++){e[b].dataSet.sort(f,c);
}if(a>0){var d=e[0].dataSet;this.lastSortColumns=d.lastSortColumns.slice(0);this.lastSortOrder=d.lastSortOrder;}}};Spry.Data.NestedXMLDataSet.prototype.filterData=function(d,c){this.filterDataFunc=d;var e=this.nestedDataSets;var a=e.length;for(var b=0;b<a;b++){e[b].dataSet.filterData(d,c);}};Spry.Data.NestedXMLDataSet.prototype.filter=function(d,c){this.filterFunc=d;
var e=this.nestedDataSets;var a=e.length;for(var b=0;b<a;b++){e[b].dataSet.filter(d,c);}};Spry.Data.NestedXMLDataSet.prototype.setXPath=function(a){if(this.xpath!=a){this.xpath=a;this.loadData();}};
