/*
 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/analysis/templates/AggregateTool.html":"<div class=\"esriAnalysis\">\r\n    <div data-dojo-type=\"dijit/layout/ContentPane\" style=\"margin-top:0.5em; margin-bottom: 0.5em;\">\r\n      <div data-dojo-attach-point=\"_aggregateToolContentTitle\" class=\"analysisTitle\">\r\n        <table class=\"esriFormTable\" > \r\n          <tr>\r\n            <td class=\"esriToolIconTd\"><div class=\"aggregateIcon\"></div></td>\r\n            <td class=\"esriAlignLeading\">${i18n.aggregatePoints}</td>\r\n            <td>\r\n              <div class=\"esriFloatTrailing\" style=\"padding:0;\">\r\n                  <a href=\"#\" class='esriFloatLeading helpIcon' esriHelpTopic=\"toolDescription\"></a>\r\n                  <a href=\"#\" data-dojo-attach-point=\"_closeBtn\" title=\"${i18n.close}\" class=\"closeIcon\">              \r\n                  <img data-dojo-attach-point=\"_closeImg\" border=\"0\"/></a>            \r\n              </div>                \r\n            </td>\r\n          </tr>\r\n        </table>\r\n      </div>\r\n      <div style=\"clear:both; border-bottom: #333 thin solid; height:1px;width:100%;\"></div>\r\n    </div>\r\n    <div data-dojo-type=\"dijit/form/Form\" data-dojo-attach-point=\"_form\" readOnly=\"true\">\r\n       <table class=\"esriFormTable\"  data-dojo-attach-point=\"_aggregateTable\"  style=\"border-collapse:collapse;border-spacing:5px;\" cellpadding=\"5px\" cellspacing=\"5px\"> \r\n         <tbody>\r\n          <tr>\r\n            <td  colspan=\"3\" class=\"sectionHeader\" data-dojo-attach-point=\"_aggregateToolDescription\" >${i18n.aggregateDefine}</td>\r\n          </tr>      \r\n          <tr>\r\n            <td colspan=\"3\">\r\n              <label class=\"esriFloatLeading  esriTrailingMargin025\">${i18n.oneLabel}</label>\r\n              <label class=\"\">${i18n.chooseAreaLabel}</label>\r\n              <a href=\"#\" class='esriFloatTrailing helpIcon' esriHelpTopic=\"PolygonLayer\"></a>\r\n              <select class=\"esriLeadingMargin1 longInput esriLongLabel\"  style=\"margin-top:1.0em;\" data-dojo-type=\"dijit/form/Select\" data-dojo-attach-point=\"_layersSelect\" data-dojo-attach-event=\"onChange:_handleLayerChange\"></select>\r\n            </td>\r\n          </tr>\r\n          <tr>\r\n         <tr>\r\n           <td colspan=\"2\">\r\n             <label class=\"esriLeadingMargin1 esriSelectLabel\">\r\n               <div data-dojo-type=\"dijit/form/CheckBox\" data-dojo-attach-point=\"_keepPolygonsCheck\" data-dojo-props=\"checked:'true'\"></div>\r\n               ${i18n.keepPolygonLabel}\r\n             </label>\r\n           </td>\r\n           <td class=\"shortTextInput\">\r\n              <a href=\"#\" class='esriFloatTrailing helpIcon' esriHelpTopic=\"KeepBoundaryNoPoints\"></a>\r\n           </td>\r\n          </tr>    \r\n          <tr>\r\n            <td colspan=\"3\" class=\"clear\"></td>\r\n          </tr>\r\n          <tr>\r\n            <td colspan=\"2\">\r\n              <label class=\"esriFloatLeading esriTrailingMargin025\">${i18n.twoLabel}</label>\r\n              <label class=\"longTextInput\">${i18n.addStatsLabel}</label>\r\n            </td>\r\n            <td class=\"shortTextInput\">\r\n              <a href=\"#\" class='esriFloatTrailing helpIcon' esriHelpTopic=\"SummaryFields\"></a> \r\n            </td>             \r\n          </tr>\r\n          <tr data-dojo-attach-point=\"_afterStatsRow\">\r\n            <td colspan=\"3\" class=\"clear\"></td>\r\n          </tr>\r\n\r\n          <tr>\r\n            <td colspan=\"2\">\r\n              <label class=\"esriFloatLeading esriTrailingMargin025\">${i18n.threeLabel}</label>\r\n              <label class=\"longTextInput\"  data-dojo-attach-point=\"_groupByLabel\">${i18n.groupByLabel}</label>\r\n            </td>\r\n            <td class=\"shortTextInput\">\r\n              <a href=\"#\" class='esriFloatTrailing helpIcon' esriHelpTopic=\"GroupByField\"></a> \r\n            </td>             \r\n          </tr>\r\n          <tr>\r\n            <td colspan=\"3\">\r\n              <select class=\"longInput\" data-dojo-type=\"dijit.form.Select\"  data-dojo-attach-point=\"_groupBySelect\"></select>\r\n            </td>                \r\n          </tr>         \r\n          <tr>\r\n            <td colspan=\"3\" class=\"clear\"></td>\r\n          </tr> \r\n          <tr>\r\n            <td colspan=\"2\">\r\n              <label class=\"esriFloatLeading esriTrailingMargin025\">${i18n.fourLabel}</label>\r\n              <label class=\"longTextInput\">${i18n.outputLayerLabel}</label>\r\n            </td>\r\n            <td class=\"shortTextInput\">\r\n              <a href=\"#\" class='esriFloatTrailing helpIcon' esriHelpTopic=\"OutputLayer\"></a> \r\n            </td>             \r\n          </tr>\r\n          <tr>\r\n            <td colspan=\"3\">\r\n              <input type=\"text\" data-dojo-type=\"dijit/form/ValidationTextBox\" class=\"esriLeadingMargin1 longInput\" data-dojo-props=\"required:true\" data-dojo-attach-point=\"_outputLayerInput\" value=\"\"></input>\r\n            </td>                \r\n          </tr>\r\n          <tr>\r\n            <td colspan=\"3\">\r\n               <div class=\"esriLeadingMargin1\" data-dojo-attach-point=\"_chooseFolderRow\">\r\n                 <label style=\"width:9px;font-size:smaller;\">${i18n.saveResultIn}</label>\r\n                 <input class=\"longInput esriFolderSelect\" data-dojo-attach-point=\"_webMapFolderSelect\" dojotype=\"dijit/form/ComboBox\" trim=\"true\"></input>\r\n               </div>              \r\n            </td>\r\n          </tr>\r\n        </tbody>         \r\n       </table>\r\n     </div>\r\n    <div data-dojo-attach-point=\"_aggregateToolContentButtons\" style=\"padding:5px;margin-top:5px;border-top:solid 1px #BBB;\">\r\n      <div style=\"width:100%;padding:0.5em 0 0.5em 0\">\r\n        <a class=\"esriFloatTrailing esriSmallFont\"  href=\"#\" data-dojo-attach-point=\"_showCreditsLink\" data-dojo-attach-event=\"onclick:_handleShowCreditsClick\">${i18n.showCredits}</a>\r\n       <label data-dojo-attach-point=\"_chooseExtentDiv\"class=\"esriSelectLabel\" style=\"font-size:smaller;\">\r\n         <input type=\"radio\" data-dojo-attach-point=\"_useExtentCheck\" data-dojo-type=\"dijit/form/CheckBox\" data-dojo-props=\"checked:true\" name=\"extent\" value=\"true\"/>\r\n           ${i18n.useMapExtent}\r\n       </label>\r\n      </div>\r\n      <button data-dojo-type=\"dijit/form/Button\" type=\"submit\" data-dojo-attach-point=\"_saveBtn\" class=\"esriLeadingMargin4\" data-dojo-attach-event=\"onClick:_handleSaveBtnClick\">\r\n          ${i18n.runAnalysis}\r\n      </button>\r\n    </div>\r\n    <div data-dojo-type=\"dijit/Dialog\" title=\"${i18n.creditTitle}\" data-dojo-attach-point=\"_usageDialog\" style=\"width:40em;\">\r\n      <div data-dojo-type=\"esri/dijit/analysis/CreditEstimator\"  data-dojo-attach-point=\"_usageForm\"></div>\r\n    </div>    \r\n  </div>\r\n"}});define("esri/dijit/analysis/AggregateTool",["require","dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/connect","dojo/_base/json","dojo/has","dojo/i18n","dojo/json","dojo/string","dojo/dom-style","dojo/dom-attr","dojo/dom-construct","dojo/query","dojo/dom-class","dijit/_WidgetBase","dijit/_TemplatedMixin","dijit/_WidgetsInTemplateMixin","dijit/_OnDijitClickMixin","dijit/_FocusMixin","dijit/registry","dijit/form/Button","dijit/form/CheckBox","dijit/form/Form","dijit/form/Select","dijit/form/TextBox","dijit/form/ValidationTextBox","dijit/layout/ContentPane","dijit/form/ComboBox","dijit/Dialog","esri/kernel","esri/lang","esri/dijit/analysis/AnalysisBase","esri/dijit/analysis/utils","esri/dijit/analysis/CreditEstimator","dojo/text!esri/dijit/analysis/templates/AggregateTool.html"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_1a,_1b,_1c,_1d,_1e,_1f,_20,_21,_22,_23,_24){var _25=_2([_10,_11,_12,_13,_14,_21],{declaredClass:"esri.dijit.analysis.AggregateTool",templateString:_24,basePath:_1.toUrl("esri/dijit/analysis"),widgetsInTemplate:true,pointLayer:null,polygonLayers:null,summaryFields:null,aggregateFields:null,outputLayerName:null,keepBoundariesWithNoPoints:true,polygonLayer:null,groupByField:null,showSelectFolder:false,showChooseExtent:true,showHelp:true,showCredits:true,i18n:null,toolName:"AggregatePoints",helpFileName:"AggregatePoints",resultParameter:"AggregatedLayer",constructor:function(_26){this.inherited(arguments);this._pbConnects=[];if(_26.containerNode){this.container=_26.containerNode;}},destroy:function(){this.inherited(arguments);_4.forEach(this._pbConnects,_5.disconnect);delete this._pbConnects;},postMixInProperties:function(){this.inherited(arguments);_3.mixin(this.i18n,_8.getLocalization("esri","jsapi").aggregatePointsTool);},postCreate:function(){this.inherited(arguments);_f.add(this._form.domNode,"esriSimpleForm");_c.set(this._closeImg,"src",this.basePath+"/images/close.gif");this._outputLayerInput.set("validator",_3.hitch(this,this.validateServiceName));this._buildUI();},startup:function(){},_onClose:function(_27){if(_27){this._save();this.onSave();}this.onClose();},_handleSaveBtnClick:function(){if(!this._form.validate()){return;}this._saveBtn.set("disabled",true);var _28={},_29={},_2a;_2a=this.polygonLayers[this._layersSelect.get("value")];_28.PolygonLayer=_6.toJson(_22.constructAnalysisInputLyrObj(_2a));_28.PointLayer=_6.toJson(_22.constructAnalysisInputLyrObj(this.pointLayer));_28.SummaryFields=_6.toJson(this.get("aggregateFields"));_28.OutputName=_6.toJson({serviceProperties:{name:this._outputLayerInput.get("value")}});_28.KeepBoundariesWithNoPoints=this._keepPolygonsCheck.get("checked");if(this._groupBySelect.get("value")!=="0"){_28.GroupByField=this._groupBySelect.get("value");}if(this.showChooseExtent){if(this._useExtentCheck.get("checked")){_28.context=_6.toJson({extent:this.map.extent});}}_29.jobParams=_28;_29.itemParams={"description":_a.substitute(this.i18n.itemDescription,{pointlayername:this.pointLayer.name,polygonlayername:_2a.name}),"tags":_a.substitute(this.i18n.itemTags,{pointlayername:this.pointLayer.name,polygonlayername:_2a.name}),"snippet":this.i18n.itemSnippet};if(this.showSelectFolder){_29.itemParams.folder=this._webMapFolderSelect.item?this.folderStore.getValue(this._webMapFolderSelect.item,"id"):"";}this.execute(_29);},_handleLayerChange:function(_2b){this.outputLayerName=_a.substitute(this.i18n.outputLayerName,{pointlayername:this.pointLayer.name,polygonlayername:this.polygonLayers[_2b].name});this._outputLayerInput.set("value",this.outputLayerName);},_handleAttrSelectChange:function(_2c){var _2d,_2e,obj;if(_2c!=="0"){_2d=this.get("statisticSelect");if(_2d.get("value")!=="0"){if(!_2d.get("isnewRowAdded")){_2e=_2d.get("removeTd");_b.set(_2e,"display","block");obj=_2d.get("referenceWidget");_3.hitch(obj,obj._createStatsRow());_2d.set("isnewRowAdded",true);}}}},_handleStatsValueUpdate:function(_2f,_30,_31){var _32,_33,obj;if(!this.get("attributeSelect")){return;}_32=this.get("attributeSelect");if(_32.get("value")!=="0"&&_31!=="0"){if(!this.get("isnewRowAdded")){_33=this.get("removeTd");_b.set(_33,"display","block");obj=this.get("referenceWidget");_3.hitch(obj,obj._createStatsRow());this.set("isnewRowAdded",true);}}},_handleShowCreditsClick:function(e){e.preventDefault();var _34={},_35={},_36;if(!this._form.validate()){return;}_36=this.polygonLayers[this._layersSelect.get("value")];_34.PolygonLayer=_6.toJson(_22.constructAnalysisInputLyrObj(_36));_34.PointLayer=_6.toJson(_22.constructAnalysisInputLyrObj(this.pointLayer));_34.SummaryFields=_6.toJson(this.get("aggregateFields"));_34.OutputName=_6.toJson({serviceProperties:{name:this._outputLayerInput.get("value")}});_34.KeepBoundariesWithNoPoints=this._keepPolygonsCheck.get("checked");if(this._groupBySelect.get("value")!=="0"){_34.GroupByField=this._groupBySelect.get("value");}if(this.showChooseExtent){if(this._useExtentCheck.get("checked")){_34.Context=_6.toJson({extent:this.map.extent});}}this.getCreditsEstimate(this.toolName,_34).then(_3.hitch(this,function(_37){this._usageForm.set("content",_37);this._usageDialog.show();}));},_save:function(){},_buildUI:function(){this._loadConnections();_22.initHelpLinks(this.domNode,this.showHelp);if(this.pointLayer){_c.set(this._aggregateToolDescription,"innerHTML",_a.substitute(this.i18n.aggregateDefine,{layername:this.pointLayer.name}));}if(this.polygonLayers){_4.forEach(this.polygonLayers,function(_38,_39){if(_38.geometryType==="esriGeometryPolygon"){this._layersSelect.addOption({value:_39,label:_38.name});if(_39===0&&!this.outputLayerName){this.outputLayerName=_a.substitute(this.i18n.outputLayerName,{pointlayername:this.pointLayer.name,polygonlayername:_38.name});}}},this);}if(this.outputLayerName){this._outputLayerInput.set("value",this.outputLayerName);}this._keepPolygonsCheck.set("checked",this.keepBoundariesWithNoPoints);if(this.polygonLayer){this._layersSelect.set();}this._createStatsRow();_4.forEach(this.aggregateFields,function(_3a){var _3b=_3a.split(" ");this._currentAttrSelect.set("value",_3b[0]);_3.hitch(this._currentAttrSelect,this._handleAttrSelectChange,_3b[0])();this._currentStatsSelect.set("value",_3b[1]);_3.hitch(this._currentStatsSelect,this._handleStatsValueUpdat,"value","",_3b[1])();},this);_b.set(this._chooseFolderRow,"display",this.showSelectFolder===true?"block":"none");if(this.showSelectFolder){this.getFolderStore().then(_3.hitch(this,function(_3c){this.folderStore=_3c;this._webMapFolderSelect.set("store",_3c);this._webMapFolderSelect.set("value",this.portalUser.username);}));}_b.set(this._chooseExtentDiv,"display",this.showChooseExtent===true?"block":"none");this.set("groupBySelect",this.groupByField);_b.set(this._showCreditsLink,"display",this.showCredits===true?"block":"none");},_loadConnections:function(){this._connect(this,"onExecute",_3.hitch(this,"_onClose",false));this._connect(this._closeBtn,"onclick",_3.hitch(this,"_onClose",false));},_createStatsRow:function(){var _3d,_3e,_3f,_40,_41,_42,_43;_3d=_d.create("tr",null,this._afterStatsRow,"before");_3f=_d.create("td",{style:{width:"45%",maxWidth:"100px"}},_3d);_3e=_d.create("td",{style:{width:"55%",maxWidth:"104px"}},_3d);_40=new _19({maxHeight:200,"class":"esriLeadingMargin1 mediumInput esriTrailingMargin025 attrSelect",style:{tableLayout:"fixed",overflowX:"hidden"}},_d.create("select",null,_3f));this.set("attributes",{selectWidget:_40,pointLayer:this.pointLayer});_41=new _19({"class":"mediumInput statsSelect",style:{tableLayout:"fixed",overflowX:"hidden"}},_d.create("select",null,_3e));this.set("statistics",{selectWidget:_41});_40.set("statisticSelect",_41);_5.connect(_40,"onChange",this._handleAttrSelectChange);_43=_d.create("td",{"class":"shortTextInput removeTd",style:{"display":"none",maxWidth:"12px"}},_3d);_42=_d.create("a",{"title":this.i18n.removeAttrStats,"class":"closeIcon statsRemove","innerHTML":"<img src='"+this.basePath+"/images/close.gif"+"' border='0''/>"},_43);_5.connect(_42,"onclick",_3.hitch(this,this._removeStatsRow,_3d));_41.set("attributeSelect",_40);_41.set("removeTd",_43);_41.set("isnewRowAdded",false);_41.set("referenceWidget",this);_41.watch("value",this._handleStatsValueUpdate);this._currentStatsSelect=_41;this._currentAttrSelect=_40;return true;},_removeStatsRow:function(row){_4.forEach(_15.findWidgets(row),function(w){w.destroyRecursive();});_d.destroy(row);},_setAnalysisGpServerAttr:function(url){this.analysisGpServer=url;this.set("toolServiceUrl",this.analysisGpServer+"/"+this.toolName);},_setPointLayerAttr:function(_44){if(_44.geometryType==="esriGeometryPoint"){this.pointLayer=_44;}},_setPolygonLayersAttr:function(_45){this.polygonLayers=_45;},_setLayersAttr:function(_46){this.polygonLayers=[];_4.forEach(_46,function(_47){if(_47.geometryType==="esriGeometryPolygon"){this.polygonLayers.push(_47);}else{if(_47.geometryType==="esriGeometryPoint"){this.pointLayer=_47;}}},this);},_setAttributesAttr:function(_48){if(!_48.pointLayer){return;}var _49,_4a,_4b;_49=_48.pointLayer;_4a=_48.selectWidget;_4b=_49.fields;_4a.addOption({value:"0",label:this.i18n.attribute});_4.forEach(_4b,function(_4c){if(_4.indexOf(["esriFieldTypeSmallInteger","esriFieldTypeInteger","esriFieldTypeSingle","esriFieldTypeDouble"],_4c.type)!==-1){if(_4c.name!==_49.objectIdField){_4a.addOption({value:_4c.name,label:_20.isDefined(_4c.alias)&&_4c.alias!==""?_4c.alias:_4c.name});}}},this);},_setStatisticsAttr:function(_4d){var _4e=_4d.selectWidget;_4e.addOption({value:"0",label:this.i18n.statistic});_4e.addOption({value:"SUM",label:this.i18n.sum});_4e.addOption({value:"MIN",label:this.i18n.minimum});_4e.addOption({value:"MAX",label:this.i18n.maximum});_4e.addOption({value:"MEAN",label:this.i18n.average});_4e.addOption({value:"STDDEV",label:this.i18n.standardDev});},_setAggregateFieldsAttr:function(_4f){this.aggregateFields=_4f;},_getAggregateFieldsAttr:function(){var _50="",_51=[],_52,_53;_e(".statsSelect",this.domNode).forEach(function(_54){_52=_15.byNode(_54);_53=_52.get("attributeSelect");if(_53.get("value")!=="0"&&_52.get("value")!=="0"){_50+=_53.get("value")+" "+_52.get("value")+";";_51.push(_53.get("value")+" "+_52.get("value"));}});return _51;},_setGroupBySelectAttr:function(_55){if(!this.pointLayer){return;}var _56=this.pointLayer.fields;this._groupBySelect.addOption({value:"0",label:this.i18n.attribute});_4.forEach(_56,function(_57,_58){if(_4.indexOf(["esriFieldTypeSmallInteger","esriFieldTypeInteger","esriFieldTypeSingle","esriFieldTypeString","esriFieldTypeDate"],_57.type)!==-1){if(_57.name!==this.pointLayer.objectIdField){this._groupBySelect.addOption({value:_57.name,label:_20.isDefined(_57.alias)&&_57.alias!==""?_57.alias:_57.name});}}},this);if(_55){this._groupBySelect.set("value",_55);}},_setDisableRunAnalysisAttr:function(_59){this._saveBtn.set("disabled",_59);},_setShowSelectFolderAttr:function(_5a){this.showSelectFolder=_5a;},_getShowSelectFolderAttr:function(){return this.showSelectFolder;},_setShowChooseExtentAttr:function(_5b){this.showChooseExtent=_5b;},_getShowChooseExtentAttr:function(){return this.showChooseExtent;},_setMapAttr:function(map){this.map=map;},_getMapAttr:function(){return this.map;},_setShowHelpAttr:function(_5c){this.showHelp=_5c;},_getShowHelpAttr:function(){return this.showHelp;},_setShowCreditsAttr:function(_5d){this.showCredits=_5d;},_getShowCreditsAttr:function(){return this.showCredits;},validateServiceName:function(_5e){var _5f=/(:|&|<|>|%|#|\?|\\|\"|\/|\+)/.test(_5e);if(_5e.length===0||((_a.trim(_5e)).length===0)){this._outputLayerInput.set("invalidMessage",this.i18n.requiredValue);return false;}if(_5f){this._outputLayerInput.set("invalidMessage",this.i18n.invalidServiceName);return false;}if(_5e.length>98){this._outputLayerInput.set("invalidMessage",this.i18n.invalidServiceNameLength);return false;}return true;},_connect:function(_60,evt,_61){this._pbConnects.push(_5.connect(_60,evt,_61));},onSave:function(){},onClose:function(){}});if(_7("extend-esri")){_3.setObject("dijit.analysis.AggregateTool",_25,_1f);}return _25;});