/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.dijit.editing.TemplatePicker"],["require","dojo.data.ItemFileReadStore"],["require","dojox.grid.DataGrid"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.dijit.editing.TemplatePicker"]){_4._hasResource["esri.dijit.editing.TemplatePicker"]=true;_4.provide("esri.dijit.editing.TemplatePicker");_4.require("dojo.data.ItemFileReadStore");_4.require("dojox.grid.DataGrid");(function(){var _7=[_4.moduleUrl("esri.dijit.editing","css/TemplatePicker.css"),_4.moduleUrl("dojox","grid/resources/Grid.css")];var _8=document.getElementsByTagName("head").item(0),_9;for(var i=0,il=_7.length;i<il;i++){_9=document.createElement("link");_9.type="text/css";_9.rel="stylesheet";_9.href=_7[i].toString();_8.appendChild(_9);}}());_4.declare("esri.dijit.editing.TemplatePicker",[_5._Widget,_5._Templated],{widgetsInTemplate:true,templateString:"<div class=\"templatePicker\">\r\n\r\n  <table dojoType=\"dojox.grid.DataGrid\" noDataMessage=\"${emptyMessage}\" selectionMode=\"none\" autoHeight=\"${_rows}\" autoWidth=\"${_autoWidth}\"\r\n         query=\"{ query: '*' }\" dojoAttachPoint=\"grid\" class=\"grid\">\r\n  </table>\r\n  \r\n</div>\r\n",basePath:_4.moduleUrl("esri.dijit.editing"),featureLayers:null,items:null,grouping:true,showTooltip:false,maxLabelLength:0,rows:4,columns:3,surfaceWidth:30,surfaceHeight:30,emptyMessage:"",_uniqueId:{id:0},_assumedCellWidth:90,_initialAutoWidth:300,_initialAutoHeight:200,_ieTimer:150,constructor:function(_a,_b){_a=_a||{};if(!_a.items&&!_a.featureLayers){console.error("TemplatePicker: please provide 'featureLayers' or 'items' parameter in the constructor");}this._dojo14x=(_4.version.minor>=4);this._itemWidgets={};this.emptyMessage=_a.emptyMessage||_4.getObject("bundle.widgets.templatePicker.creationDisabled",false,esri)||"";},postMixInProperties:function(){this.inherited(arguments);this._preprocess();},startup:function(){this.inherited(arguments);if(this.rows==="auto"&&this.columns==="auto"){var _c=_4.contentBox(this.domNode);if(!_c.w){this.domNode.style.width=this._initialAutoWidth+"px";}if(!_c.h){this.domNode.style.height=this._initialAutoHeight+"px";}_c=_4.contentBox(this.domNode);this._columns=Math.floor(_c.w/this._assumedCellWidth)||1;}this._applyGridPatches();this._setGridLayout();_4.connect(this.grid,"onRowClick",this,this._rowClicked);this._setGridData();this._toggleTooltip();if(_4.isIE<9){this._repaintItems=_4.hitch(this,this._repaintItems);setTimeout(this._repaintItems,this._ieTimer);}},destroy:function(){this.showTooltip=false;this._toggleTooltip();this.featureLayers=this.items=this.grid=this._flItems=this._itItems=this._groupRowIndices=this._selectedCell=this._selectedInfo=this._selectedItem=null;this.inherited(arguments);},getSelected:function(){return this._selectedCell?this._selectedItem:null;},clearSelection:function(){var _d=this._selectedCell,_e=this._selectedInfo;if(_d){this._rowClicked({cellNode:_d,rowIndex:_e.selRow,cellIndex:_e.selCol});}},update:function(_f){var _10=(this.rows==="auto"&&this.columns==="auto"&&_f)?true:false;var _11=this.grid;if(_10){var _12=this.domNode,box=_4.contentBox(_12),id=_12.id;this._columns=Math.floor((box.w-_11.views.views[0].getScrollbarWidth())/_4.coords(_4.query("#"+id+".templatePicker div.item")[0].parentNode).w);this._columns=this._columns||1;}var _13=this._rows;this._preprocess();var _14=this._rows;this._setGridLayout();this._setGridData();if(_14!==_13){_11.set("autoHeight",this._rows,false);}if(_10){_11._resize({w:box.w,h:box.h});_11.viewsHeaderNode.style.display="none";}else{_11.update();}this._toggleTooltip();var _15=this,_16=this.getSelected();if(_16){_11.store.fetch({onComplete:function(its){var _17=_15._locate(_16,_15._selectedInfo,its);var _18=_17&&_11.views.views[0].getCellNode(_17[0],_17[1]);if(_18){_15._rowClicked({cellNode:_18,rowIndex:_17[0],cellIndex:_17[1]},true);}}});}if(_4.isIE<9){setTimeout(this._repaintItems,this._ieTimer);}var _19=this.featureLayers,_1a=this.items;if((!_19||!_19.length)&&(!_1a||!_1a.length)&&_11&&this.emptyMessage){_11.showMessage(this.emptyMessage);}},onSelectionChange:function(){},_preprocess:function(){if(this.items){this.grouping=false;}this._autoWidth=false;if(this.rows==="auto"||this.columns==="auto"){this._autoWidth=true;}var _1b;if(this.featureLayers){_1b=this._flItems=this._getItemsFromLayers(this.featureLayers);}else{_1b=this._itItems=this._getItemsFromItems(this.items);}if(this.rows==="auto"&&this.columns==="auto"){if(!this._started){this._rows=false;this._columns=null;this._autoWidth=false;}return;}var len=0;this._rows=this.rows;this._columns=this.columns;if(this.rows==="auto"){if(this.featureLayers){if(this.grouping){len=_1b.length;_4.forEach(_1b,function(_1c){len+=Math.ceil(_1c.length/this.columns);},this);}else{_4.forEach(_1b,function(_1d){len+=_1d.length;},this);len=Math.ceil(len/this.columns);}}else{len=Math.ceil(_1b.length/this.columns);}this._rows=len;}else{if(this.columns==="auto"){if(this.featureLayers){if(this.grouping){len=3;}else{_4.forEach(_1b,function(_1e){len+=_1e.length;},this);len=Math.ceil(len/this.rows);}}else{len=Math.ceil(_1b.length/this.rows);}this._columns=len;}}},_applyGridPatches:function(){var _1f=this.grid;var _20=_1f.adaptWidth;_1f.adaptWidth=function(){var _21=this.views.views;for(var i=0,_22;_22=_21[i];i++){_4.style(_22.headerNode,"display","block");}_20.apply(this,arguments);for(var i=0,_22;_22=_21[i];i++){_4.style(_22.headerNode,"display","none");}};if(this._dojo14x){if(this.rows!=="auto"&&this.columns!=="auto"){var _23=_4.connect(_1f,"_onFetchComplete",this,function(){_4.disconnect(_23);this.grid.set("autoHeight",this._rows);});}_4.connect(_1f,"_onDelete",this,this._destroyItems);_4.connect(_1f,"_clearData",this,this._destroyItems);_4.connect(_1f,"destroy",this,this._destroyItems);var _24=_1f.focus;if(_24&&_24.findAndFocusGridCell){_24.findAndFocusGridCell=function(){return false;};}}},_setGridLayout:function(){var _25=function(_26){return function(_27,_28){return this._cellGet(_26,_27,_28);};};var _29=_4.hitch(this,this._cellFormatter);var _2a=[],_2b=this._columns;for(var i=0;i<_2b;i++){_2a.push({field:"cell"+i,get:_4.hitch(this,_25(i)),formatter:_29});}var _2c={cells:[_2a]};if(this.grouping){var _2d={field:"groupName",colSpan:_2b,get:_4.hitch(this,this._cellGetGroup),formatter:_4.hitch(this,this._cellGroupFormatter)};_2c.cells.push([_2d]);}var _2e=this.grid;_2e.set("structure",_2c);},_setGridData:function(){var _2f=[];if(this.grouping){this._groupRowIndices=[];var _30,_31,_32=this._columns;_4.forEach(this._flItems,function(_33,idx){_2f.push({});var _34=(idx===0)?0:(_30+_31+1);this._groupRowIndices.push(_34);_30=_34;_31=Math.ceil(_33.length/_32);_2f=_2f.concat(this._getStoreItems(_33));},this);}else{if(this.featureLayers){_4.forEach(this._flItems,function(_35){_2f=_2f.concat(_35);});_2f=this._getStoreItems(_2f);}else{_2f=this._getStoreItems(this._itItems);}}var _36=new _4.data.ItemFileReadStore({data:{items:_2f}});this.grid.setStore(_36);},_toggleTooltip:function(){if(this.showTooltip){if(this.tooltip){return;}this.tooltip=_4.create("div",{"class":"tooltip"},this.domNode);this.tooltip.style.display="none";this.tooltip.style.position="fixed";var _37=this.grid;this._mouseOverConnect=_4.connect(_37,"onCellMouseOver",this,this._cellMouseOver);this._mouseOutConnect=_4.connect(_37,"onCellMouseOut",this,this._cellMouseOut);}else{if(this.tooltip){_4.disconnect(this._mouseOverConnect);_4.disconnect(this._mouseOutConnect);_4.destroy(this.tooltip);this.tooltip=null;}}},_rowClicked:function(evt,_38){var _39=evt.cellNode,row=evt.rowIndex,col=evt.cellIndex;var _3a=this._getCellInfo(_39,row,col);if(!_3a){return;}if(this._selectedCell){_4.removeClass(this._selectedCell,"selectedItem");}if(_39!==this._selectedCell){_4.addClass(_39,"selectedItem");this._selectedCell=_39;var _3b=this.grid.store;this._selectedItem={featureLayer:_3b.getValue(_3a,"layer"),type:_3b.getValue(_3a,"type"),template:_3b.getValue(_3a,"template"),symbolInfo:_3b.getValue(_3a,"symbolInfo"),item:this._getItem(_3a)};this._selectedInfo={selRow:row,selCol:col,index1:_3b.getValue(_3a,"index1"),index2:_3b.getValue(_3a,"index2"),index:_3b.getValue(_3a,"index")};}else{this._selectedCell=this._selectedInfo=this._selectedItem=null;}if(!_38){this.onSelectionChange();}},_locate:function(_3c,_3d,_3e){var _3f=this.grid.store,_40=new Array(this._columns);var _41,_42=_3d.index1,_43=_3d.index2,_44=_3d.index,_45=_3c.item;_4.some(_3e,function(_46,_47){return _4.some(_40,function(_48,_49){var _4a=_3f.getValue(_46,"cell"+_49);if(_4a&&(_45?(_44===_3f.getValue(_4a,"index")):(_42===_3f.getValue(_4a,"index1")&&_43===_3f.getValue(_4a,"index2")))){_41=[_47,_49];return true;}else{return false;}});});return _41;},_getCellInfo:function(_4b,row,col){if(!_4b){return;}var _4c=this.grid;var _4d=_4c.getItem(row);var _4e=_4c.store.getValue(_4d,"cell"+col);return _4e;},_getItem:function(_4f){var _50=this.items;if(_50){return _50[this.grid.store.getValue(_4f,"index")];}},_cellMouseOver:function(evt){var _51=this.tooltip;var _52=evt.cellNode,row=evt.rowIndex,col=evt.cellIndex;var _53=this._getCellInfo(_52,row,col);if(_51&&_53){var _54=this.grid.store;var _55=_54.getValue(_53,"template");var _56=_54.getValue(_53,"type");var _57=_54.getValue(_53,"symbolInfo");var _58=_54.getValue(_53,"layer");var _59=this._getItem(_53);var _5a=(_59&&(_59.label+(_59.description?(": "+_59.description):"")))||(_55&&(_55.name+(_55.description?(": "+_55.description):"")))||(_56&&_56.name)||(_57&&(_57.label+(_57.description?(": "+_57.description):"")))||((_58&&_58.name+": ")+"Default");_51.style.display="none";_51.innerHTML=_5a;var _5b=_4.coords(_52.firstChild);_4.style(_51,{left:(_5b.x)+"px",top:(_5b.y+_5b.h+5)+"px"});_51.style.display="";}},_cellMouseOut:function(){var _5c=this.tooltip;if(_5c){_5c.style.display="none";}},_destroyItems:function(){var _5d=this._itemWidgets;for(var w in _5d){if(!_5d[w]){continue;}_5d[w].destroy();delete _5d[w];}},_repaintItems:function(){var _5e=this._itemWidgets;for(var w in _5e){var _5f=_5e[w];if(_5f){_5f._repaint(_5f._surface);}}},_getStoreItems:function(_60){var uid=this._uniqueId;_60=_4.map(_60,function(_61){return _4.mixin({"surfaceId":"tpick-surface-"+(uid.id++)},_61);});var len=_60.length,_62=0,obj={},k=0,_63,_64=[],_65=true,_66=this._columns;while(_62<len){_65=true;_63="cell"+k;obj[_63]=_60[_62];_62++;k++;if(k%_66===0){_65=false;_64.push(obj);obj={};k=0;}}if(_65){_64.push(obj);}return _64;},_getItemsFromLayers:function(_67){var _68=[];_4.forEach(_67,function(_69,_6a){_68.push(this._getItemsFromLayer(_69,_6a));},this);return _68;},_getItemsFromLayer:function(_6b,_6c){var _6d=[];var _6e=[];_6e=_6e.concat(_6b.templates);_4.forEach(_6b.types,function(_6f){var _70=_6f.templates;_4.forEach(_70,function(_71){_71._type_=_6f;});_6e=_6e.concat(_70);});_6e=_4.filter(_6e,esri._isDefined);var _72=_6b.renderer;if(_72){if(_6e.length>0){_4.forEach(_6e,function(_73){var _74=_73.prototype;if(_74){var _75=_72.getSymbol(_74);if(_75){_6d.push({label:this._trimLabel(_73.name),symbol:_75,layer:_6b,type:_73._type_,template:_73,index1:_6c,index2:_6d.length});}}delete _73._type_;},this);}else{var _76=_72.declaredClass.replace("esri.renderer.",""),_77=[];if(_76==="TemporalRenderer"){_72=_72.observationRenderer;if(_72){_76=_72.declaredClass.replace("esri.renderer.","");}}switch(_76){case "SimpleRenderer":_77=[{symbol:_72.symbol,label:_72.label,description:_72.description}];break;case "UniqueValueRenderer":case "ClassBreaksRenderer":_77=_72.infos;break;}_6d=_4.map(_77,function(_78,idx){return {label:this._trimLabel(_78.label),description:_78.description,symbolInfo:_4.mixin({constructor:function(){}},_78),symbol:_78.symbol,layer:_6b,index1:_6c,index2:idx};},this);}}return _6d;},_getItemsFromItems:function(_79){return _4.map(_79,function(_7a,idx){var _7a=_4.mixin({index:idx},_7a);_7a.label=this._trimLabel(_7a.label);return _7a;},this);},_trimLabel:function(_7b){var max=this.maxLabelLength;if(max&&_7b){if(_7b.length>max){_7b=_7b.substr(0,max)+"...";}}return _7b||"";},_cellGet:function(_7c,_7d,_7e){if(!_7e){return "";}return this.grid.store.getValue(_7e,"cell"+_7c);},_cellFormatter:function(_7f){if(_7f){var _80=this._itemWidgets,_81=this.grid.store;var sid=_81.getValue(_7f,"surfaceId");var w=_80[sid];if(!w){w=(_80[sid]=new esri.dijit.editing.TemplatePickerItem({id:sid,label:_81.getValue(_7f,"label"),symbol:_81.getValue(_7f,"symbol"),surfaceWidth:this.surfaceWidth,surfaceHeight:this.surfaceHeight,template:_81.getValue(_7f,"template")}));}return w||"";}else{return "";}},_cellGetGroup:function(_82,_83){if(!this._groupRowIndices){return "";}var _84=_4.indexOf(this._groupRowIndices,_82);if(!_83||_84===-1){return "";}return (this.featureLayers[_84]&&this.featureLayers[_84].name)||"";},_cellGroupFormatter:function(_85){if(_85){return "<div class='groupLabel'>"+_85+"</div>";}else{return "";}}});_4.declare("esri.dijit.editing.TemplatePickerItem",[_5._Widget,_5._Templated],{templateString:"<div class='item' style='text-align: center;'>"+"<div class='itemSymbol' dojoAttachPoint='_surfaceNode'></div>"+"<div class='itemLabel'>${label}</div>"+"</div>",startup:function(){if(this._started){return;}this.inherited(arguments);this._surface=this._draw(this._surfaceNode,this.symbol,this.surfaceWidth,this.surfaceHeight,this.template);},_draw:function(_86,_87,_88,_89,_8a){var _8b=_6.gfx.createSurface(_86,_88,_89);if(_4.isIE<9){var _8c=_8b.getEventSource();_4.style(_8c,"position","relative");_4.style(_8c.parentNode,"position","relative");}var _8d=this._getDrawingToolShape(_87,_8a)||esri.symbol.getShapeDescriptors(_87);var _8e;try{_8e=_8b.createShape(_8d.defaultShape).setFill(_8d.fill).setStroke(_8d.stroke);}catch(e){_8b.clear();_8b.destroy();return;}var dim=_8b.getDimensions();var _8f={dx:dim.width/2,dy:dim.height/2};var _90=_8e.getBoundingBox(),_91=_90.width,_92=_90.height;if(_91>_88||_92>_89){var _93=_91>_92?_91:_92;var _94=_88<_89?_88:_89;var _95=(_94-5)/_93;_4.mixin(_8f,{xx:_95,yy:_95});}_8e.applyTransform(_8f);return _8b;},_getDrawingToolShape:function(_96,_97){var _98,_99=_97?_97.drawingTool||null:null;switch(_99){case "esriFeatureEditToolArrow":_98={type:"path",path:"M 10,1 L 3,8 L 3,5 L -15,5 L -15,-2 L 3,-2 L 3,-5 L 10,1 E"};break;case "esriFeatureEditToolLeftArrow":_98={type:"path",path:"M -15,1 L -8,8 L -8,5 L 10,5 L 10,-2 L -8,-2 L -8,-5 L -15,1 E"};break;case "esriFeatureEditToolRightArrow":_98={type:"path",path:"M 10,1 L 3,8 L 3,5 L -15,5 L -15,-2 L 3,-2 L 3,-5 L 10,1 E"};break;case "esriFeatureEditToolUpArrow":_98={type:"path",path:"M 1,-10 L 8,-3 L 5,-3 L 5,15 L -2,15 L -2,-3 L -5,-3 L 1,-10 E"};break;case "esriFeatureEditToolDownArrow":_98={type:"path",path:"M 1,15 L 8,8 L 5,8 L 5,-10 L -2,-10 L -2,8 L -5,8 L 1,15 E"};break;case "esriFeatureEditToolTriangle":_98={type:"path",path:"M -10,14 L 2,-10 L 14,14 L -10,14 E"};break;case "esriFeatureEditToolRectangle":_98={type:"path",path:"M -10,-10 L 10,-10 L 10,10 L -10,10 L -10,-10 E"};break;case "esriFeatureEditToolCircle":_98={type:"circle",cx:0,cy:0,r:10};break;case "esriFeatureEditToolEllipse":_98={type:"ellipse",cx:0,cy:0,rx:10,ry:5};break;case "esriFeatureEditToolFreehand":if(_96.type==="simplelinesymbol"||_96.type==="cartographiclinesymbol"){_98={type:"path",path:"m -11, -7c-1.5,-3.75 7.25,-9.25 12.5,-7c5.25,2.25 6.75,9.75 3.75,12.75c-3,3 -3.25,2.5 -9.75,5.25c-6.5,2.75 -7.25,14.25 2,15.25c9.25,1 11.75,-4 13.25,-6.75c1.5,-2.75 3.5,-11.75 12,-6.5"};}else{_98={type:"path",path:"M 10,-13 c3.1,0.16667 4.42564,2.09743 2.76923,3.69231c-2.61025,2.87179 -5.61025,5.6718 -6.14358,6.20513c-0.66667,0.93333 -0.46667,1.2 -0.53333,1.93333c-0.00001,0.86666 0.6,1.66667 1.13334,2c1.03077,0.38462 2.8,0.93333 3.38974,1.70769c0.47693,0.42564 0.87693,0.75897 1.41026,1.75897c0.13333,1.06667 -0.46667,2.86667 -1.8,3.8c-0.73333,0.73333 -3.86667,2.66666 -4.86667,3.13333c-0.93333,0.8 -7.4,3.2 -7.6,3.06667c-1.06667,0.46667 -4.73333,1.13334 -5.2,1.26667c-1.6,0.33334 -4.6,0.4 -6.25128,0.05128c-1.41539,-0.18462 -2.34872,-2.31796 -1.41539,-4.45129c0.93333,-1.73333 1.86667,-3.13333 2.64615,-3.85641c1.28718,-1.47692 2.57437,-2.68204 3.88718,-3.54359c0.88718,-1.13845 1.8,-1.33333 2.26666,-2.45641c0.33334,-0.74359 0.37949,-1.7641 0.06667,-2.87692c-0.66666,-1.46666 -1.66666,-1.86666 -2.98975,-2.2c-1.27692,-0.26666 -2.12307,-0.64102 -3.27692,-1.46666c-0.66667,-1.00001 -1.01538,-3.01539 0.73333,-4.06667c1.73333,-1.2 3.6,-1.93333 4.93333,-2.2c1.33333,-0.46667 4.84104,-1.09743 5.84103,-1.23076c1.60001,-0.46667 6.02564,-0.50257 7.29231,-0.56924z"};}break;default:return null;}return {defaultShape:_98,fill:_96.getFill(),stroke:_96.getStroke()};},_repaint:function(_9a){if(!_9a){this._surface=this._draw(this._surfaceNode,this.symbol,this.surfaceWidth,this.surfaceHeight,this.template);return;}if(_9a.getStroke&&_9a.setStroke){_9a.setStroke(_9a.getStroke());}if(_9a.getFill&&_9a.setFill){_9a.setFill(_9a.getFill());}if(_9a.children&&_4.isArray(_9a.children)){_4.forEach(_9a.children,this._repaint,this);}},destroy:function(){if(this._surface){this._surface.destroy();delete this._surface;}this.inherited(arguments);}});}}};});