// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
require({cache:{"url:esri/dijit/analysis/templates/GPWidget.html":'\x3cdiv class\x3d"esriAnalysis"\x3e\r\n    \x3cdiv data-dojo-type\x3d"dijit/layout/ContentPane" style\x3d"margin-top:0.5em; margin-bottom: 0.5em;"\x3e\r\n      \x3cdiv data-dojo-attach-point\x3d"_aggregateToolContentTitle" class\x3d"analysisTitle"\x3e\r\n        \x3ctable class\x3d"esriFormTable" \x3e\r\n          \x3ctr\x3e\r\n            \x3ctd class\x3d"esriToolIconTd"\x3e\x3cdiv class\x3d"GPWidgetIcon"\x3e\x3c/div\x3e\x3c/td\x3e\r\n            \x3ctd class\x3d"esriAlignLeading esriAnalysisTitle" data-dojo-attach-point\x3d"_toolTitle"\x3e\r\n              \x3clabel data-dojo-attach-point\x3d"_titleLbl"\x3e\x3c/label\x3e\r\n            \x3c/td\x3e\r\n            \x3ctd\x3e\r\n              \x3cdiv class\x3d"esriFloatTrailing" style\x3d"padding:0;"\x3e\r\n                  \x3cdiv class\x3d"esriFloatLeading" data-dojo-attach-point\x3d"_toolDescHelpDiv"\x3e\r\n                    \x3ca href\x3d"#" class\x3d\'esriFloatLeading helpIcon\' esriHelpTopic\x3d"toolDescription"\x3e\x3c/a\x3e\r\n                  \x3c/div\x3e\r\n                  \x3cdiv class\x3d"esriFloatTrailing"\x3e\r\n                    \x3ca href\x3d"#" data-dojo-attach-point\x3d"_closeBtn" title\x3d"${i18n.close}" class\x3d"esriAnalysisCloseIcon"\x3e\x3c/a\x3e\r\n                  \x3c/div\x3e\r\n              \x3c/div\x3e\r\n            \x3c/td\x3e\r\n          \x3c/tr\x3e\r\n        \x3c/table\x3e\r\n      \x3c/div\x3e\r\n      \x3cdiv class\x3d"toolHeaderLine"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-type\x3d"dijit/form/Form" data-dojo-attach-point\x3d"_form" readOnly\x3d"true"\x3e\r\n      \x3cdiv class\x3d"section" data-dojo-attach-point\x3d"inputSectionNode"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"_aggregateToolContentButtons" style\x3d"padding:5px;margin-top:5px;border-top:solid 1px #BBB;"\x3e\r\n      \x3cdiv class\x3d"esriFormWarning esriRoundedBox" data-dojo-attach-point\x3d"_errorMessagePane" style\x3d"display:none;"\x3e\r\n        \x3ca href\x3d"#" title\x3d"${i18n.close}" class\x3d"esriFloatTrailing esriAnalysisCloseIcon"\x3e\x3c/a\x3e\r\n        \x3cspan data-dojo-attach-point\x3d"_bodyNode"\x3e\x3c/span\x3e\r\n      \x3c/div\x3e\r\n      \x3cdiv class\x3d"esriExtentCreditsCtr"\x3e\r\n        \x3ca class\x3d"esriFloatTrailing esriSmallFont"  href\x3d"#" data-dojo-attach-point\x3d"_showCreditsLink"\x3e\x3c/a\x3e\r\n       \x3clabel data-dojo-attach-point\x3d"_chooseExtentDiv" class\x3d"esriSelectLabel esriExtentLabel"\x3e\r\n         \x3cinput type\x3d"radio" data-dojo-attach-point\x3d"_useExtentCheck" data-dojo-type\x3d"dijit/form/CheckBox" data-dojo-props\x3d"checked:true" name\x3d"extent" value\x3d"true"/\x3e\r\n           ${i18n.useMapExtent}\r\n       \x3c/label\x3e\r\n      \x3c/div\x3e\r\n      \x3cbutton data-dojo-type\x3d"dijit/form/Button" type\x3d"submit" data-dojo-attach-point\x3d"_saveBtn" data-dojo-attach-event\x3d"onClick:_handleSaveBtnClick" class\x3d"esriLeadingMargin4 esriAnalysisSubmitButton"\x3e\r\n          ${i18n.runAnalysis}\r\n      \x3c/button\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv class\x3d"output-pane" data-dojo-attach-point\x3d"outputPaneNode"\x3e\r\n      \x3cdiv class\x3d"section info" data-dojo-attach-point\x3d"infoNode"\x3e\r\n        \x3cdiv data-dojo-attach-point\x3d"loadingNode" class\x3d"loading"\x3e\x3c/div\x3e\r\n        \x3cdiv data-dojo-attach-point\x3d"infoTextNode" class\x3d"text"\x3e\x3c/div\x3e\r\n      \x3c/div\x3e\r\n      \x3cdiv class\x3d"section" data-dojo-attach-point\x3d"outputSectionNode"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n'}});
define("esri/dijit/analysis/GPWidget","require dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/connect dojo/_base/json dojo/_base/Deferred dojo/has dojo/json dojo/string dojo/dom-style dojo/dom-attr dojo/dom-construct dojo/query dojo/dom-class dojo/NodeList dojo/NodeList-dom dojo/on dojo/Deferred dojo/promise/all dojo/Evented dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dijit/_OnDijitClickMixin dijit/_FocusMixin dijit/registry dijit/form/Button dijit/form/CheckBox dijit/form/ValidationTextBox dijit/form/Form dijit/layout/ContentPane ./_Widget ./_AnalysisOptions ./utils ./GPWidgetViewModel ./customgp/editorManager ./customgp/resultRendererManager ./customgp/common/dijit/Message ../../kernel ../../lang ../../tasks/Geoprocessor ../../tasks/GPMessage ../../tasks/JobInfo ../../layers/ImageParameters ../../graphicsUtils ../../deferredUtils ../../request dojo/i18n!../../nls/jsapi dojo/i18n!./customgp/common/nls/main dojo/i18n!./customgp/nls/strings dojo/text!./templates/GPWidget.html".split(" "),
function(p,T,b,f,v,U,w,x,V,W,q,y,g,X,Y,Z,aa,h,z,A,B,ba,C,D,E,F,ca,da,ea,G,fa,ga,H,I,J,K,r,n,ha,L,ia,M,k,t,ja,N,O,P,m,u,Q,R){p=H.createSubclass([C,D,E,F,B,I],{declaredClass:"esri.dijit.analysis.GPWidget",templateString:R,widgetsInTemplate:!0,viewModelType:K,showChooseExtent:!1,i18n:null,toolName:"GPWidget",helpFileName:"GPWidget",constructor:function(a){a.containerNode&&(this.container=a.containerNode)},destroy:function(){this._clearLastInput();this._clearLastResult();this._clearMessageInterval();
this.inherited(arguments)},_onClose:function(a){a&&this.emit("save",{save:!0});a||(this._clearLastInput(),this._clearLastResult(),this._clearMessageInterval());this.emit("close",b.mixin({save:a},{isWebTool:!0,addToMap:0<this.resultLayerNames.length}))},postMixInProperties:function(){this.inherited(arguments);this.i18n={};b.mixin(this.i18n,m.common);b.mixin(this.i18n,m.analysisTools);b.mixin(this.i18n,m.analysisMsgCodes);b.mixin(this.i18n,m.analysisSettings);b.mixin(this.i18n,m.aggregatePointsTool);
b.mixin(this.i18n,u.common);b.mixin(this.i18n,u.units);b.mixin(this.i18n,Q);this._initModelWatchers()},postCreate:function(){this.inherited(arguments);this._loadConnections();q.set(this._chooseExtentDiv,"display",!0===this.showChooseExtent?"inline-block":"none");this.renderUI();this.resultLayerNames=[]},_loadConnections:function(){v.connect(this._closeBtn,"onclick",b.hitch(this,this._onClose,!1));this.own(this.on("start",b.hitch(this,function(){this._onClose(!0)})))},startup:function(){},renderUI:function(){r.setMap(this.viewModel.map);
r.setNls(this.i18n);n.setMap(this.viewModel.map);n.setNls(this.i18n);this.viewModel.title&&this._updateTitle();this.viewModel.inputParams&&this._createInputNodes();this.viewModel.outputParams&&this._createResultNameNodes();this.viewModel.taskUrl&&this._setUpGP();this.viewModel.helpUrl&&this._updateHelpUrl();this.viewModel.map&&this._updateMap()},_initModelWatchers:function(){this.own(this.viewModel.watch("title",b.hitch(this,this._updateTitle)),this.viewModel.watch("inputParams",b.hitch(this,this._createInputNodes)),
this.viewModel.watch("outputParams",b.hitch(this,this._createResultNameNodes)),this.viewModel.watch("taskUrl",b.hitch(this,this._setUpGP)),this.viewModel.watch("helpUrl",b.hitch(this,this._updateHelpUrl)),this.viewModel.watch("helpUrl",b.hitch(this,this._updateMap)))},_setUpGP:function(){this.gp=new M(this.viewModel.taskUrl);this.gp.setOutSpatialReference(this.viewModel.map.spatialReference);this.own(h(this.gp,"execute-complete",b.hitch(this,this.onExecuteComplete)));this.own(h(this.gp,"job-complete",
b.hitch(this,this.onJobComplete)));this.own(h(this.gp,"job-cancel",b.hitch(this,this.onJobCancel)));this.own(h(this.gp,"status-update",b.hitch(this,this.onStatusUpdate)));this.own(h(this.gp,"get-result-data-complete",b.hitch(this,this.onGetResultDataComplate)));this.own(h(this.gp,"get-result-image-layer-complete",b.hitch(this,this.onGetResultImageLayerComplete)));this.own(h(this.gp,"error",b.hitch(this,this.onError)))},_createInputNodes:function(){this.inputNodes&&0<this.inputNodes.length&&f.forEach(this.inputNodes,
function(a,d){g.destroy(a)},this);this.inputNodes=[];this.drawnLayers=[];f.forEach(this.viewModel.inputParams,function(a,d){this._createInputNode(a,d)},this)},_createInputNode:function(a,d){var c=g.create("div",{"class":"esriAnalysisPadding1"},this.inputSectionNode),e=g.create("div",{"class":"esriAnalysisStepsLabel",title:a.tooltip||a.label||""},c);g.create("span",{"class":"esriTrailingMargin025 esriAnalysisNumberLabel",innerHTML:d+1+""},e);g.create("span",{"class":"",innerHTML:a.label},e);a.required&&
g.create("span",{"class":"label-star",innerHTML:"*"},e);var e=g.create("div",{"class":"esriLeadingMargin1"},c),b=r.createEditor(a,"input","widget",{uid:this.id,config:this.viewModel,widget:this});b.placeAt(e);this.drawTools=[];"SelectFeatureSetFromLayer"===b.editorName&&this.drawTools.push(b);c.param=a;c.inputEditor=b;this.inputNodes.push(c);!1===a.visible&&q.set(c,"display","none");return c},_createResultNameNodes:function(){this.resultNameNodes&&0<this.resultNameNodes.length&&f.forEach(this.resultNameNodes,
function(a,d){g.destroy(a)},this);this.resultLayerParams=[];this.resultNameNodes=[];f.forEach(this.viewModel.outputParams,function(a,d){"GPFeatureRecordSetLayer"===a.dataType&&this.resultLayerParams.push(a)},this);f.forEach(this.resultLayerParams,function(a,d){this._createResultNameNode(a,this.inputNodes.length+d)},this)},_createResultNameNode:function(a,d){var c=g.create("div",{"class":"esriAnalysisPadding1"},this.inputSectionNode),e=g.create("div",{"class":"esriAnalysisStepsLabel",title:a.tooltip||
a.label||""},c);g.create("span",{"class":"esriTrailingMargin025 esriAnalysisNumberLabel",innerHTML:d+1+""},e);g.create("span",{"class":"",innerHTML:a.label},e);a.required&&g.create("span",{"class":"label-star",innerHTML:"*"},e);var e=g.create("div",{"class":"esriLeadingMargin1"},c),b=new G;b.placeAt(e);b.set("value",a.name);!1===a.visible&&q.set(c,"display","none");c.param=a;c.resultNameNode=b;this.resultNameNodes.push(c);return c},_handleSaveBtnClick:function(){this._form.validate()&&(this.set("disableRunAnalysis",
!0),this._clearLastResult(),this._getInputParamValues().then(b.hitch(this,function(a){this.jobParams=a;this.resultLayerNames=[];this.resultNameNodes&&0<this.resultNameNodes.length&&f.forEach(this.resultNameNodes,function(a,c){a.param&&"GPFeatureRecordSetLayer"===a.param.dataType&&a.resultNameNode&&this.resultLayerNames.push(a.resultNameNode.get("value"))},this);0<this.resultLayerNames.length&&(a.resultName=this.resultLayerNames[0],a.returnFeatureCollection=!this.viewModel.serverInfo.resultMapServerName);
this.emit("start",b.mixin({},a,{isWebTool:!0,addToMap:0<this.resultLayerNames.length}));this.viewModel.serverInfo.isSynchronous?this.gp.execute(a):this.gp.submitJob(a);this.emit("job-submit",b.mixin({},a,{isWebTool:!0,addToMap:0<this.resultLayerNames.length}))})))},_getInputParamValues:function(){var a=new z,d={},c=[],e,l="";f.forEach(this.inputNodes,function(a){e=a.inputEditor.getGPValue();e.param=a.param;c.push(e)},this);A(c).then(b.hitch(this,function(e){for(var b=0;b<e.length;b++)if(!c[b].param.required||
null!==e[b]&&void 0!==e[b])d[c[b].param.name]=e[b];else{l=c[b].param.label+" "+this.i18n.requiredInfo;a.reject(l);return}a.resolve(d)}),function(d){a.reject(d)});return a},_createOutputNodes:function(a){var d=[];this.resultNodes=[];this.resultLayers=[];f.forEach(this.viewModel.outputParams,function(b,c){d.push(this._createOutputNode(b,a[c]))},this);if(f.some(d,function(a){return null!==a})){var c=[];f.forEach(a,b.hitch(this,function(a){"GPFeatureRecordSetLayer"===a.dataType&&(a=a.value&&a.value.features)&&
0<a.length&&(c=c.concat(a))}));if(0<c.length)try{var e=N.graphicsExtent(c);e&&this.viewModel.map.setExtent(e.expand(1.4))}catch(l){console.error(l)}}},_createOutputNode:function(a,d){var b;if(a.visible){try{b=n.createResultRenderer(a,d,{uid:this.id,config:this.viewModel})}catch(S){console.error(S),b=n.createResultRenderer("error",d,{uid:this.id,config:this.viewModel})}var e=g.create("div",{"class":"output-node"},this.outputSectionNode);this.resultNodes.push(e);var f=g.create("div",{"class":"output-label",
title:a.tooltip||a.label||"",innerHTML:a.label},e);e.param=a;e.labelNode=f;f=g.create("div",{"class":"renderer-container"},e);b.placeAt(f);b.startup();e.resultRenderer=b;return e}return null},_updateTitle:function(){y.set(this._titleLbl,"innerHTML",this.viewModel.title)},_setDisableRunAnalysisAttr:function(a){this._saveBtn.set("disabled",a);this._saveBtn.set("iconClass",a?"esriLoading":"")},_getDrawLayerAttr:function(){return this.drawLayer},_setDrawLayerAttr:function(a){this.drawLayer||(this.drawLayer=
[]);this.drawLayer.push(a)},_setDrawnLayerNameAttr:function(a){this.drawnLayerName=a},_setDrawPointLayerNameAttr:function(a){this.drawPointLayerName=a},_setDrawLineLayerNameAttr:function(a){this.drawLineLayerName=a},_setDrawPolyLayerNameAttr:function(a){this.drawPolyLayerName=a},_getDrawnLayerNameAttr:function(a){return this.drawnLayerName},clear:function(){f.forEach(this.drawTools,function(a){a.clear()})},onExecuteComplete:function(a){this.set("disableRunAnalysis",!1);var b;a.messages&&0<a.messages.length&&
(b=f.filter(a.messages,function(a){return a.type===k.TYPE_WARNING||a.type===k.TYPE_ERROR}),0<b.length&&this._createErrorMessages(b));this._createOutputNodes(a.results)},onJobComplete:function(a){this.set("disableRunAnalysis",!1);this._clearMessageInterval();a.jobParams=this.jobParams;this.resultLayerNames&&0<this.resultLayerNames.length&&(a.jobParams.resultName=this.resultLayerNames[0]);var d;if(a.jobInfo.messages&&0<a.jobInfo.messages.length&&(d=f.filter(a.jobInfo.messages,function(a){return a.type===
k.TYPE_WARNING||a.type===k.TYPE_ERROR}),0<d.length&&(this._createErrorMessages(d,a),a.jobInfo.jobStatus!==t.STATUS_SUCCEEDED)))return;this.emit("job-success",b.mixin({},a,{isWebTool:!0,addToMap:0<this.resultLayerNames.length}));if(this.viewModel.useResultMapServer){d=this.viewModel.taskUrl.replace("GPServer","MapServer");d=d.substring(0,d.lastIndexOf("/"));d+="/jobs/"+a.jobInfo.jobId;var c=f.filter(this.resultNameNodes,function(b,d){return b.param&&b.param.name===a.jobParams.resultName},this),c=0<
c.length&&c[0].resultNameNode?c[0].resultNameNode.get("value"):a.jobParams.resultName;this.emit("job-result",{value:{url:d,type:"ArcGISDynamicMapServiceLayer"},outputLayerName:c,isWebTool:!0,addToMap:!0});f.some(this.viewModel.outputParams,function(a){if("MapServiceLayer"===a.dataType)return!0});f.forEach(this.viewModel.outputParams,function(b){b.visible&&"GPFeatureRecordSetLayer"!==b.dataType&&"GPRasterDataLayer"!==b.dataType&&"GPRecordSet"!==b.dataType&&this.gp.getResultData(a.jobInfo.jobId,b.name)},
this)}else f.forEach(this.viewModel.outputParams,function(b){b.visible&&("GPFeatureRecordSetLayer"===b.dataType&&this.viewModel.serverInfo&&!this.viewModel.serverInfo.resultMapServerName?this._getCustomResultData(a.jobInfo.jobId,b.name,{returnFeatureCollection:!0}):this.gp.getResultData(a.jobInfo.jobId,b.name))},this)},_getCustomResultData:function(a,d,c,e,f){var g=this.gp._getResultDataHandler,l=this.gp._errorHandler,h=new w(O._dfdCanceller);h._pendingDfd=P({url:this.gp._url.path+"/jobs/"+a+"/results/"+
d,content:b.mixin({},this.gp._url.query,{f:"json",returnType:"data"},c),callbackParamName:"callback",load:function(a,b){g(a,b,e,f,h)},error:function(a){l(a,f,h)}});return h},onJobCancel:function(a){this.infoTextNode.innerHTML="Canceled";this._clearMessageInterval();this.resultLayerNames&&0<this.resultLayerNames.length&&(a.resultName=this.resultLayerNames[0]);this.emit("job-cancel",b.mixin({},a,{isWebTool:!0,addToMap:0<this.resultLayerNames.length}))},onStatusUpdate:function(a){this.jobId=a.jobInfo.jobId;
b.mixin(a,a.jobInfo);a.jobInfo.jobStatus===t.STATUS_SUCCEEDED&&(this.set("disableRunAnalysis",!1),this._clearMessageInterval());!this.messageInterval&&this.jobId&&this._setupMessageInterval();a.jobParams=this.jobParams;this.resultLayerNames&&0<this.resultLayerNames.length&&(a.jobParams.resultName=this.resultLayerNames[0]);this.emit("job-status",b.mixin({},a,{isWebTool:!0,addToMap:0<this.resultLayerNames.length}))},onGetResultDataComplate:function(a){a.result&&("GPFeatureRecordSetLayer"!==a.result.dataType||
"GPFeatureRecordSetLayer"===a.result.dataType&&this.shouldAddToMap)&&this._createOutputNode(this._getOutputParamByName(a.result.paramName),a.result);var d=f.filter(this.resultNameNodes,function(b,d){return b.param&&b.param.name===a.result.paramName},this);a.result.outputLayerName=0<d.length&&d[0].resultNameNode?d[0].resultNameNode.get("value"):a.result.paramName;this.emit("job-result",b.mixin({},a.result,{param:this._getOutputParamByName(a.result.paramName),isWebTool:!0,addToMap:0<this.resultLayerNames.length}))},
onGetResultImageLayerComplete:function(a){if(a=a.layer){var b=a.url.substring(a.url.lastIndexOf("/")+1),b={name:b,title:b,tooltip:b,dataType:"result map service",visible:!0};a._wab_type="ArcGISDynamicMapServiceLayer";var c=this._getResultMapServiceParam();c&&(b.label=c.label,b.tooltip=c.tooltip,a.title=c.label);null!==this._createOutputNode(b,a)&&this.resultLayers.push(a)}},onError:function(a){this.infoTextNode.innerHTML=a.error.message;this._clearMessageInterval()},_createErrorMessages:function(a,
d){var c="",e=0;f.forEach(a,function(a){if(a.type===k.TYPE_WARNING||a.type===k.TYPE_ERROR)a.type===k.TYPE_ERROR&&e++,c+=a.description+"\n"});var g={message:c};d&&d.jobParams&&d.jobParams.resultName&&b.mixin(g,{jobParams:d.jobParams,resultName:d.jobParams.resultName});0===e&&c&&(g.type="warning");g.isWebTool=!0;this.emit("job-fail",g)},_setupMessageInterval:function(){this.messageInterval=setInterval(b.hitch(this,this._updateJobMessage),1E3)},_clearMessageInterval:function(){this.jobId="";this.messageInterval&&
(clearInterval(this.messageInterval),this.messageInterval=null)},_getResultMapServiceParam:function(){var a;f.some(this.viewModel.outputParams,function(b){if("MapServiceLayer"===b.dataType)return a=b,!0});return a},_getOutputParamByName:function(a){for(var b=0;b<this.viewModel.outputParams.length;b++)if(this.viewModel.outputParams[b].name===a)return this.viewModel.outputParams[b]},_clearLastInput:function(){f.forEach(this.inputNodes,function(a){a.inputEditor.clear&&b.isFunction(a.inputEditor.clear)&&
a.inputEditor.clear()},this)},_clearLastResult:function(){g.empty(this.infoTextNode);f.forEach(this.resultNodes,function(a){g.destroy(a.labelNode);a.resultRenderer&&a.resultRenderer.destroy();g.destroy(a)});f.forEach(this.resultLayers,function(a){null!==a&&this.viewModel.map.removeLayer(a)},this);this.resultNodes=[];this.resultLayers=[]},_showLoading:function(){},_hideLoading:function(){},_updateHelpUrl:function(){J.initHelpLinks(this.domNode,!0,{isSingleTenant:!0,helpUrl:this.viewModel.helpUrl,showHelpFromUrl:!0})},
_updateMap:function(){this.viewModel.map&&this.set("map",this.viewModel.map)}});x("extend-esri")&&b.setObject("dijit.analysis.GPWidget",p,L);return p});