/*
 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
 */
//>>built
require({cache:{"url:esri/dijit/editing/templates/TemplatePicker.html":"<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>"}});define("esri/dijit/editing/TemplatePicker",["require","dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojo/_base/html","dojo/_base/array","dojo/_base/json","dojo/_base/kernel","dojo/has","dojo/query","dojo/sniff","dojo/dom-class","dojo/dom-construct","dojo/dom-geometry","dojo/dom-style","dijit/_Widget","dijit/_Templated","dojo/data/ItemFileReadStore","dojox/grid/DataGrid","dojox/gfx","esri/layers/FeatureLayer","esri/symbols/PictureMarkerSymbol","esri/dijit/editing/TemplatePickerItem","esri/kernel","esri/lang","esri/request","esri/dijit/_EventedWidget","dojo/i18n!esri/nls/jsapi","dojo/text!esri/dijit/editing/templates/TemplatePicker.html"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11,_12,_13,gfx,_14,_15,_16,_17,_18,_19,_1a,_1b,_1c){var TP=_2([_1a,_10,_11],{declaredClass:"esri.dijit.editing.TemplatePicker",widgetsInTemplate:true,templateString:_1c,basePath:_1.toUrl("esri/dijit/editing")+"/",featureLayers:null,items:null,grouping:true,showTooltip:false,maxLabelLength:0,rows:4,_rows:0,columns:3,surfaceWidth:30,surfaceHeight:30,emptyMessage:"",useLegend:true,legendCache:{},_uniqueId:{id:0},_assumedCellWidth:90,_initialAutoWidth:300,_initialAutoHeight:200,_ieTimer:150,constructor:function(_1d,_1e){_1d=_1d||{};if(!_1d.items&&!_1d.featureLayers){console.error("TemplatePicker: please provide 'featureLayers' or 'items' parameter in the constructor");}this._dojo14x=(_8.version.minor>=4);this._itemWidgets={};if(_1d.featureLayers&&_1d.featureLayers.length){this._flChanged=1;}this._nls=_1b.widgets.templatePicker;this.emptyMessage=_1d.emptyMessage||(this._nls&&this._nls.creationDisabled)||"";},postMixInProperties:function(){this.inherited(arguments);this._preprocess();},startup:function(){this.inherited(arguments);if(this.rows==="auto"&&this.columns==="auto"){var box=_e.getContentBox(this.domNode);if(!box.w){this.domNode.style.width=this._initialAutoWidth+"px";}if(!box.h){this.domNode.style.height=this._initialAutoHeight+"px";}box=_e.getContentBox(this.domNode);this._columns=Math.floor(box.w/this._assumedCellWidth)||1;}this._applyGridPatches();this._setGridLayout();_4.connect(this.grid,"onRowClick",this,this._rowClicked);this._setGridData();this._toggleTooltip();if(_9("ie")<9){this._repaintItems=_3.hitch(this,this._repaintItems);setTimeout(this._repaintItems,this._ieTimer);}},destroy:function(){this.showTooltip=false;this._toggleTooltip();this._clearLegendInfo();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 _1f=this._selectedCell,_20=this._selectedInfo;if(_1f){this._rowClicked({cellNode:_1f,rowIndex:_20.selRow,cellIndex:_20.selCol});}},update:function(_21){var _22=(this.rows==="auto"&&this.columns==="auto"&&_21)?true:false,_23=this.grid,box;if(_22){var _24=this.domNode,id=_24.id,_25,_26=_8.query("#"+id+".templatePicker div.item")[0];box=_e.getContentBox(_24);_26=_26&&_26.parentNode;if(_26){_25=_5.coords(_26).w;}else{_25=this._assumedCellWidth;}this._columns=Math.floor((box.w-_23.views.views[0].getScrollbarWidth())/_25);this._columns=this._columns||1;}var _27=this._rows;this._preprocess();var _28=this._rows;this._setGridLayout();this._setGridData();if(_28!==_27){_23.set("autoHeight",this._rows,false);}if(_22){_23._resize({w:box.w,h:box.h});_23.viewsHeaderNode.style.display="none";}else{_23.update();}this._toggleTooltip();var _29=this,_2a=this.getSelected();if(_2a){_23.store.fetch({onComplete:function(its){var _2b=_29._locate(_2a,_29._selectedInfo,its);var _2c=_2b&&_23.views.views[0].getCellNode(_2b[0],_2b[1]);if(_2c){_29._rowClicked({cellNode:_2c,rowIndex:_2b[0],cellIndex:_2b[1]},true);}}});}if(_9("ie")<9){setTimeout(this._repaintItems,this._ieTimer);}var _2d=this.featureLayers,_2e=this.items;if((!_2d||!_2d.length)&&(!_2e||!_2e.length)&&_23&&this.emptyMessage){_23.showMessage(this.emptyMessage);}},_eventMap:{"selection-change":true},onSelectionChange:function(){},_setUseLegendAttr:function(use){var _2f=this.useLegend;if(!this._started||_2f!==use){if(use){this._flChanged=1;}else{this._clearLegendInfo();}}this.useLegend=use;},_setFeatureLayersAttr:function(_30){var _31=this.featureLayers;if(!this._started||_31!==_30){this._flChanged=1;}this.featureLayers=_30;},_adjustRowsCols:function(_32){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=_32.length;_6.forEach(_32,function(_33){len+=Math.ceil(_33.length/this.columns);},this);}else{_6.forEach(_32,function(_34){len+=_34.length;},this);len=Math.ceil(len/this.columns);}}else{len=Math.ceil(_32.length/this.columns);}this._rows=len;}else{if(this.columns==="auto"){if(this.featureLayers){if(this.grouping){len=3;}else{_6.forEach(_32,function(_35){len+=_35.length;},this);len=Math.ceil(len/this.rows);}}else{len=Math.ceil(_32.length/this.rows);}this._columns=len;}}},_preprocess:function(){if(this.items){this.grouping=false;}this._autoWidth=false;if(this.rows==="auto"||this.columns==="auto"){this._autoWidth=true;}var _36;if(this.featureLayers){if(this.useLegend&&this._flChanged){this._legendIndices=[];this._loadingIndices=[];this._legendSymbols={};this._ignoreLegends();this._loadingLegends=[];clearTimeout(this._legendTimer);this._legendTimer=null;this._processSelectionLayers();this._flChanged=0;}if(_6.every(this.featureLayers,function(_37){return _37.loaded;})){_36=this._flItems=this._getItemsFromLayers(this.featureLayers);this._adjustRowsCols(_36);}else{var _38=this.featureLayers.length;var _39=[];_6.forEach(this.featureLayers,function(_3a){if(_3a.loaded){_38--;_39.push(_3a);}else{var _3b=_4.connect(_3a,"onLoad",this,function(_3c){_4.disconnect(_3b);_3b=null;_38--;_39.push(_3c);if(!_38){_36=this._flItems=this._getItemsFromLayers(_39);this._adjustRowsCols(_36);this.update();}});}},this);}}else{_36=this._itItems=this._getItemsFromItems(this.items);this._adjustRowsCols(_36);}},_processSelectionLayers:function(){var map,_3d,_3e,_3f,key,_40,_41,_42={};_6.forEach(this.featureLayers,function(_43,idx){if(_43.mode===_14.MODE_SELECTION&&_43._map&&_43.url&&_43._params.drawMode&&!_43.source){_3d=_3.trim(_43._url.path).replace(/\/(MapServer|FeatureServer).*/ig,"/MapServer").replace(/^https?:\/\//ig,"").toLowerCase();_3e=(_42[_3d]=_42[_3d]||{});_3f=(_3e.featureLayers=_3e.featureLayers||{});_40=(_3e.indices=_3e.indices||[]);_3f[idx]=_43;_40.push(idx);map=_43._map;}});if(map){_6.forEach(map.layerIds,function(_44){_44=map.getLayer(_44);if(_44&&_44.url&&(_44.getImageUrl||_44.getTileUrl)&&_44.loaded&&_44.version>=10.1){_3d=_3.trim(_44._url.path).replace(/(\/MapServer).*/ig,"$1");key=_3d.replace(/^https?:\/\//ig,"").toLowerCase();if(_42[key]&&(!_42[key].mapServiceUrl)){_3e=_42[key];_3e.mapServiceUrl=_3d;_3e.mapServiceLayer=_44;this._legendIndices=this._legendIndices.concat(_3e.indices);_41=this._fetchLegend({pickerInstance:this,info:_3e},key);if(_41.then){this._loadingIndices=this._loadingIndices.concat(_3e.indices);this._loadingLegends.push(_41);}else{this._processLegendResponse(_41,_3e);}}}},this);}},_fetchLegend:function(_45,key){var _46=TP.prototype,_47=_46.legendCache[key];if(!_47){_47=(_46.legendCache[key]=_19({url:_45.info.mapServiceUrl+"/legend",content:{f:"json"},callbackParamName:"callback"}));_47._contexts=[_45];_47.addBoth(function(_48){if(_47.canceled){return;}_46.legendCache[key]=_48;var _49=_47._contexts;_47._contexts=null;_6.forEach(_49,function(_4a){var _4b=_4a.pickerInstance,_4c=_4a.info,_4d;if(_4b._destroyed){return;}_6.forEach(_4c.indices,function(idx){_4d=_6.indexOf(_4b._loadingIndices,idx);if(_4d>-1){_4b._loadingIndices.splice(_4d,1);}});_4d=_6.indexOf(_4b._loadingLegends,_47);if(_4d>-1){_4b._loadingLegends.splice(_4d,1);}_4b._processLegendResponse(_48,_4c);});});}else{if(_47.then){_47._contexts.push(_45);}}return _47;},_clearLegendInfo:function(){clearTimeout(this._legendTimer);this._ignoreLegends();this._legendIndices=this._loadingIndices=this._legendSymbols=this._loadingLegends=this._legendTimer=null;},_ignoreLegends:function(){if(this._loadingLegends){_6.forEach(this._loadingLegends,function(_4e){var _4f=-1;_6.some(_4e._contexts,function(_50,idx){if(_50.pickerInstance===this){_4f=idx;}return (_4f>-1);},this);if(_4f>-1){_4e._contexts.splice(_4f,1);}},this);}},_processLegendResponse:function(_51,_52){if(_51&&!(_51 instanceof Error)){_6.forEach(_52.indices,function(idx){var _53=_52.featureLayers[idx].layerId,i,_54=_52.mapServiceUrl+"/"+_53+"/images/",_55=_52.mapServiceLayer._getToken(),_56,obj,_57,url;if(this._legendSymbols[idx]){return;}_56=null;_6.some(_51.layers,function(_58){if(_58.layerId==_53){_56=_58;}return !!_56;});if(_56){obj=(this._legendSymbols[idx]={});_6.forEach(_56.legend,function(_59){_57=_59.values;if(_57&&_57.length){for(i=0;i<_57.length;i++){obj[_57[i]]=_59;}}else{obj.defaultSymbol=_59;}url=_59.url;if(url&&!_59._fixed){_59._fixed=1;if((url.search(/https?\:/)===-1)){_59.url=_54+url;}if(_55&&_59.url.search(/https?\:/)!==-1){_59.url+=(((_59.url.indexOf("?")>-1)?"&":"?")+"token="+_55);}}});}},this);}else{var _5a;_6.forEach(_52.indices,function(idx){_5a=_6.indexOf(this._legendIndices,idx);if(_5a>-1){this._legendIndices.splice(_5a,1);}},this);}var _5b=this;if(_5b._started&&!_5b._legendTimer){_5b._legendTimer=setTimeout(function(){clearTimeout(_5b._legendTimer);_5b._legendTimer=null;if(!_5b._destroyed){_5b.update();}},0);}},_applyGridPatches:function(){var _5c=this.grid;var _5d=_5c.adaptWidth,_5e,i,_5f;_5c.adaptWidth=function(){_5e=this.views.views;for(i=0;_5f=_5e[i];i++){_f.set(_5f.headerNode,"display","block");}_5d.apply(this,arguments);for(i=0;_5f=_5e[i];i++){_f.set(_5f.headerNode,"display","none");}};if(this._dojo14x){if(this.rows!=="auto"&&this.columns!=="auto"){var _60=_4.connect(_5c,"_onFetchComplete",this,function(){_4.disconnect(_60);this.grid.set("autoHeight",this._rows);});}_4.connect(_5c,"_onDelete",this,this._destroyItems);_4.connect(_5c,"_clearData",this,this._destroyItems);_4.connect(_5c,"destroy",this,this._destroyItems);var _61=_5c.focus;if(_61&&_61.findAndFocusGridCell){_61.findAndFocusGridCell=function(){return false;};}}},_setGridLayout:function(){var _62=function(_63){return function(_64,_65){return this._cellGet(_63,_64,_65);};};var _66=_3.hitch(this,this._cellFormatter),_67=[],_68=this._columns,i;for(i=0;i<_68;i++){_67.push({field:"cell"+i,get:_3.hitch(this,_62(i)),formatter:_66});}var _69={cells:[_67]};if(this.grouping){var _6a={field:"groupName",colSpan:_68,get:_3.hitch(this,this._cellGetGroup),formatter:_3.hitch(this,this._cellGroupFormatter)};_69.cells.push([_6a]);}var _6b=this.grid,_6c=_13.prototype.rowsPerPage;_6b.set("rowsPerPage",(this._rows>_6c)?this._rows:_6c);_6b.set("structure",_69);},_setGridData:function(){var _6d=[];if(this.grouping){this._groupRowIndices=[];var _6e,_6f,_70=this._columns;_6.forEach(this._flItems,function(_71,idx){_6d.push({});var _72=(idx===0)?0:(_6e+_6f+1);this._groupRowIndices.push(_72);_6e=_72;_6f=Math.ceil(_71.length/_70);_6d=_6d.concat(this._getStoreItems(_71));},this);}else{if(this.featureLayers){_6.forEach(this._flItems,function(_73){_6d=_6d.concat(_73);});_6d=this._getStoreItems(_6d);}else{_6d=this._getStoreItems(this._itItems);}}var _74=new _12({data:{items:_6d}});this.grid.setStore(_74);},_toggleTooltip:function(){if(this.showTooltip){if(this.tooltip){return;}this.tooltip=_d.create("div",{"class":"tooltip"},this.domNode);this.tooltip.style.display="none";this.tooltip.style.position="fixed";var _75=this.grid;this._mouseOverConnect=_4.connect(_75,"onCellMouseOver",this,this._cellMouseOver);this._mouseOutConnect=_4.connect(_75,"onCellMouseOut",this,this._cellMouseOut);}else{if(this.tooltip){_4.disconnect(this._mouseOverConnect);_4.disconnect(this._mouseOutConnect);_d.destroy(this.tooltip);this.tooltip=null;}}},_rowClicked:function(evt,_76){var _77=evt.cellNode,row=evt.rowIndex,col=evt.cellIndex;var _78=this._getCellInfo(_77,row,col);if(!_78){return;}var _79=this.grid.store;if(_79.getValue(_78,"loadingCell")){return;}if(this._selectedCell){_c.remove(this._selectedCell,"selectedItem");}if(_77!==this._selectedCell){_c.add(_77,"selectedItem");this._selectedCell=_77;this._selectedItem={featureLayer:_79.getValue(_78,"layer"),type:_79.getValue(_78,"type"),template:_79.getValue(_78,"template"),symbolInfo:_79.getValue(_78,"symbolInfo"),item:this._getItem(_78)};this._selectedInfo={selRow:row,selCol:col,index1:_79.getValue(_78,"index1"),index2:_79.getValue(_78,"index2"),index:_79.getValue(_78,"index")};}else{this._selectedCell=this._selectedInfo=this._selectedItem=null;}if(!_76){this.onSelectionChange();}},_locate:function(_7a,_7b,_7c){var _7d=this.grid.store,_7e=new Array(this._columns);var _7f,_80=_7b.index1,_81=_7b.index2,_82=_7b.index,_83=_7a.item;_6.some(_7c,function(_84,_85){return _6.some(_7e,function(_86,_87){var _88=_7d.getValue(_84,"cell"+_87);if(_88&&(_83?(_82===_7d.getValue(_88,"index")):(_80===_7d.getValue(_88,"index1")&&_81===_7d.getValue(_88,"index2")))){_7f=[_85,_87];return true;}else{return false;}});});return _7f;},_getCellInfo:function(_89,row,col){if(!_89){return;}var _8a=this.grid;var _8b=_8a.getItem(row);var _8c=_8a.store.getValue(_8b,"cell"+col);return _8c;},_getItem:function(_8d){var _8e=this.items;if(_8e){return _8e[this.grid.store.getValue(_8d,"index")];}},_cellMouseOver:function(evt){var _8f=this.tooltip;var _90=evt.cellNode,row=evt.rowIndex,col=evt.cellIndex;var _91=this._getCellInfo(_90,row,col);if(_8f&&_91){var _92=this.grid.store;var _93=_92.getValue(_91,"template");var _94=_92.getValue(_91,"type");var _95=_92.getValue(_91,"symbolInfo");var _96=_92.getValue(_91,"layer");var _97=this._getItem(_91);var _98=(_97&&(_97.label+(_97.description?(": "+_97.description):"")))||(_93&&(_93.name+(_93.description?(": "+_93.description):"")))||(_94&&_94.name)||(_95&&(_95.label+(_95.description?(": "+_95.description):"")))||((_96&&_96.name+": ")+"Default");_8f.style.display="none";_8f.innerHTML=_98;var _99=_5.coords(_90.firstChild);_f.set(_8f,{left:(_99.x)+"px",top:(_99.y+_99.h+5)+"px"});_8f.style.display="";}},_cellMouseOut:function(){var _9a=this.tooltip;if(_9a){_9a.style.display="none";}},_destroyItems:function(){var _9b=this._itemWidgets,w;for(w in _9b){if(!_9b[w]){continue;}_9b[w].destroy();delete _9b[w];}},_repaintItems:function(){var _9c=this._itemWidgets,w;for(w in _9c){var _9d=_9c[w];if(_9d){_9d._repaint(_9d._surface);}}},_getStoreItems:function(_9e){var uid=this._uniqueId;_9e=_6.map(_9e,function(_9f){return _3.mixin({"surfaceId":"tpick-surface-"+(uid.id++)},_9f);});var len=_9e.length,_a0=0,obj={},k=0,_a1,_a2=[],_a3=true,_a4=this._columns;while(_a0<len){_a3=true;_a1="cell"+k;obj[_a1]=_9e[_a0];_a0++;k++;if(k%_a4===0){_a3=false;_a2.push(obj);obj={};k=0;}}if(_a3&&len){_a2.push(obj);}return _a2;},_getItemsFromLayers:function(_a5){var _a6=[];_6.forEach(_a5,function(_a7,_a8){_a6.push(this._getItemsFromLayer(_a7,_a8));},this);return _a6;},_getItemsFromLayer:function(_a9,_aa){var _ab=[];if(this.useLegend&&_6.indexOf(this._loadingIndices,_aa)>-1){return [{label:(this._nls&&this._nls.loading)||"",symbol:null,layer:_a9,type:null,template:null,index1:_aa,index2:0,loadingCell:1}];}var _ac=[];_ac=_ac.concat(_a9.templates);_6.forEach(_a9.types,function(_ad){var _ae=_ad.templates;_6.forEach(_ae,function(_af){_af._type_=_ad;});_ac=_ac.concat(_ae);});_ac=_6.filter(_ac,_18.isDefined);var _b0=_a9.renderer;if(_b0){var _b1=_b0.declaredClass.replace("esri.renderer.","");if(_ac.length>0){_6.forEach(_ac,function(_b2){var _b3=_b2.prototype;if(_b3){var _b4=_b0.getSymbol(_b3);if(_b4){var _b5=null,pms,_b6;if(this.useLegend&&_6.indexOf(this._legendIndices,_aa)>-1){_b6=this._legendSymbols&&this._legendSymbols[_aa];if(_b6){switch(_b1){case "SimpleRenderer":_b5=_b6.defaultSymbol;break;case "UniqueValueRenderer":_6.some(_b0.infos,function(_b7){if(_b7.symbol===_b4){_b5=_b6[_b7.value];}return !!_b5;});break;case "ClassBreaksRenderer":_6.some(_b0.infos,function(_b8){if(_b8.symbol===_b4){_b5=_b6[_b8.maxValue];}return !!_b5;});break;}}if(_b5){pms=_7.fromJson(_7.toJson(_15.defaultProps));pms.url=_b5.url;pms.imageData=_b5.imageData;pms.contentType=_b5.contentType;pms.width=_b5.width;pms.height=_b5.height;if(!_18.isDefined(pms.width)||!_18.isDefined(pms.height)){pms.width=15;pms.height=15;}_b5=new _15(pms);}}_ab.push({label:this._trimLabel(_b2.name),symbol:_b5||_b4,legendOverride:!!_b5,layer:_a9,type:_b2._type_,template:_b2,index1:_aa,index2:_ab.length});}}delete _b2._type_;},this);}else{var _b9=[];if(_b1==="TemporalRenderer"){_b0=_b0.observationRenderer;if(_b0){_b1=_b0.declaredClass.replace("esri.renderer.","");}}switch(_b1){case "SimpleRenderer":_b9=[{symbol:_b0.symbol,label:_b0.label,description:_b0.description}];break;case "UniqueValueRenderer":case "ClassBreaksRenderer":_b9=_b0.infos;break;}_ab=_6.map(_b9,function(_ba,idx){return {label:this._trimLabel(_ba.label),description:_ba.description,symbolInfo:_3.mixin({constructor:function(){}},_ba),symbol:_ba.symbol,layer:_a9,index1:_aa,index2:idx};},this);}}return _ab;},_getItemsFromItems:function(_bb){return _6.map(_bb,function(_bc,idx){_bc=_3.mixin({index:idx},_bc);_bc.label=this._trimLabel(_bc.label);return _bc;},this);},_trimLabel:function(_bd){var max=this.maxLabelLength;if(max&&_bd){if(_bd.length>max){_bd=_bd.substr(0,max)+"...";}}return _bd||"";},_cellGet:function(_be,_bf,_c0){if(!_c0){return "";}return this.grid.store.getValue(_c0,"cell"+_be);},_cellFormatter:function(_c1){if(_c1){var _c2=this._itemWidgets,_c3=this.grid.store;var sid=_c3.getValue(_c1,"surfaceId");var w=_c2[sid];if(!w){w=(_c2[sid]=new _16({id:sid,label:_c3.getValue(_c1,"label"),symbol:_c3.getValue(_c1,"symbol"),legendOverride:_c3.getValue(_c1,"legendOverride"),surfaceWidth:this.surfaceWidth,surfaceHeight:this.surfaceHeight,template:_c3.getValue(_c1,"template")}));}return w||"";}else{return "";}},_cellGetGroup:function(_c4,_c5){if(!this._groupRowIndices){return "";}var _c6=_6.indexOf(this._groupRowIndices,_c4);if(!_c5||_c6===-1){return "";}return (this.featureLayers[_c6]&&this.featureLayers[_c6].name)||"";},_cellGroupFormatter:function(_c7){if(_c7){return "<div class='groupLabel'>"+_c7+"</div>";}else{return "";}}});if(_9("extend-esri")){_3.setObject("dijit.editing.TemplatePicker",TP,_17);}return TP;});