Viewing File: /usr/local/cpanel/base/frontend/jupiter/user_manager/views/editController.min.js

define(["angular","lodash","cjt/util/locale","app/views/addEditController","cjt/directives/alertList","cjt/directives/toggleLabelInfoDirective","cjt/directives/toggleSwitchDirective","cjt/services/alertService","cjt/directives/spinnerDirective","app/directives/issueList","app/services/userService","cjt/services/dataCacheService"],(function(e,i,s,t){return e.module("App").controller("editController",["$scope","$route","$routeParams","$timeout","$location","$anchorScroll","userService","alertService","spinnerAPI","dataCache","defaultInfo","quotaInfo","emailDaemonInfo","ftpDaemonInfo","webdiskDaemonInfo","features",function(e,n,r,a,o,u,c,d,l,m,p,g,v,f,h,y){var w=t(e,c,v,f,h,y,p,g,d);function S(i){return l.start("loadingSpinner"),e.ui.isSaving=!0,c.edit(i).then((function(i){var t=m.get("userList"),n=!1;t&&(e.insertSubAndRemoveDupes(i,t),m.set("userList",t),n=!0),l.stop("loadingSpinner"),e.ui.isSaving=!1,e.loadView("list/rows",{loadFromCache:n}),d.add({type:"success",message:s.maketext("The system successfully updated the following user: [_1]",i.full_username),id:"updateUserSuccess",autoClose:1e4})}),(function(t){t=t.error||t,d.clear(),d.add({type:"danger",message:s.maketext("The system failed to update the “[_1]” user with the following error: [_2]",i.full_username,t),id:"updateFailedErrorServer"}),l.stop("loadingSpinner"),e.ui.isSaving=!1,u("top")}))}function b(e,i){return"service"===e.type&&(!1===i.enabled||!1===i.enabledigest)||"sub"===e.type&&(!1===i.enabled||!1===i.enabledigest)}function k(t){if(t)return e.ui.isLoading=!0,e.ui.user=null,l.start("loadingSpinner"),e.ui.user=c.emptyUser(),c.fetchUser(r.guid).then((function(s){e.ui.user=s,e.ui.originalServices=i.cloneDeep(s.services),e.useCandidateServices(s,s),c.addInvitationIssues(s),l.stop("loadingSpinner"),e.ui.isLoading=!1}),(function(i){d.clear(),d.add({type:"warn",message:s.maketext("The system could not load the [asis,subaccount] with the following error: [_1]",i),id:"missingUserWarning"}),e.loadView("list/rows",{loadFromCache:!0})}));d.clear(),d.add({type:"warn",message:s.maketext("You did not select a [asis,subaccount]."),id:"missingUserWarning"}),e.loadView("list/rows",{loadFromCache:!0})}function _(){e.ui.user.synced_password||d.add({type:"warn",message:s.maketext("You cannot enable additional services for this [asis,subaccount] until you set its password. When you set the password, all of your services will utilize the same password."),id:"unsyncedPasswordWarning",replace:!1,counter:!1})}w.initializeScope(),w.initializeView(),e.toggleService=function(e){e.enabled=!e.enabled},e.update=function(i){switch(u("btn-save"),e.mode){case"subaccount":return S(i);case"service":return function(i){return l.start("loadingSpinner"),e.ui.isSaving=!0,e.canPromote(i)?c.link(i,e.ui.originalServiceType,!0).then((function(s){var t=m.get("userList");return e.insertSubAndRemoveDupes(i,t),m.set("userList",t),i.type="sub",i.guid=s.guid,S(i)}),(function(e){d.clear(),d.add({type:"danger",message:s.maketext("The system failed to upgrade the “[_1]” service account to a [asis,subaccount] with the following error: [_2]",i.full_username,e),id:"updateFailedErrorServer"}),u("top")})).finally((function(){l.stop("loadingSpinner"),e.ui.isSaving=!1})):c.editService(i,e.ui.originalService).then((function(){e.loadView("list/rows",{loadFromCache:!1}),d.add({type:"success",message:s.maketext("The system successfully modified the service account: [_1]",i.full_username),id:"updateServiceSuccess",autoClose:1e4})})).catch((function(e){d.add({type:"danger",message:s.maketext("The system failed to modify the service account for “[_1]”: [_2]",i.full_username,e),id:"updateServiceFailed"}),u("top")})).finally((function(){l.stop("loadingSpinner"),e.ui.isSaving=!1}))}(i);default:return d.clear(),void d.add({type:"danger",message:s.maketext("The system did not recognize the update mode: [_1]",e.mode),id:"updateUnrecognizedMode"})}},e.isInProgress=function(){return e.ui.isSaving||e.ui.isLoading},e.unlinkService=function(i,t){return l.start("loadingSpinner"),e.ui.isSaving=!0,c.unlink(i,t).then((function(){return m.remove("userList"),k(i.guid).then((function(){l.stop("loadingSpinner"),e.ui.isSaving=!1,d.add({type:"success",message:s.maketext("The system successfully unlinked the “[_1]” service.",t),id:"unlinkServiceSuccess",autoClose:1e4})}))}),(function(i){d.clear(),d.add({type:"danger",message:s.maketext("The system failed to unlink the “[_1]” service with the following error: [_2]",t,i),id:"unlinkServiceFailed"}),l.stop("loadingSpinner"),e.ui.isSaving=!1,u("top")}))},e.isAllowed=function(i,s){return e.canPromote(i)||s.enabled},e.canEnableDigest=function(i){return!b(i,e.ui.originalServices.webdisk)||!!i.password},e.showDigestRequiresPasswordWarning=function(i){return b(i,e.ui.originalServices.webdisk)&&i.services.webdisk.enabled},e.showUnlink=function(e,i){return!e.synced_password&&!e.services[i].isNew&&!e.services[i].isCandidate},e.canPromote=function(e){return"sub"===e.type||("service"===e.type?!e.has_siblings&&!e.sub_account_exists:void 0)},e.$watch("ui.user.services.ftp.homedir",(function(){e.ui.user.services.ftp.homedir||!e.form.txtFtpHomeDirectory||e.form.txtFtpHomeDirectory.$pristine||e.form.txtFtpHomeDirectory.$setViewValue("/")})),e.$watch("ui.user.services.webdisk.homedir",(function(){e.ui.user.services.webdisk.homedir||!e.form.txtWebDiskHomeDirectory||e.form.txtWebDiskHomeDirectory.$pristine||e.form.txtWebDiskHomeDirectory.$setViewValue("/")})),e.$watch("ui.user.password",(function(i){""!==i||e.canAddServices(e.ui.user)||["email","ftp","webdisk"].forEach((function(i){e.ui.user.services[i].enabled=e.ui.originalServices[i].enabled}))})),e.canAddServices=function(e){return!!e.synced_password||!!e.password},e.linkServices=function(t){return l.start("loadingSpinner"),e.ui.isSaving=!0,c.linkAndDismiss(t).then((function(t){var n=m.get("userList");n&&(e.insertSubAndRemoveDupes(t,n),m.set("userList",n)),e.ui.user.synced_password=t.synced_password,t.linked_services.forEach((function(s){e.ui.user.services[s]=t.services[s],e.ui.originalServices[s]=i.cloneDeep(t.services[s])})),d.add({type:"success",message:t.synced_password?s.maketext("The system successfully linked the service account to the “[_1]” user’s [asis,subaccount]. The service account passwords have not changed.",t.full_username):s.maketext("The system successfully linked the service account to the “[_1]” user’s [asis,subaccount]. The service account passwords have not changed. You must provide a new password if you enable any additional [asis,subaccount] services.",t.full_username),id:"link-user-success",replace:!1})})).catch((function(e){d.add({type:"danger",message:e.error?e.error:e,id:"link"===e.call?"link-error":"link-and-dismiss-error"}),u("top")})).finally((function(){e.ui.isSaving=!1,l.stop("loadingSpinner")}))},/^\/edit\/subaccount/.test(n.current.originalPath)?(e.mode="subaccount",k(r.guid).finally(_)):/^\/edit\/service/.test(n.current.originalPath)&&(e.mode="service",function(t,n){if(t&&n)return e.ui.isLoading=!0,e.ui.user=null,l.start("loadingSpinner"),e.ui.user=c.emptyUser(),c.fetchService(t,n).then((function(s){e.ui.user=s,"email"===t&&0===s.services.email.quota&&0!==e.defaults.email.unlimitedValue&&(s.services.email.quota=e.defaults.email.unlimitedValue),e.ui.originalService=i.cloneDeep(s.services[t]),e.ui.originalServiceType=t,e.ui.originalServices=i.cloneDeep(s.services),e.ui.user.synced_password=!0,l.stop("loadingSpinner"),e.ui.isLoading=!1}),(function(i){d.clear(),d.add({type:"warn",message:s.maketext("The system could not load the service account with the following error: [_1]",i),id:"missingServiceWarning"}),e.loadView("list/rows",{loadFromCache:!0})})).finally((function(){e.ui.user&&!e.canPromote(e.ui.user)&&d.add({type:"warn",message:s.maketext("The system cannot upgrade this service account to a [asis,subaccount]. To access all the features within this interface, you must delete any accounts that share the same username or link this service account to a [asis,subaccount]."),id:"cannotPromoteWarning"})}));d.clear(),d.add({type:"warn",message:s.maketext("You did not select a valid service account."),id:"missingUserWarning"}),e.loadView("list/rows",{loadFromCache:!0})}(r.type,r.user).finally(_))}])}));
Back to Directory File Manager