Blame view
app/partials/accountSetting/accountSetting.Controller.js
6.96 KB
3a9f4472b
|
1 2 3 4 5 6 7 |
(function() { 'use strict' angular.module('acufuel') .controller('AccountSettingController', [ '$scope', '$filter', '$rootScope', '$state', 'AccountSettingService', AccountSettingController]); function AccountSettingController($scope, $filter, $rootScope, $state, AccountSettingService) { |
bb639860c
|
8 9 |
$scope.addArray = []; $scope.userData = {}; |
f746aee1b
|
10 11 12 |
getAdditionalAccounts(); function getAdditionalAccounts() { |
1b71872b2
|
13 14 |
AccountSettingService.getAdditionalAccounts().then(function(result) { $scope.additionalAccounts = result; |
f746aee1b
|
15 16 17 |
}) } |
bb639860c
|
18 19 |
$scope.userid = JSON.parse(localStorage.getItem('userProfileId')); if($scope.userid && $scope.userid != null && $scope.userid != undefined){ |
1b71872b2
|
20 21 22 23 24 25 |
var id = $scope.userid; AccountSettingService.loginUserData(id).then(function(result) { $scope.userData = result; $scope.userData.status = $scope.userData.account.user.status.toLowerCase(); $scope.userData.userType = $scope.userData.userType.type.toLowerCase(); }) |
bb639860c
|
26 |
} |
3a9f4472b
|
27 |
AccountSettingService.getProducts().then(function(result) { |
bb639860c
|
28 29 30 31 32 33 34 35 36 |
$scope.productList = result; for(var i=0;i<$scope.productList.length;i++){ var obj = { id : $scope.productList[i].id, name : $scope.productList[i].name, status : $scope.productList[i].status } $scope.addArray.push(obj); } |
3a9f4472b
|
37 |
}) |
bb639860c
|
38 39 40 41 42 43 44 45 46 |
$scope.productData = {}; $scope.productData.productList = []; $scope.checkProduct = function(productlist, product, index){ $scope.addArray[index].id = productlist[index].id; $scope.addArray[index].name = productlist[index].name; $scope.addArray[index].status = productlist[index].status; $scope.productData.productList = $scope.addArray; |
bfbbd8668
|
47 |
console.log($scope.productData) |
bb639860c
|
48 49 50 |
} $scope.updateUser = function(){ |
1b71872b2
|
51 52 53 54 |
var updateData = "companyName=" + $scope.userData.companyName + "&username=" + $scope.userData.username + "&firstName=" + $scope.userData.firstName + "&lastName=" + $scope.userData.lastName + "&phone=" + $scope.userData.phone + "&mobile=" + $scope.userData.mobile + "&status=" + $scope.userData.status + "&userType=" + $scope.userData.userType + "&userTypeId=" + $scope.userData.userType.id + "&userProfileId=" + $scope.userid; |
bb639860c
|
55 56 57 58 59 60 |
AccountSettingService.updateUserProfile(updateData).then(function(result) { AccountSettingService.updateProducts($scope.productData).then(function(result) { toastr.success(''+result.success+'', { closeButton: true |
3c77051a2
|
61 62 |
}); window.localStorage.setItem('currentUserName', JSON.stringify($scope.userData.firstName +' '+ $scope.userData.lastName)); |
8041a48e1
|
63 |
window.localStorage.setItem('companyName', JSON.stringify($scope.userData.companyName)); |
3c77051a2
|
64 |
$scope.currentUserName = JSON.parse(localStorage.getItem('currentUserName')); |
8041a48e1
|
65 |
$scope.companyName= JSON.parse(localStorage.getItem('companyName')) |
3c77051a2
|
66 |
$scope.testFunction(); |
bb639860c
|
67 |
}) |
1b71872b2
|
68 |
|
bb639860c
|
69 70 |
}) } |
4c25c98b5
|
71 72 73 |
$scope.accountdata = {}; $scope.accountdata.userName = ''; $scope.accountdata.status = true; |
ae523d5ef
|
74 75 76 |
$scope.addAccount = function(){ $('#demo-modal').css('display', 'block'); |
ab1d9513c
|
77 |
$scope.accountdata.status = true; |
ae523d5ef
|
78 |
} |
f746aee1b
|
79 |
$scope.cancelAddAccount = function(){ |
1b71872b2
|
80 |
$scope.accountdata = {}; |
ae523d5ef
|
81 82 |
$('#demo-modal').css('display', ''); } |
4c25c98b5
|
83 |
|
f746aee1b
|
84 |
$scope.additionalAccnObj = {}; |
ae523d5ef
|
85 |
$scope.createAddAccount = function(){ |
ab1d9513c
|
86 |
$scope.accountdata.status = true; |
4c25c98b5
|
87 88 |
if ($scope.accountdata.userName === '') { toastr.error('Please enter all the fields.', { |
ae523d5ef
|
89 90 |
closeButton: true }) |
4c25c98b5
|
91 92 |
}else{ if (validateEmail($scope.accountdata.userName)) { |
bfbbd8668
|
93 94 |
console.log("checkbox",$scope.accountdata.allowEpd ,$scope.accountdata.allowFma ) |
4c25c98b5
|
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
AccountSettingService.addAdditionalAccount($scope.accountdata).then(function(result) { getAdditionalAccounts(); $scope.accountdata = {}; $('#demo-modal').css('display', ''); toastr.success(''+result.success+'', { closeButton: true }) }) }else{ toastr.error('Please enter valid email.', { closeButton: true }) } } |
1b71872b2
|
109 |
|
ae523d5ef
|
110 |
} |
4c25c98b5
|
111 112 113 114 115 116 117 118 |
/*Validate Email */ function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } $scope.changeStatus = function(id, index){ |
f746aee1b
|
119 120 121 122 123 124 125 |
event.stopPropagation(); var id = id; var statusData = "status=" + $scope.additionalAccounts[index].status + "&id=" + $scope.additionalAccounts[index].id + "&firstName=" + $scope.additionalAccounts[index].firstName + "&lastName=" + $scope.additionalAccounts[index].lastName + "&username=" + $scope.additionalAccounts[index].userName + "&password=" + $scope.additionalAccounts[index].password + "&allowEpd=" + $scope.additionalAccounts[index].allowEpd + "&allowFma=" + $scope.additionalAccounts[index].allowFma; AccountSettingService.updateStatus(statusData).then(function(result) { if(result.success){ |
1b71872b2
|
126 |
toastr.success('Updated Successfully', { |
f746aee1b
|
127 128 129 130 131 132 133 |
closeButton: true }) } }) } var deleteAccnId = ""; $scope.deleteAdditionalAccount = function(id) { |
1b71872b2
|
134 |
$('#delete1').css('display', 'block'); |
f746aee1b
|
135 |
deleteAccnId = id; |
1b71872b2
|
136 |
|
f746aee1b
|
137 138 139 |
} $scope.accnDelete = function(){ |
1b71872b2
|
140 141 142 |
AccountSettingService.deleteAccount(deleteAccnId).then(function(result) { getAdditionalAccounts(); $('#delete1').css('display', 'none'); |
f746aee1b
|
143 |
if(result.success){ |
1b71872b2
|
144 |
toastr.success('Deleted Successfully', { |
f746aee1b
|
145 146 147 148 149 150 151 |
closeButton: true }) } }) } $scope.cancelDelete = function(){ |
1b71872b2
|
152 |
$('#delete1').css('display', 'none'); |
f746aee1b
|
153 |
} |
ae523d5ef
|
154 |
|
3a9f4472b
|
155 156 |
} })(); |