// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
require({cache:{"url:widgets/NearMe/setting/NetworkServiceChooser.html":'\x3cdiv style\x3d"width: 100%; height: 100%;"\x3e\r\n    \x3cdiv class\x3d"public-search-radios esriCTSearchRadio" data-dojo-attach-point\x3d"routeSearch"\x3e\r\n        \x3cinput data-dojo-attach-point\x3d"organizationRadio" checked type\x3d"radio" name\x3d"routeSearchRadio"\r\n            class\x3d"esriCTFloatLeading portal-public-radio routeSearchRadio jimu-radio-btn" id\x3d"org_Radio"\r\n            data-dojo-type\x3d"dijit/form/RadioButton"\x3e\r\n        \x3clabel data-dojo-attach-point\x3d"organizationLabel" class\x3d"esriCTFloatLeading portal-public-label"\r\n            for\x3d"org_Radio" style\x3d"cursor: pointer;"\x3e\r\n            ${nls.networkServiceChooser.arcgislabel}\x3c/label\x3e\r\n        \x3cinput data-dojo-attach-point\x3d"inputRouteURLRadio" type\x3d"radio" name\x3d"routeSearchRadio"\r\n            class\x3d"esriCTFloatLeading online-public-radio routeSearchRadio jimu-radio-btn" id\x3d"route_URL_Radio"\r\n            data-dojo-type\x3d"dijit/form/RadioButton"\x3e\r\n        \x3clabel data-dojo-attach-point\x3d"inputRouteURLLabel" class\x3d"esriCTFloatLeading online-public-label"\r\n            for\x3d"route_URL_Radio" style\x3d"cursor: pointer;"\x3e\r\n            ${nls.networkServiceChooser.serviceURLabel}\x3c/label\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"itemSelectDiv" class\x3d"esriCTItemSelectDiv"\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"serviceUrlDiv" class\x3d"esriCTServiceUrlDiv esriCTHidden"\x3e\r\n        \x3cdiv class\x3d"serviceUrlContainer row"\x3e\r\n            \x3cdiv class\x3d"esriCTServiceLable" title\x3d"${nls.networkServiceChooser.routeURL}"\x3e\r\n                ${nls.networkServiceChooser.routeURL}\r\n            \x3c/div\x3e\r\n            \x3cdiv class\x3d"esriCTServiceField"\x3e\r\n                \x3cdiv class\x3d"esriCTSetServiceURL" data-dojo-type\x3d"dijit/form/ValidationTextBox" trim\x3d"true" required\x3d"true"\r\n                    data-dojo-attach-point\x3d"serviceURL"\x3e\r\n                \x3c/div\x3e\r\n                \x3cdiv class\x3d"jimu-btn jimu-float-trailing jimu-leading-margin1 urlButton esriCTBtnEllipsis jimu-state-disabled"\r\n                    title\x3d"${nls.networkServiceChooser.validateRouteURL}" data-dojo-attach-point\x3d"validateRouteURL"\x3e\r\n                    ${nls.networkServiceChooser.validateRouteURL}\x3c/div\x3e\r\n            \x3c/div\x3e\r\n        \x3c/div\x3e\r\n        \x3cdiv class\x3d"esriCTExampleUrl row"\x3e\r\n            \x3cdiv class\x3d"esriCTServiceLable" title\x3d" ${nls.networkServiceChooser.exampleText}"\x3e\r\n                ${nls.networkServiceChooser.exampleText}\r\n            \x3c/div\x3e\r\n            \x3cdiv class\x3d"esriCTServiceField"\x3e\r\n                \x3cdiv class\x3d"esriCTHint esriCTNetworkChooserHint"\x3e\r\n                    \x3cdiv class\x3d"esriCTExampleUrl"\x3e\r\n                        ${nls.networkServiceChooser.hintRouteURL1}\x3c/div\x3e\r\n                    \x3cdiv class\x3d"esriCTExampleUrl"\x3e\r\n                        ${nls.networkServiceChooser.hintRouteURL2}\x3c/div\x3e\r\n                \x3c/div\x3e\r\n            \x3c/div\x3e\r\n        \x3c/div\x3e\r\n        \x3cdiv data-dojo-attach-point\x3d"routeLayerList" class\x3d"esriCTRouteListDiv"\x3e\r\n        \x3c/div\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"agolRouteLayerList" class\x3d"esriCTAgolRouteListDiv esriCTHidden"\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv data-dojo-attach-point\x3d"buttonsDiv" class\x3d"buttonsDiv"\x3e\r\n        \x3cdiv class\x3d"button-container button-container-absolute" style\x3d"padding: 0px;"\x3e\r\n            \x3cdiv class\x3d"jimu-btn jimu-float-trailing jimu-leading-margin1" data-dojo-attach-point\x3d"cancelButton"\x3e\r\n                ${nls.common.cancel}\x3c/div\x3e\r\n            \x3cdiv class\x3d"jimu-btn jimu-float-trailing jimu-leading-margin1 jimu-state-disabled"\r\n                data-dojo-attach-point\x3d"okButton"\x3e\r\n                ${nls.common.ok}\x3c/div\x3e\r\n            \x3cdiv class\x3d"jimu-btn jimu-float-trailing next jimu-state-disabled" data-dojo-attach-point\x3d"btnNext"\x3e\r\n                ${nls.common.next}\x3c/div\x3e\r\n            \x3cdiv class\x3d"jimu-btn jimu-float-trailing back esriCTHidden" data-dojo-attach-point\x3d"btnBack"\r\n                data-dojo-attach-event\x3d"onclick:_onBtnBackClicked"\x3e\r\n                ${nls.common.back}\x3c/div\x3e\r\n        \x3c/div\x3e\r\n    \x3c/div\x3e\r\n\x3c/div\x3e\r\n'}});
define("dojo/_base/declare jimu/BaseWidgetSetting dijit/_WidgetsInTemplateMixin dojo/_base/lang dojo/on dojo/dom-class dojo/text!./NetworkServiceChooser.html jimu/dijit/ItemSelector dijit/Tree dojo/query esri/request dojo/store/Memory dojo/dom-construct dijit/tree/ObjectStoreModel jimu/dijit/LoadingIndicator dojox/validate/regexp jimu/dijit/Message dojo/domReady!".split(" "),function(p,q,r,f,h,a,t,u,v,w,x,y,m,z,A,B,C){return p([q,r],{baseClass:"jimu-widget-nearme-setting",templateString:t,selectRouteURL:null,
agolFlag:!1,serviceFlag:!1,startup:function(){this.inherited(arguments)},postCreate:function(){this.routeChooser=new u({portalUrl:this.portalUrl,itemTypes:["Network analysis service"]});this.routeChooser.placeAt(this.itemSelectDiv);this.own(h(this.okButton,"click",f.hitch(this,function(c){if(!a.contains(this.okButton,"jimu-state-disabled"))this.onOkClick(c)})));this.own(h(this.cancelButton,"click",f.hitch(this,function(c){this.onCancelClick(c)})));this.own(h(this.routeChooser,"item-selected",f.hitch(this,
function(){a.remove(this.btnNext,"jimu-state-disabled")})));this.own(h(this.routeChooser,"none-item-selected",f.hitch(this,function(){a.add(this.btnNext,"jimu-state-disabled")})));this.own(h(this.serviceURL,"keyup",f.hitch(this,function(){""===f.trim(this.serviceURL.get("value"))?a.add(this.validateRouteURL,"jimu-state-disabled"):a.remove(this.validateRouteURL,"jimu-state-disabled")})));this.own(h(this.validateRouteURL,"click",f.hitch(this,function(){a.contains(this.validateRouteURL,"jimu-state-disabled")||
(this.serviceFlag=!0,this._fetchRouteLayer(this.routeLayerList))})));this.own(h(this.btnNext,"click",f.hitch(this,function(){a.contains(this.btnNext,"jimu-state-disabled")||(this.agolFlag=!0,this._fetchRouteLayer(this.agolRouteLayerList))})));var b=w(".routeSearchRadio",this.routeSearch);this.own(h(b,"change",f.hitch(this,function(){this.organizationRadio&&this.organizationRadio.get("checked")?(a.add(this.serviceUrlDiv,"esriCTHidden"),this.agolFlag?(a.add(this.itemSelectDiv,"esriCTHidden"),a.remove(this.agolRouteLayerList,
"esriCTHidden"),a.add(this.btnBack,"esriCTHidden")):(a.remove(this.itemSelectDiv,"esriCTHidden"),a.add(this.agolRouteLayerList,"esriCTHidden"),a.remove(this.btnNext,"esriCTHidden"),a.add(this.okButton,"jimu-state-disabled"))):(a.add(this.itemSelectDiv,"esriCTHidden"),a.remove(this.serviceUrlDiv,"esriCTHidden"),a.add(this.btnNext,"esriCTHidden"),a.add(this.btnBack,"esriCTHidden"),a.add(this.agolRouteLayerList,"esriCTHidden"))})));this._initLoading()},_initLoading:function(){this.loading=new A({hidden:!0});
this.loading.placeAt(this.domNode);this.loading.startup()},onOkClick:function(b){return b},onCancelClick:function(b){return b},_fetchRouteLayer:function(b){var c=this._getValidRouteURL();this.loading.show();x({url:c,content:{f:"json"},handleAs:"json",callbackParamName:"callback"}).then(f.hitch(this,function(d){var g=!1;d.hasOwnProperty("routeLayers")&&null!==d.routeLayers&&0<d.routeLayers.length&&(a.add(this.itemSelectDiv,"esriCTHidden"),this.serviceFlag?(a.remove(this.serviceUrlDiv,"esriCTHidden"),
a.add(this.agolRouteLayerList,"esriCTHidden"),a.add(this.btnNext,"esriCTHidden"),a.add(this.btnBack,"esriCTHidden"),this.serviceFlag=!1):(a.add(this.serviceUrlDiv,"esriCTHidden"),a.remove(this.agolRouteLayerList,"esriCTHidden"),a.add(this.btnNext,"esriCTHidden"),a.remove(this.btnBack,"esriCTHidden"),this.agolFlag=!1),this._createTree(c,d.routeLayers,b),g=!0);g||(this._resetRouteSearch(b,this.nls.networkServiceChooser.invalidRouteServiceURL),this.loading.hide())}),f.hitch(this,function(d){d&&"Rate limit exceeded. Please try again later."===
d.message?this._resetRouteSearch(b,this.nls.networkServiceChooser.rateLimitExceeded):d&&"Error invoking service"===d.message?this._resetRouteSearch(b,this.nls.networkServiceChooser.errorInvokingService):this._resetRouteSearch(b,this.nls.networkServiceChooser.invalidRouteServiceURL);this.loading.hide()}))},_getValidRouteURL:function(){if(this.routeChooser&&this.agolFlag){var b=this.routeChooser.getSelectedItem();var c=b.url}else c=this.serviceURL.value;var d=c.lastIndexOf("/");var g=c.substr(0,d+1);
b=this._urlValidator(g);this.routeName="";b&&(this.routeName=c.substring(d+1,c.length+1),c=g);return c},_createTree:function(b,c,d){var g=this,e;m.empty(d);var l={data:[{id:1,name:"Route Layers",url:b,root:!0}],getChildren:function(k){return this.query({parent:k.id})}};if(this.routeName)for(e=0;e<c.length;e++)this.routeName===c[e]&&l.data.push({id:c[e],name:c[e],url:b+c[e],parent:1});else for(e=0;e<c.length;e++)l.data.push({id:c[e],name:c[e],url:b+"/"+c[e],parent:1});b=new y(l);b=new z({store:b,query:{root:!0}});
b=new v({model:b,onClick:function(k){1===k.id?a.add(g.okButton,"jimu-state-disabled"):(a.remove(g.okButton,"jimu-state-disabled"),g.selectRouteURL=k.url)},getIconStyle:f.hitch(this,function(k){if(!k||"root"===k.id)return null;var n={width:"20px",height:"20px",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundImage:""};n.backgroundImage="url("+this.folderUrl+"images/"+(1===k.id?"group-layer.png":"route-layer.png")+")";return n})});b.placeAt(d).startup();this.routeName&&1<l.data.length&&
(b.set("paths",[["1",this.routeName]]),a.remove(this.okButton,"jimu-state-disabled"),this.selectRouteURL=l.data[1].url);this.loading.hide()},_resetRouteSearch:function(b,c){this._errorMessage(c);m.empty(b);this.loading.hide();this.serviceFlag=this.agolFlag=!1},_onBtnBackClicked:function(){a.remove(this.itemSelectDiv,"esriCTHidden");a.add(this.serviceUrlDiv,"esriCTHidden");a.add(this.agolRouteLayerList,"esriCTHidden");a.remove(this.btnNext,"esriCTHidden");a.add(this.btnBack,"esriCTHidden")},_errorMessage:function(b){(new C({message:b})).message=
b},_urlValidator:function(b){var c="^"+B.url({allowNamed:!0,allLocal:!1});c=(new RegExp(c,"g")).test(b);b=/\/Route\/NAServer/gi.test(b);return c&&b}})});