Spry.Data.NestedXMLDataSet=function(c,a,b){this.parentDataSet=c;this.xpath=a;this.nestedDataSets=[];this.nestedDataSetsHash={};this.currentDS=null;this.currentDSAncestor=null;this.options=b;this.ignoreOnDataChanged=false;this.entityEncodeStrings=c?c.entityEncodeStrings:true;Spry.Data.DataSet.call(this,b);c.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 e=f.ds_XMLNode;if(e&&this.nestedDataSets){if(this.currentDSAncestor&&this.currentDSAncestor==e){return this.currentDS}var c=this.nestedDataSets;var b=c.length;for(var a=0;a<b;a++){var d=c[a];if(d&&e==d.ancestor){return d.dataSet}}}return null};Spry.Data.NestedXMLDataSet.prototype.getNestedXMLDataSetsArray=function(){var c=[];if(this.nestedDataSets){var b=this.nestedDataSets;var d=this.nestedDataSets.length;for(var a=0;a<d;a++){c.push(b[a].dataSet)}}return c};Spry.Data.NestedXMLDataSet.prototype.onDataChanged=function(a,b){if(!this.ignoreOnDataChanged){this.loadData()}};Spry.Data.NestedXMLDataSet.prototype.onCurrentRowChanged=function(b,d){this.notifyObservers("onPreParentContextChange");this.currentDS=null;this.currentDSAncestor=null;var c=this.parentDataSet.getCurrentRow();if(c){var a=this.getNestedDataSetForParentRow(c);if(a){this.currentDS=a;this.currentDSAncestor=c.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 g=this.parentDataSet;if(!g||g.getLoadDataRequestIsPending()||!this.xpath){return}if(!g.getDataWasLoaded()){g.loadData();return}this.notifyObservers("onPreLoad");this.nestedDataSets=[];this.currentDS=null;this.currentDSAncestor=null;this.data=[];this.dataHash={};var q=this;var o=[g];if(g.getNestedXMLDataSetsArray){o=g.getNestedXMLDataSetsArray()}var m=null;var r=g.getCurrentRow();if(r){m=r.ds_XMLNode}var e=o.length;for(var k=0;k<e;k++){var b=o[k];var f=b.getData(true);if(f){var h=f.length;for(var n=0;n<h;n++){var l=f[n];if(l&&l.ds_XMLNode){var a=new Spry.Data.DataSet(this.options);for(var d in this.columnTypes){a.setColumnType(d,this.columnTypes[d])}var p=Spry.Data.XMLDataSet.getRecordSetFromXMLDoc(l.ds_XMLNode,this.xpath,false,this.entityEncodeStrings);a.setDataFromArray(p.data,true);var c=new Object;c.ancestor=l.ds_XMLNode;c.dataSet=a;this.nestedDataSets.push(c);if(l.ds_XMLNode==m){this.currentDS=a;this.currentDSAncestor=this.ds_XMLNode}a.addObserver(function(j,i,s){if(i==q.currentDS){setTimeout(function(){q.notifyObservers(j,s)},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(b,c,a){if(this.currentDS){return this.currentDS.findRowsWithColumnValues(b,c,a)}return c?null:[]};Spry.Data.NestedXMLDataSet.prototype.setColumnType=function(c,b){if(c){Spry.Data.DataSet.prototype.setColumnType.call(this,c,b);var e=this.nestedDataSets;var d=e.length;for(var a=0;a<d;a++){e[a].dataSet.setColumnType(c,b)}}};Spry.Data.NestedXMLDataSet.prototype.getColumnType=function(a){if(this.currentDS){return this.currentDS.getColumnType(a)}return"string"};Spry.Data.NestedXMLDataSet.prototype.distinct=function(b){if(b){var d=this.nestedDataSets;var c=d.length;for(var a=0;a<c;a++){d[a].dataSet.distinct(b)}}};Spry.Data.NestedXMLDataSet.prototype.sort=function(d,c){if(d){var f=this.nestedDataSets;var e=f.length;for(var b=0;b<e;b++){f[b].dataSet.sort(d,c)}if(e>0){var a=f[0].dataSet;this.lastSortColumns=a.lastSortColumns.slice(0);this.lastSortOrder=a.lastSortOrder}}};Spry.Data.NestedXMLDataSet.prototype.filterData=function(e,c){this.filterDataFunc=e;var b=this.nestedDataSets;var d=b.length;for(var a=0;a<d;a++){b[a].dataSet.filterData(e,c)}};Spry.Data.NestedXMLDataSet.prototype.filter=function(e,c){this.filterFunc=e;var b=this.nestedDataSets;var d=b.length;for(var a=0;a<d;a++){b[a].dataSet.filter(e,c)}};Spry.Data.NestedXMLDataSet.prototype.setXPath=function(a){if(this.xpath!=a){this.xpath=a;this.loadData()}};
