(function() { 'use strict'; angular .module('hyperion') .controller('system.NewAccountController', ['$http', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', 'modalDialog', 'CONFIG', 'sysClock', 'authService', function($http, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, modalDialog, CONFIG, sysClock, authService) { // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } /////////////////////////////////////////////////////////////////////////////// // TEMPLATE SETTINGS $scope.accessdenied = false; $scope.isLoading = true; // show ajax loader $scope.account = {}; $scope.account.company_id = $sessionStorage.currentUser.company_id; $scope.account.language_id = 1; $scope.account.timezone_id = 0; $scope.account.phone_number = null; $scope.ismanager = false; $scope.account.ismanager = false; $scope.notification_email = true; $scope.account.notification_email = true; $scope.notification_sms = false; $scope.account.notification_sms = false; /////////////////////////////////////////////////////////////////////////////// $timeout(function() { if(!$sessionStorage.currentUser.ismanager) { $scope.accessdenied = true; } else { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_country { ' + 'id ' + 'name ' + 'full_name ' + 'code_iso_31661 ' + 'calling_code ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.countries = response.data.data.dictionary_country; },function(error) { // failure console.error(error); } ); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_title { ' + 'id ' + 'name ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.titles = response.data.data.dictionary_title; },function(error) { // failure console.error(error); } ); }); } $scope.isLoading = false; // show ajax loader }, 100); $scope.selectCountry = function(){ var country = $filter('filter')($scope.countries, {id: parseInt($scope.account.mobile_country, 10)})[0]; $scope.account.phone_dialcode = '+' + country.calling_code; }; $scope.accessManager = function() { $scope.clientForm.$setDirty(); }; $scope.emailNotifications = function() { $scope.clientForm.$setDirty(); }; $scope.smsNotifications = function() { $scope.clientForm.$setDirty(); }; $scope.save = function(){ authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'accountadd ( ' + 'company_id: "' + $scope.account.company_id + '", ' + 'title_id: ' + $scope.account.title_id + ', ' + 'first_name: "' + $scope.account.first_name + '", ' + 'last_name: "' + $scope.account.last_name + '", ' + 'email: "' + $scope.account.email + '", ' + 'mobile_number: "' + $scope.account.phone_number + '", ' + 'mobile_country_id: ' + $scope.account.mobile_country + ', ' + 'language_id: ' + $scope.account.language_id + ', ' + 'isnotifyemail: ' + $scope.account.notification_email + ', ' + 'isnotifysms: ' + $scope.account.notification_sms + ', ' + 'ismanager: ' + $scope.account.ismanager + '){ id }' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); $location.path('/system/account/' + response.data.data.accountadd.id); },function(error) { // failure console.error(error); } ); }); }; $scope.cancel = function(){ $location.path('/system/mycompany'); }; }]) .controller('system.ViewAccountController', ['$http', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', 'modalDialog', 'CONFIG', 'sysClock', 'authService', '$stateParams', function($http, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, modalDialog, CONFIG, sysClock, authService, $stateParams) { // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } /////////////////////////////////////////////////////////////////////////////// // TEMPLATE SETTINGS $scope.accessdenied = false; $scope.isLoading = true; // show ajax loader let account_cache = {}; /////////////////////////////////////////////////////////////////////////////// $timeout(function() { if(!$sessionStorage.currentUser.ismanager) { $scope.accessdenied = true; } else { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'accounts(id:"' + $stateParams.account_id + '") { ' + 'id ' + 'created ' + 'title { ' + 'id ' + 'name ' + '}' + 'first_name ' + 'last_name ' + 'email ' + 'mobile { ' + 'number ' + 'country { ' + 'id ' + 'calling_code ' + '} ' + '} ' + 'isactive ' + 'ismanager ' + 'isverified ' + 'isnotifyemail ' + 'isnotifysms ' + 'first_signin ' + 'last_signin ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.account = {}; $scope.account.id = response.data.data.accounts[0].id; $scope.account.isactive = response.data.data.accounts[0].isactive; $scope.account.isverified = response.data.data.accounts[0].isverified; $scope.account.status = $scope.account.isverified?($scope.account.isactive?0:1):2; $scope.account.title_id = response.data.data.accounts[0].title.id; $scope.account.first_name = response.data.data.accounts[0].first_name; $scope.account.last_name = response.data.data.accounts[0].last_name; $scope.account.email = response.data.data.accounts[0].email; let mobile = response.data.data.accounts[0].mobile; $scope.account.phone_number = mobile.number; $scope.mobile_country_id = mobile.country.id; $scope.account.phone_dialcode = '+' + mobile.country.calling_code; $scope.account.ismanager = response.data.data.accounts[0].ismanager; $scope.account.notification_email = response.data.data.accounts[0].isnotifyemail; $scope.account.notification_sms = response.data.data.accounts[0].isnotifysms; angular.copy($scope.account, account_cache); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_title { ' + 'id ' + 'name ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.titles = response.data.data.dictionary_title; },function(error) { // failure console.error(error); } ); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_country { ' + 'id ' + 'name ' + 'full_name ' + 'code_iso_31661 ' + 'calling_code ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.countries = response.data.data.dictionary_country; $scope.account.mobile_country = $scope.mobile_country_id; },function(error) { // failure console.error(error); } ); }); },function(error) { // failure console.error(error); } ); }); } $scope.isLoading = false; // show ajax loader }, 100); $scope.selectCountry = function(){ let country = $filter('filter')($scope.countries, {id: parseInt($scope.account.mobile_country, 10)})[0]; $scope.account.phone_dialcode = '+' + country.calling_code; }; $scope.accountChangeStatus = function() { console.log('accountChangeStatus: ' + $scope.account.id); $scope.account.status = $scope.account.isverified?($scope.account.isactive?0:1):2; $scope.clientForm.$setDirty(); } $scope.accessManager = function() { $scope.clientForm.$setDirty(); }; $scope.emailNotifications = function() { $scope.clientForm.$setDirty(); }; $scope.smsNotifications = function() { $scope.clientForm.$setDirty(); }; $scope.cancel = function() { angular.copy(account_cache, $scope.account); $scope.account.mobile_country = $scope.mobile_country_id; $scope.clientForm.$setPristine(); }; $scope.update = function(){ $scope.account.language_id = 1; $scope.account.company_id = $sessionStorage.currentUser.company_id; authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'accountupdate ( ' + 'account_id: "' + $stateParams.account_id + '", ' + 'company_id: "' + $scope.account.company_id + '", ' + 'isactive: ' + $scope.account.isactive + ', ' + 'title_id: ' + $scope.account.title_id + ', ' + 'first_name: "' + $scope.account.first_name + '", ' + 'last_name: "' + $scope.account.last_name + '", ' + 'mobile_number: "' + $scope.account.phone_number + '", ' + 'mobile_country_id: ' + $scope.account.mobile_country + ', ' + 'language_id: ' + $scope.account.language_id + ', ' + 'isnotifyemail: ' + $scope.account.notification_email + ', ' + 'isnotifysms: ' + $scope.account.notification_sms + ', ' + 'ismanager: ' + $scope.account.ismanager + '){ id }' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.clientForm.$setPristine(); //$location.path('/system/account/' + response.data.data.accountupdate.id); },function(error) { // failure console.error(error); } ); }); }; $scope.delete = function(){ modalDialog.showDialog({ 'template':'modal.codeconfirmation.html', 'controller':'modalCodeConfirmationController', 'subtitle': "DELETING A USER ACCOUNT", 'message': "PLEASE VALIDATE WITH CONFIRMATION CODE" }).then( // acknowledge function(event_id){ if(event_id!==null) { } } ) } $scope.back = function(){ $location.path('/system/mycompany'); }; }]) .controller('system.MyAccountController', ['$http', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', 'modalDialog', 'CONFIG', 'sysClock', 'authService', '$stateParams', function($http, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, modalDialog, CONFIG, sysClock, authService, $stateParams) { // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } /////////////////////////////////////////////////////////////////////////////// // TEMPLATE SETTINGS $scope.isLoading = true; // show ajax loader let account_cache = {}; /////////////////////////////////////////////////////////////////////////////// $timeout(function() { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'accounts(id:"' + $sessionStorage.currentUser.user_id + '") { ' + 'id ' + 'created ' + 'title { ' + 'id ' + 'name ' + '}' + 'first_name ' + 'last_name ' + 'email ' + 'mobile { ' + 'number ' + 'country { ' + 'id ' + 'calling_code ' + '} ' + '} ' + 'isactive ' + 'ismanager ' + 'isverified ' + 'isnotifyemail ' + 'isnotifysms ' + 'first_signin ' + 'last_signin ' + 'last_passwd_change_days ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.account = {}; $scope.account.id = response.data.data.accounts[0].id; $scope.account.isactive = response.data.data.accounts[0].isactive; $scope.account.isverified = response.data.data.accounts[0].isverified; $scope.account.status = $scope.account.isverified?($scope.account.isactive?0:1):2; $scope.account.title_id = response.data.data.accounts[0].title.id; $scope.account.first_name = response.data.data.accounts[0].first_name; $scope.account.last_name = response.data.data.accounts[0].last_name; $scope.account.email = response.data.data.accounts[0].email; let mobile = response.data.data.accounts[0].mobile; $scope.account.phone_number = mobile.number; $scope.mobile_country_id = mobile.country.id; $scope.account.phone_dialcode = '+' + mobile.country.calling_code; $scope.account.ismanager = response.data.data.accounts[0].ismanager; $scope.account.notification_email = response.data.data.accounts[0].isnotifyemail; $scope.account.notification_sms = response.data.data.accounts[0].isnotifysms; angular.copy($scope.account, account_cache); $scope.password_expired_alert = parseInt(response.data.data.accounts[0].last_passwd_change_days,10) >= CONFIG.PASSWD_MAX_DAYS; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_title { ' + 'id ' + 'name ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.titles = response.data.data.dictionary_title; },function(error) { // failure console.error(error); } ); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'dictionary_country { ' + 'id ' + 'name ' + 'full_name ' + 'code_iso_31661 ' + 'calling_code ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.countries = response.data.data.dictionary_country; $scope.account.mobile_country = $scope.mobile_country_id; },function(error) { // failure console.error(error); } ); }); },function(error) { // failure console.error(error); } ); }); $scope.isLoading = false; // show ajax loader }, 100); $scope.selectCountry = function(){ let country = $filter('filter')($scope.countries, {id: parseInt($scope.account.mobile_country, 10)})[0]; $scope.account.phone_dialcode = '+' + country.calling_code; }; $scope.emailNotifications = function() { $scope.clientForm.$setDirty(); }; $scope.smsNotifications = function() { $scope.clientForm.$setDirty(); }; $scope.cancel = function() { angular.copy(account_cache, $scope.account); $scope.account.mobile_country = $scope.mobile_country_id; $scope.clientForm.$setPristine(); }; $scope.passwordChange = function() { $location.path('/system/password'); }; $scope.update = function(){ $scope.account.language_id = 1; $scope.account.company_id = $sessionStorage.currentUser.company_id; authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'accountupdate ( ' + 'account_id: "' + $sessionStorage.currentUser.user_id + '", ' + 'company_id: "' + $scope.account.company_id + '", ' + 'isactive: ' + $scope.account.isactive + ', ' + 'title_id: ' + $scope.account.title_id + ', ' + 'first_name: "' + $scope.account.first_name + '", ' + 'last_name: "' + $scope.account.last_name + '", ' + 'mobile_number: "' + $scope.account.phone_number + '", ' + 'mobile_country_id: ' + $scope.account.mobile_country + ', ' + 'language_id: ' + $scope.account.language_id + ', ' + 'isnotifyemail: ' + $scope.account.notification_email + ', ' + 'isnotifysms: ' + $scope.account.notification_sms + ', ' + 'ismanager: ' + $scope.account.ismanager + '){ id }' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.clientForm.$setPristine(); //$location.path('/system/account/' + response.data.data.accountupdate.id); },function(error) { // failure console.error(error); } ); }); }; }]) .controller('system.PasswordController', ['$http', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', 'modalDialog', 'CONFIG', 'sysClock', 'authService', '$stateParams', function($http, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, modalDialog, CONFIG, sysClock, authService, $stateParams) { // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } /////////////////////////////////////////////////////////////////////////////// // TEMPLATE SETTINGS $scope.isLoading = true; // show ajax loader $scope.passwd = {}; $scope.error_message = null; $scope.success_message = null; /////////////////////////////////////////////////////////////////////////////// $timeout(function() { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'accounts(id:"' + $sessionStorage.currentUser.user_id + '") { ' + 'last_passwd_change_time ' + 'last_passwd_change_days ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.passwd.last_change = response.data.data.accounts[0].last_passwd_change_time; $scope.passwd.days_ago = response.data.data.accounts[0].last_passwd_change_days; $scope.password_expired_alert = parseInt($scope.passwd.days_ago,10) >= CONFIG.PASSWD_MAX_DAYS; console.log('last_change: ' + $scope.passwd.last_change); console.log('days_ago: ' + $scope.passwd.days_ago); console.log('password_expired_alert: ' + $scope.password_expired_alert); },function(error) { // failure console.error(error); } ); }); $scope.isLoading = false; // show ajax loader }, 100); function checkOldPassword(){ $scope.error_message = null; if($scope.account.password_old === undefined || $scope.account.password_old.length===0) { $scope.error_message = 'Error: You need to provide current password!'; return false; } return true; } function checkNewPasswords(){ $scope.error_message = null; if(!CONFIG.PASSWD_PATTERN.test($scope.account.password_new0)) { $scope.error_message = 'Error: new password does not meet requirements'; return false; } if($scope.account.password_new0!=$scope.account.password_new1) { $scope.error_message = 'Error: new passwords does not match'; return false; } return true; } $scope.saveNewPassword = function(){ if(checkOldPassword() && checkNewPasswords()) { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'password ( ' + 'password_old: "' + $scope.account.password_old + '", ' + 'password_new: "' + $scope.account.password_new0 + '"' + ')' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.account.password_old = null; $scope.account.password_new0 = null; $scope.account.password_new1 = null; $scope.passwordForm.$setPristine(); $scope.passwordForm.$setUntouched(); if(response.data.errors) { $scope.error_message = response.data.errors[0].message; } else { if(response.data.data.password) { $scope.error_message = false; $scope.success_message = 'Password changed'; } } },function(error) { // failure console.error(error); } ); }); } } }]) })();