define(["angular","lodash","cjt/util/locale","jquery","ace","uiBootstrap","cjt/directives/alertList","cjt/services/alertService","cjt/decorators/growlDecorator","app/services/configService"],(function(e,t,n,o){return e.module("App").controller("editorMode",["$scope","$location","$routeParams","$timeout","spinnerAPI","alertService","growl","configService",function(e,i,a,s,r,c,l,h){var p,d,m=[],u=!1;e.noIniPaths=!0,e.txtInFirstOption=n.maketext("[comment,used for highlight in select option]-- Not Available --[comment,used for highlight in select option]"),e.selectedIniPath={type:"",name:""},e.iniPathNames=[],e.processingEditor=!1;var f=function(t){void 0!==d&&d.setReadOnly(t),e.processingEditor=t};e.loadContent=function(){if(c.clear(),e.selectedIniPath.type){r.start("loadingSpinner");var i=e.selectedIniPath;f(!0),u=!1;var a=(s=e.selectedIniPath,t.find(m,(function(e){return"home"===s.type&&"home"===e.type||"vhost"===s.type&&s.name===e.vhost||void 0})));return"home"===a.type?a.inifullpath=a.homedir+"/"+a.path:"vhost"===a.type&&(a.inifullpath=a.documentroot+"/"+a.path),e.currentIniPathInfo=a,h.fetchContent(i.type,i.name).then((function(t){if("undefined"!==t){""===t&&c.add({type:"info",message:n.maketext("The [asis,INI] content does not exist. You may add new content."),closeable:!0,replace:!1,group:"multiphpIniEditor"});var i=o("<div/>").html(t).text();void 0===d&&((d=ace.edit("editor")).$blockScrolling=1/0,d.setShowPrintMargin(!1)),d.focus(),d.scrollToRow(0),d.setTheme("ace/theme/chrome");var a=ace.createEditSession(i);d.setSession(a),void 0!==a&&(a.setMode("ace/mode/ini"),d.on("change",e.informUser))}}),(function(e){c.add({type:"danger",message:e,closeable:!0,replace:!1,group:"multiphpIniEditor"})})).then((function(){f(!1)})).finally((function(){r.stop("loadingSpinner")}))}var s},e.informUser=function(){u||(u=!0,l.info(n.maketext("You must click “[_1]” to apply the new changes.",n.maketext("Save")),{ttl:-1,onopen:function(){p=this}}))},e.save=function(){c.clear(),u=!1,void 0!==p&&p.destroy(),f(!0);var o=t.escape(d.getSession().getValue());return h.saveIniContent(o,e.selectedIniPath.type,e.selectedIniPath.name).then((function(e){void 0!==e&&c.add({type:"success",message:n.maketext("Successfully saved the changes."),closeable:!0,replace:!1,autoClose:1e4,group:"multiphpIniEditor"})}),(function(e){c.add({type:"danger",message:t.escape(e),closeable:!0,replace:!1,group:"multiphpIniEditor"})})).then((function(){f(!1)}))};e.$on("$viewContentLoaded",(function(){c.clear();var o,i,a=PAGE.php_ini_data;!a.status&&a.errors.length>0&&a.errors.forEach((function(e){c.add({type:"danger",message:e,replace:!1,closeable:!0,group:"multiphpIniEditor"})}));(o=a.data.paths).length>0&&(m=o,t.each(o,(function(t){"home"===t.type||t.main_domain?t.main_domain&&(i=t.vhost):e.iniPathNames.push({type:t.type,name:t.vhost})})),e.iniPathNames=t.sortBy(e.iniPathNames,"name"),e.iniPathNames.unshift({type:"vhost",name:i}),e.iniPathNames.unshift({type:"home",name:"Home Directory"})),e.iniPathNames.length>0&&(e.noIniPaths=!1,e.txtInFirstOption=n.maketext("[comment,used for highlight in select option]-- Select a location --[comment,used for highlight in select option]"))}))}])}));