UNPKG

cronapp-framework-js

Version:
1 lines 10.5 kB
window.hostApp||(window.hostApp=""),function(){angular.module("custom.controllers",[]);var e=function(o,t,a){o({method:"GET",url:window.hostApp+"auth/refresh"}).then((function(n,r,s,i){if(n=getRequestData(n),localStorage.getItem("_u")){let e=JSON.parse(localStorage.getItem("_u"));e.user.username===n.user.username&&(n.user=e.user)}localStorage.setItem("_u",JSON.stringify(n)),setTimeout((function(){e(o,t,a)}),18e5),t()})).catch((function(){a()}))};app.controller("ResetPasswordController",["$scope","$translate","Notification","$location","$http","$state",function(e,o,t,a,n,r){e.resetPassword=function(){if(""===passwordNew.value)return void t.error(o.instant("ResetPasswordNewCanNotBeEmpty"));if(""===passwordConfirmation.value)return void t.error(o.instant("ResetPasswordConfirmationCanNotBeEmpty"));if(passwordNew.value!==passwordConfirmation.value)return void t.error(o.instant("ResetPasswordDoesNotMatch"));n({method:"POST",url:window.hostApp+"auth/confirm-reset-password",data:$.param({password:passwordNew.value}),headers:{"Content-Type":"application/x-www-form-urlencoded","X-AUTH-TOKEN":a.search().token}}).then((()=>{t.info(o.instant("ResetPasswordSuccess")),passwordNew.value="",passwordConfirmation.value="",r.go("login")})).catch((e=>{let a=o.instant("ResetPasswordDoesNotMatch");e&&e.data&&(a=e.data.message||e.data.error),t.error(a)}))}}]),app.controller("SignupController",["$controller","$scope","$stateParams","$location","$http","$rootScope","$translate","Notification","UploadService","$timeout","$state","ReportService",function(e,o,t,a,n,r,s,i,l,c,d,p){app.registerEventsCronapi(o,s),r.Notification=i,o.cronapi.screen.changeValueOfField("vars.signupEmail",""),o.cronapi.screen.changeValueOfField("vars.signupUsername",""),o.cronapi.screen.changeValueOfField("vars.signupPassword",""),o.cronapi.screen.changeValueOfField("vars.signupConfirmPassword","")}]),app.controller("LoginController",["$controller","$scope","$http","$rootScope","$window","$state","$translate","Notification","ReportService","UploadService","$location","$stateParams","$timeout","$cookies","$templateCache","DashboardService","SyncService",function(e,o,t,a,n,r,s,i,l,c,d,p,u,m,w,h,f){function g(){t({method:"GET",url:window.hostApp+"me"}).then(v)}function v(e,t,n,r){200==e.status&&(e=getRequestData(e),"undefined"!=typeof Storage&&(localStorage.setItem("_u",JSON.stringify(e)),a.session=JSON.parse(localStorage._u)),o.goHome(),o.blockly&&o.blockly.events&&o.blockly.events.onLogin&&o.blockly.events.onLogin instanceof Function&&o.blockly.events.onLogin())}function y(e,o,t,a){let n;if(o=o||e.status,null!==(e=getRequestData(e))&&e.message)if("string"!=typeof e.message){n=JSON.parse(e.message).exception}else n=e.message;else"string"==typeof e&&502!==o?(n=e,n||401!==o||(n=s.instant("Login.view.invalidPassword"))):n=null!==e&&null!==e.config&&"login"===e.config.url&&401===o?s.instant("Login.view.invalidPassword"):s.instant("Admin.server.out");i.error(n)}t.get(window.NotificationProviderOptions.templateUrl,{cache:!0}).then((e=>w.put(window.NotificationProviderOptions.templateUrl,e.data))),o.goHome=()=>{let e=cronapi.screen.getParam("returnUrl");e?window.location.hash=e:r.go("home"),o.cronapi.forceCloseAllModal()},o.$http=t,o.params=p,o.$state=r,app.registerEventsCronapi(o,s,d),a.http=t,a.Notification=i,a.UploadService=c,a.getReport=function(e,o,t){l.openReport(e,o,t)},a.getDashboard=function(e,o,t){h.openDashboard(e,o,t)},o.redirectToLogin=function(){o.cronapi.social.ssoLogin()},localStorage.getItem("redir_mob")&&(localStorage.removeItem("redir_mob"),n.location.href="/mobileapp/#/app/logged/home"),o.message={},o.renderRecaptcha=function(){window.grecaptcha.render("loginRecaptcha"),window.grecaptcha.reset()},o.login=function(e,a){if(o.message.error=void 0,$("form").find("*[class=g-recaptcha]").length){if(!o.captcha_token&&""===$("form").find("*[class=g-recaptcha]").attr("data-sitekey"))return void i.error(s.instant("Login.view.EmptySiteKeyCaptcha"));if(o.captcha_token=window.grecaptcha.getResponse(),!o.captcha_token&&"invisible"!==$("form").find("*[class=g-recaptcha]").attr("data-size"))return void i.error(s.instant("Login.view.InvalidCaptcha"));"invisible"===$("form").find("*[class=g-recaptcha]").attr("data-size")&&window.grecaptcha.execute()}var n={username:e||o.username.value,password:a||o.password.value,recaptchaToken:o.captcha_token?o.captcha_token:void 0};t({method:"POST",url:window.hostApp+"login",data:$.param(n),headers:{"Content-Type":"application/x-www-form-urlencoded"}}).then(g).catch(y)},g(),o.forgotPassword=function(){""!==forgotPasswordEmail.value?forgotPasswordEmail.validity.valid?t({method:"POST",url:window.hostApp+"auth/reset-password",data:$.param({email:forgotPasswordEmail.value}),headers:{"Content-Type":"application/x-www-form-urlencoded"}}).then((()=>{i.info(s.instant("ForgotPasswordSent")),forgotPasswordEmail.value="",$("#forgotPasswordModal").modal("hide")})).catch((e=>i.error(e))):i.error(s.instant("ForgotPasswordEmailInvalid")):i.error(s.instant("ForgotPasswordEmailCanNotBeEmpty"))};try{var S=e("AfterLoginController",{$scope:o});app.copyContext(S,this,"AfterLoginController")}catch(e){}u((function(){o.blockly&&o.blockly.events&&o.blockly.events.afterLoginRender&&o.blockly.events.afterLoginRender instanceof Function&&o.blockly.events.afterLoginRender()}))}]),app.controller("HomeController",["$controller","$scope","$http","$rootScope","$state","$translate","Notification","ReportService","UploadService","$location","$stateParams","$timeout","DashboardService","SyncService",function(o,t,a,n,r,s,i,l,c,d,p,u,m,w){t.$http=a,t.params=p,t.$state=r,app.registerEventsCronapi(t,s,d),n.http=a,n.Notification=i,n.UploadService=c,n.getReport=function(e,o,t){l.openReport(e,o,t)},n.getDashboard=function(e,o,t){m.openDashboard(e,o,t)};cronapp.ioc.getInstance(cronapp.configuration.IConfigurationService).getValue("cronapp.framework.auth.idletime").then((function(e){let o=!1,a=(new Date).getTime();var n,r=function(){a=(new Date).getTime(),o&&console.log("User is Back"),o=!1};e&&e>0&&((n=window).onload=r,n.onmousemove=r,n.onmousedown=r,n.ontouchstart=r,n.onclick=r,n.onkeypress=r,n.addEventListener("scroll",r,!0),r(),setInterval((()=>{(new Date).getTime()-a>6e4*e&&function(){if(!o){o=!0,console.log("User is Idle");try{t.logout()}catch(e){console.log(e)}}}()}),1e3))})),t.message={},t.selecionado={valor:1},0===t.$state.get().filter((e=>"LoginController"===e.controller)).length&&(t.ignoreAuth=!0),n.session=void 0!==localStorage.getItem("_u")?JSON.parse(localStorage.getItem("_u")):null,n.session?(n.myTheme="",n.session.user&&(n.myTheme=n.session.user.theme),t.$watch("myTheme",(function(e){void 0!==e&&""!==e&&$("#themeSytleSheet").attr("href","node_modules/cronapp-framework-js/css/themes/"+e+".min.css")})),localStorage.getItem("_u")&&e(a,(function(){}),(function(){localStorage.removeItem("_u"),window.location.hash?r.go("loginReturnUrl",{returnUrl:window.location.hash}):r.go("login")}))):t.ignoreAuth||(localStorage.removeItem("_u"),window.location.hash?r.go("loginReturnUrl",{returnUrl:window.location.hash}):window.location.href=""),n.logout=function(){function e(e){e=getRequestData(e),n.session={},"undefined"!=typeof Storage&&localStorage.removeItem("_u"),t.cronapi.util.changeViewLogout()}a({method:"POST",url:window.hostApp+"logout",headers:{"Content-Type":"application/json"}}).then(e).catch(e)},t.changePassword=function(){if(function(){if(""===oldPassword.value||""===newPassword.value||""===newPasswordConfirmation.value)return""===newPasswordConfirmation.value&&i.error(s.instant("Home.view.ConfirmationPasswordCanNotBeEmpty")),""===newPassword.value&&i.error(s.instant("Home.view.NewPasswordCanNotBeEmpty")),""===oldPassword.value&&i.error(s.instant("Home.view.PreviousPasswordCanNotBeEmpty")),!1;return!0}()){var e={oldPassword:oldPassword.value,newPassword:newPassword.value,newPasswordConfirmation:newPasswordConfirmation.value};a({method:"POST",url:window.hostApp+"changePassword",data:$.param(e),headers:{"Content-Type":"application/x-www-form-urlencoded"}}).then((function(e,o,t,a){i.info(s.instant("Home.view.passwordChanged")),oldPassword.value="",newPassword.value="",newPasswordConfirmation.value="",$("#modalPassword").modal("hide")})).catch((function(e,o,t,a){var n;o=o||e.status,e=getRequestData(e),n=422===o?e:o>=401?s.instant("Home.view.InvalidPassword"):e;i.error(n)}))}};var h=function(){var e=$(this);e.closest(".sub-menu").length>0&&e.closest(".navbar-nav").collapse("hide")};t.$on("$viewContentLoaded",(function(){var e=$(".navbar-nav");e.off("click","a",h),e.on("click","a",h)})),t.themes=["material","cerulean","cosmo","cyborg","darkly","flatly","journal","lumen","paper","readable","sandstone","simplex","slate","spacelab","superhero","united","yeti"],t.changeTheme=function(e){if(void 0!==e){$("body").append('<div id="transition" />'),$("#transition").css({"background-color":"#FFF",zIndex:1e5,position:"fixed",top:"0px",right:"0px",bottom:"0px",left:"0px",overflow:"hidden",display:"block"}),$("#transition").fadeIn(800,(function(){$("#themeSytleSheet").attr("href","node_modules/cronapp-framework-js/css/themes/"+e+".min.css"),n.myTheme=e,$("#transition").fadeOut(1e3,(function(){$("#transition").remove()}))}));var o={theme:e};a({method:"POST",url:window.hostApp+"changeTheme",data:$.param(o),headers:{"Content-Type":"application/x-www-form-urlencoded"}}).then((function(o,t,a,r){n.session.theme=e,n.session.user.theme=e,localStorage.setItem("_u",JSON.stringify(n.session))})).catch((function(e,o,t,a){var n=getRequestData(e);i.error(n)}))}};try{var f=o("AfterHomeController",{$scope:t});app.copyContext(f,this,"AfterHomeController")}catch(e){}u((function(){t.blockly&&t.blockly.events&&t.blockly.events.afterHomeRender&&t.blockly.events.afterHomeRender instanceof Function&&t.blockly.events.afterHomeRender()}))}]),app.controller("PublicController",["$controller","$scope",function(e,o){o.ignoreAuth=!0,angular.extend(this,e("HomeController",{$scope:o}))}]),app.controller("SocialController",["$controller","$scope","$location",function(e,o,t){o.checkSocial=!0,angular.extend(this,e("LoginController",{$scope:o}));var a=t.search(),n={};for(var r in a)a.hasOwnProperty(r)&&(n[r]=a[r]);let s=n.logoutUri;s?window.localStorage.setItem("logoutUri",s):window.localStorage.removeItem("logoutUri"),o.loginWithToken()}])}(app),window.safeApply=function(e){var o=this.$root.$$phase;"$apply"===o||"$digest"===o?e&&"function"==typeof e&&e():this.$apply(e)};