1 appDS2.controller('selfProfileController', function($scope, $http, $modal, $routeParams, $rootScope,SelfProfileService){
3 /************init values***********************/
7 $scope.ociavailableRoles=[];
11 $scope.availableRoles = [];
12 $scope.timeZones = [];
13 $scope.selectedTimeZone = {"index":'',"value":"","title":""};
14 $scope.countries = [];
15 $scope.selectedCountry = {"index":'',"value":"","title":""};
17 $scope.isUserSystemAdmin = false;
19 $scope.showLoader=false;
20 $scope.pageType=1 /*1 for slef page 2 for general profile page*/
21 $scope.pageTitle='Self Profile Detail';
22 $scope.profileIdParam = $routeParams.profileId;
23 if (typeof($scope.profileIdParam) != "undefined" && $scope.profileIdParam!=''){
24 $scope.pageTitle='Profile Detail';
28 $scope.sbcid=$scope.profile.sbcid;
29 $scope.managerAttuid=$scope.profile.managerAttuid;
31 /***********************************************************functions***********************************************/
32 $scope.getProfileDetail = function(profileIdParam){
33 $scope.showLoader=true;
34 SelfProfileService.getProfileDetail(profileIdParam).then(function(data){
35 $scope.showLoader=false;
37 $scope.data = JSON.parse(j.data);
38 $scope.profile =JSON.parse($scope.data.profile);
39 $scope.oriProfile=JSON.parse($scope.data.profile); /*original value*/
40 $scope.profileId = $scope.profile.id;
41 $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles);
42 $scope.ociTimeZones=JSON.parse($scope.data.timeZones);
43 $scope.ociCountries=JSON.parse($scope.data.countries);
44 stateList=JSON.parse($scope.data.stateList);
45 $scope.sbcid=$scope.profile.sbcid;
46 $scope.managerAttuid=$scope.profile.managerAttuid;
48 if($scope.ociavailableRoles)
49 $.each($scope.ociavailableRoles, function(i, a){
50 var availableRole = a;
51 availableRole.selected = false;
52 $.each($scope.profile.roles, function(j, b){
54 availableRole.selected = true;
56 $scope.isUserSystemAdmin = true;
60 $scope.availableRoles.push(availableRole);
63 if($scope.ociTimeZones){
64 $.each($scope.ociTimeZones, function(i, a){
65 var timeZone = {"index":i, "value":a.value, "title":a.label};
66 $scope.timeZones.push(timeZone);
67 if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){
68 $scope.selectedTimeZone = timeZone;
72 if($scope.ociCountries)
73 $.each($scope.ociCountries, function(i, a){
74 var country = {"index":i, "value":a.value, "title":a.label};
75 $scope.countries.push(country);
76 if(a.value === $scope.profile.country){
77 $scope.selectedCountry = country;
81 stateList = stateList== null? []: stateList;
82 var selectedState= $scope.profile.state ? $scope.profile.state:"";
83 $scope.stateList = initDropdownWithLookUp(stateList,selectedState );
85 $scope.errorPopUp(error);
86 $scope.showLoader=false;
90 $scope.getSelfProfileDetail = function(){
91 $scope.showLoader=true;
92 SelfProfileService.getSelfProfileDetail().then(function(data){
93 $scope.showLoader=false;
95 $scope.data = JSON.parse(j.data);
96 $scope.profile =JSON.parse($scope.data.profile);
97 $scope.oriProfile=JSON.parse($scope.data.profile); /*original value*/
98 $scope.profileId = $scope.profile.id;
99 $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles);
100 $scope.ociTimeZones=JSON.parse($scope.data.timeZones);
101 $scope.ociCountries=JSON.parse($scope.data.countries);
102 stateList=JSON.parse($scope.data.stateList);
103 $scope.sbcid=$scope.profile.sbcid;
104 $scope.managerAttuid=$scope.profile.managerAttuid;
106 if($scope.ociavailableRoles)
107 $.each($scope.ociavailableRoles, function(i, a){
108 var availableRole = a;
109 availableRole.selected = false;
110 $.each($scope.profile.roles, function(j, b){
112 availableRole.selected = true;
114 $scope.isUserSystemAdmin = true;
118 $scope.availableRoles.push(availableRole);
121 if($scope.ociTimeZones){
122 $.each($scope.ociTimeZones, function(i, a){
123 var timeZone = {"index":i, "value":a.value, "title":a.label};
124 $scope.timeZones.push(timeZone);
125 if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){
126 $scope.selectedTimeZone = timeZone;
130 if($scope.ociCountries)
131 $.each($scope.ociCountries, function(i, a){
132 var country = {"index":i, "value":a.value, "title":a.label};
133 $scope.countries.push(country);
134 if(a.value === $scope.profile.country){
135 $scope.selectedCountry = country;
139 stateList = stateList== null? []: stateList;
140 var selectedState= $scope.profile.state ? $scope.profile.state:"";
141 $scope.stateList = initDropdownWithLookUp(stateList,selectedState );
143 $scope.errorPopUp(error);
144 $scope.showLoader=false;
149 $scope.removeRole = function(data) {
150 var modalInstance = $modal.open({
151 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/role-del-confirm.html',
152 controller: ModalInstanceCtrl,
153 sizeClass: 'modal-small',
158 roleId:$scope.profileId,
165 $scope.addNewRoleFunctionModalPopup = function(data) {
166 var modalInstance = $modal.open({
167 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/role-add.html',
168 controller: ModalInstanceCtrl,
169 windowClass:'modal-docked',
170 sizeClass: 'modal-medium',
175 roleId:$scope.profileId,
176 availableRoleFunctions:$scope.ociavailableRoles
185 $scope.successPopUp = function () {
186 var modalInstance = $modal.open({
187 templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html',
188 controller: ModalInstanceCtrl,
189 sizeClass: 'modal-small',
198 $scope.errorPopUp = function (msg) {
199 var modalInstance = $modal.open({
200 templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html',
201 controller: ModalInstanceCtrl,
202 sizeClass: 'modal-small',
210 $scope.saveProfile = function() {
211 $scope.errorMsg = '';
212 if($scope.oriProfile.orgUserId != $scope.profile.orgUserId){
213 $scope.errorPopUp('Organization User ID cannot be changed');
216 if($scope.oriProfile.orgManagerUserId != $scope.profile.orgManagerUserId){
217 $scope.errorPopUp('Organization Manager ID cannot be changed');
220 if($scope.oriProfile.loginId != $scope.profile.loginId){
221 $scope.errorPopUp('Login ID cannot be changed');
224 if($scope.oriProfile.loginPwd != $scope.profile.loginPwd){
225 $scope.errorPopUp('Login Password cannot be changed');
230 profile: $scope.profile,
231 selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"",
232 selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"",
233 selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:""
235 SelfProfileService.saveProfile(postData, $scope.profileId).then(function(msg){
236 $scope.successPopUp();
238 $scope.errorPopUp(error);
241 /* updating role tables after adding or deleting*/
242 $rootScope.$on('updateRoles',function(e,d){
243 $scope.profile.roles = d.data;
245 /*****init call*****/
247 if ($scope.pageType==2){
248 $scope.getProfileDetail($scope.profileIdParam);
250 $scope.getSelfProfileDetail();
254 /****************************************************************popup modal*************************************************************/
255 var ModalInstanceCtrl = function ($scope, $modalInstance, items,$rootScope) {
256 $scope.roleFun=items;
258 $scope.activateRoleConfirmPopUp = function (selected, availableRole) {
259 $scope.msg.roleFun = availableRole.name;
260 $scope.msg.selected = selected;
261 $scope.msg.availableRole = availableRole;
262 var modalInstance = $modal.open({
263 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/role-add-confirm.html',
264 controller: ModalInstanceCtrl,
265 sizeClass: 'modal-small',
273 $scope.confirmRoleDel = function(role,profileId){
274 var postData={role:role};
275 SelfProfileService.removeRole(postData,profileId).then(function(msg){
277 $scope.roleTableRefresh(profileId);
279 $scope.errorPopUp(error);
282 $scope.confirmRoleFunAdd = function(availableRole,profileId){
283 var postData={role:availableRole};
284 SelfProfileService.addRole(postData,profileId).then(function(msg){
286 $scope.roleTableRefresh(profileId);
288 $scope.errorPopUp(error);
292 // confirm Role Function Remove
293 $scope.confirmRoleFunRemove = function(availableRole,profileId){
294 var postData={role:availableRole};
295 SelfProfileService.deRole(postData,profileId).then(function(msg){
297 $scope.roleTableRefresh(profileId);
299 $scope.errorPopUp(error);
303 $scope.cancel = function () {
304 $modalInstance.dismiss('cancel');
307 $scope.cancelRoleFunSwitch = function (msg) {
308 $scope.msg.availableRole.selected = !$scope.msg.availableRole.selected;
309 $modalInstance.dismiss('cancel');
312 $scope.selfProfileRoleRefresh = function(){
313 SelfProfileService.getSelfProfileDetail().then(function(data){
315 $scope.data = JSON.parse(j.data);
316 $scope.profileTemp =JSON.parse($scope.data.profile);
317 $rootScope.$broadcast('updateRoles',{data:$scope.profileTemp.roles});
320 $scope.profileRoleRefresh = function(profileId){
321 SelfProfileService.getProfileDetail(profileId).then(function(data){
323 $scope.data = JSON.parse(j.data);
324 $scope.profileTemp =JSON.parse($scope.data.profile);
325 $rootScope.$broadcast('updateRoles',{data:$scope.profileTemp.roles});
328 $scope.roleTableRefresh = function (profileId) {
329 if($scope.pageType==1)
330 $scope.selfProfileRoleRefresh();
332 $scope.profileRoleRefresh(profileId);
338 function initDropdownWithLookUp(arr,selectedValue){
339 var dropdownArray=[];
342 for(var i = 0,l = arr.length; i < l; i++) {
345 "value" : arr[i].value,
346 "title" : arr[i].label
348 dropdownArray.push(option);
349 if(arr[i].value === selectedValue){
355 dropDown.options = dropdownArray;
356 dropDown.selected = selected!=null?selected:{"index":'',"value":"","title":""};