/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.grid.enhanced.plugins.Exporter"],["require","dojox.grid.enhanced._Plugin"],["require","dojox.grid._RowSelector"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.grid.enhanced.plugins.Exporter"]){_4._hasResource["dojox.grid.enhanced.plugins.Exporter"]=true;_4.provide("dojox.grid.enhanced.plugins.Exporter");_4.require("dojox.grid.enhanced._Plugin");_4.require("dojox.grid._RowSelector");_4.declare("dojox.grid.enhanced.plugins.Exporter",_6.grid.enhanced._Plugin,{name:"exporter",constructor:function(_7,_8){this.grid=_7;this.formatter=(_8&&_4.isObject(_8))&&_8.exportFormatter;this._mixinGrid();},_mixinGrid:function(){var g=this.grid;g.exportTo=_4.hitch(this,this.exportTo);g.exportGrid=_4.hitch(this,this.exportGrid);g.exportSelected=_4.hitch(this,this.exportSelected);g.setExportFormatter=_4.hitch(this,this.setExportFormatter);},setExportFormatter:function(_9){this.formatter=_9;},exportGrid:function(_a,_b,_c){if(_4.isFunction(_b)){_c=_b;_b={};}if(!_4.isString(_a)||!_4.isFunction(_c)){return;}_b=_b||{};var g=this.grid,_d=this,_e=this._getExportWriter(_a,_b.writerArgs),_f=(_b.fetchArgs&&_4.isObject(_b.fetchArgs))?_b.fetchArgs:{},_10=_f.onComplete;if(g.store){_f.onComplete=function(_11,_12){if(_10){_10(_11,_12);}_c(_d._goThroughGridData(_11,_e));};_f.sort=_f.sort||g.getSortProps();g._storeLayerFetch(_f);}else{var _13=_f.start||0,_14=_f.count||-1,_15=[];for(var i=_13;i!=_13+_14&&i<g.rowCount;++i){_15.push(g.getItem(i));}_c(this._goThroughGridData(_15,_e));}},exportSelected:function(_16,_17){if(!_4.isString(_16)){return "";}var _18=this._getExportWriter(_16,_17);return this._goThroughGridData(this.grid.selection.getSelected(),_18);},_buildRow:function(_19,_1a){var _1b=this;_4.forEach(_19._views,function(_1c,_1d){_19.view=_1c;_19.viewIdx=_1d;if(_1a.beforeView(_19)){_4.forEach(_1c.structure.cells,function(_1e,_1f){_19.subrow=_1e;_19.subrowIdx=_1f;if(_1a.beforeSubrow(_19)){_4.forEach(_1e,function(_20,_21){if(_19.isHeader&&_1b._isSpecialCol(_20)){_19.spCols.push(_20.index);}_19.cell=_20;_19.cellIdx=_21;_1a.handleCell(_19);});_1a.afterSubrow(_19);}});_1a.afterView(_19);}});},_goThroughGridData:function(_22,_23){var _24=this.grid,_25=_4.filter(_24.views.views,function(_26){return !(_26 instanceof _6.grid._RowSelector);}),_27={"grid":_24,"isHeader":true,"spCols":[],"_views":_25,"colOffset":(_25.length<_24.views.views.length?-1:0)};if(_23.beforeHeader(_24)){this._buildRow(_27,_23);_23.afterHeader();}_27.isHeader=false;if(_23.beforeContent(_22)){_4.forEach(_22,function(_28,_29){_27.row=_28;_27.rowIdx=_29;if(_23.beforeContentRow(_27)){this._buildRow(_27,_23);_23.afterContentRow(_27);}},this);_23.afterContent();}return _23.toString();},_isSpecialCol:function(_2a){return _2a.isRowSelector||_2a instanceof _6.grid.cells.RowIndex;},_getExportWriter:function(_2b,_2c){var _2d,cls,_2e=_6.grid.enhanced.plugins.Exporter;if(_2e.writerNames){_2d=_2e.writerNames[_2b.toLowerCase()];cls=_4.getObject(_2d);if(cls){var _2f=new cls(_2c);_2f.formatter=this.formatter;return _2f;}else{throw new Error("Please make sure class \""+_2d+"\" is required.");}}throw new Error("The writer for \""+_2b+"\" has not been registered.");}});_6.grid.enhanced.plugins.Exporter.registerWriter=function(_30,_31){var _32=_6.grid.enhanced.plugins.Exporter;_32.writerNames=_32.writerNames||{};_32.writerNames[_30]=_31;};_6.grid.EnhancedGrid.registerPlugin(_6.grid.enhanced.plugins.Exporter);}}};});