define(["angular","lodash","cjt/util/locale","uiBootstrap","cjt/directives/alertList","cjt/directives/spinnerDirective","cjt/decorators/growlDecorator","cjt/services/alertService","app/services/configService","cjt/directives/actionButtonDirective"],(function(e,t,i){return e.module("App").controller("basicMode",["$scope","$location","configService","$routeParams","$timeout","spinnerAPI","alertService","growl",function(e,n,a,o,s,l,r,c){var p,u=[],d=!1;e.noIniPaths=!0,e.txtInFirstOption=i.maketext("[comment,used for highlight in select option]-- Not Available --[comment,used for highlight in select option]"),e.selectedIniPath={type:"",name:""},e.iniPathNames=[],e.loadingDirectiveList=!1,e.showEmptyMessage=!1,e.knobLabel=" ";e.loadDirectives=function(){if(r.clear(),e.selectedIniPath.type){l.start("loadingSpinner");var n=e.selectedIniPath;e.loadingDirectiveList=!0,d=!1;var o=m(e.selectedIniPath);return"home"===o.type?o.inifullpath=o.homedir+"/"+o.path:"vhost"===o.type&&(o.inifullpath=o.documentroot+"/"+o.path),e.currentIniPathInfo=o,a.fetchBasicList(n.type,n.name).then((function(o){if(void 0!==o.directives&&o.directives.length>0){var s=o.directives;return a.getHandlerForDomain(n.type,n.name).then((function(n){"suphp"!==n.php_handler&&(s=t.filter(s,(function(e){return"PHP_INI_SYSTEM"!==e.php_ini_mode}))),e.directiveList=s.map((function(e){e.toggleValue="On"===e.value;var t=e.default_value;return void 0!==e.cpanel_default&&null!==e.cpanel_default&&(t=e.cpanel_default),"boolean"===e.type&&(t="1"===e.default_value?i.maketext("Enabled"):i.maketext("Disabled")),e.default_text=i.maketext("[asis,PHP] Default: [output,class,_1,defaultValue]",t),e}))}),(function(e){r.add({type:"danger",message:e,closeable:!0,replace:!1,group:"multiphpIniEditor"})}))}}),(function(e){r.add({type:"danger",message:e,closeable:!0,replace:!1,group:"multiphpIniEditor"})})).then((function(){e.loadingDirectiveList=!1,l.stop("loadingSpinner")})).finally((function(){l.stop("loadingSpinner"),e.showEmptyMessage=""!==e.selectedIniPath&&e.directiveList.length<=0}))}e.directiveList=[],e.showEmptyMessage=!1};var h=function(){d||(d=!0,c.info(i.maketext("You must click “[_1]” to apply the new changes.",i.maketext("Apply")),{ttl:-1,onopen:function(){p=this}}))};e.toggle_status=function(e){"On"===e.value?(e.value="Off",e.toggleValue=!1):(e.value="On",e.toggleValue=!0),h()},e.directiveTextChange=function(t){h();var n=t.type,a=t.value||"",o=!0,s="";if("integer"===n){var l="[~!]?\\s*E_(?:(?:(?:CORE_|COMPILE_|USER_)?(?:ERROR|WARNING))|(?:USER_)?(?:NOTICE|DEPRECATED)|PARSE|STRICT|RECOVERABLE_ERROR|ALL)",r=new RegExp("^\\s*"+l+"(?:\\s*[&|^]\\s*"+l+")*$");/^-?\d+[kmg]?$/i.test(a)||r.test(a)?o=!0:(o=!1,s=i.maketext("You must provide either an integer value, a [output,url,_1,shorthand byte,target,blank,title,shorthand byte documentation], or a [output,url,_2,predefined constant,target,blank,title,predefined constant documentation].","http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes","http://php.net/manual/en/errorfunc.constants.php"))}else"float"===n&&(/^-?\d+(?:\.\d*)?$/.test(a)?o=!0:(o=!1,s=i.maketext("You must provide a valid float value.")));e.basicModeForm["txt"+t.key].$setValidity("pattern",o),t.validationMsg=s},e.disableApply=function(){return e.noIniPaths||!e.selectedIniPath.type||!e.basicModeForm.$valid},e.requiredValidation=function(e){return"string"!==e.type&&"boolean"!==e.type},e.applyPhpSettings=function(){if(e.basicModeForm.$valid)return r.clear(),d=!1,void 0!==p&&p.destroy(),a.applySettings(e.selectedIniPath.type,e.selectedIniPath.name,e.directiveList).then((function(e){void 0!==e&&r.add({type:"success",message:i.maketext("Successfully applied the settings."),closeable:!0,replace:!1,autoClose:1e4,group:"multiphpIniEditor"})}),(function(e){r.add({type:"danger",message:t.unescape(e),closeable:!0,replace:!1,group:"multiphpIniEditor"})}))};var m=function(e){return t.find(u,(function(t){return"home"===e.type&&"home"===t.type||("vhost"===e.type&&e.name===t.vhost||void 0)}))};e.$on("$viewContentLoaded",(function(){r.clear();var n,a,o=PAGE.php_ini_data;(e.localeIsRTL=!!PAGE.locale_is_RTL,!o.status&&o.errors.length>0)?o.errors.forEach((function(e){r.add({type:"danger",message:e,replace:!1,closeable:!0,group:"multiphpIniEditor"})})):((n=o.data.paths).length>0&&(u=n,t.each(n,(function(t){"home"===t.type||t.main_domain?t.main_domain&&(a=t.vhost):e.iniPathNames.push({type:t.type,name:t.vhost})})),e.iniPathNames=t.sortBy(e.iniPathNames,"name"),e.iniPathNames.unshift({type:"vhost",name:a}),e.iniPathNames.unshift({type:"home",name:"Home Directory"})),e.iniPathNames.length>0&&(e.noIniPaths=!1,e.txtInFirstOption=i.maketext("[comment,used for highlight in select option]-- Select a location --[comment,used for highlight in select option]")))}))}])}));