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';
30 /***********************************************************functions***********************************************/
31 $scope.getProfileDetail = function(profileIdParam){
32 $scope.showLoader=true;
33 SelfProfileService.getProfileDetail(profileIdParam).then(function(data){
34 $scope.showLoader=false;
36 $scope.data = JSON.parse(j.data);
37 $scope.profile =JSON.parse($scope.data.profile);
38 $scope.oriProfile=JSON.parse($scope.data.profile); /*original value*/
39 $scope.profileId = $scope.profile.id;
40 $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles);
41 $scope.ociTimeZones=JSON.parse($scope.data.timeZones);
42 $scope.ociCountries=JSON.parse($scope.data.countries);
43 stateList=JSON.parse($scope.data.stateList);
46 if($scope.ociavailableRoles)
47 $.each($scope.ociavailableRoles, function(i, a){
48 var availableRole = a;
49 availableRole.selected = false;
50 $.each($scope.profile.roles, function(j, b){
52 availableRole.selected = true;
54 $scope.isUserSystemAdmin = true;
58 $scope.availableRoles.push(availableRole);
61 if($scope.ociTimeZones){
62 $.each($scope.ociTimeZones, function(i, a){
63 var timeZone = {"index":i, "value":a.value, "title":a.label};
64 $scope.timeZones.push(timeZone);
65 if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){
66 $scope.selectedTimeZone = timeZone;
70 if($scope.ociCountries)
71 $.each($scope.ociCountries, function(i, a){
72 var country = {"index":i, "value":a.value, "title":a.label};
73 $scope.countries.push(country);
74 if(a.value === $scope.profile.country){
75 $scope.selectedCountry = country;
79 stateList = stateList== null? []: stateList;
80 var selectedState= $scope.profile.state ? $scope.profile.state:"";
81 $scope.stateList = initDropdownWithLookUp(stateList,selectedState );
83 $scope.errorPopUp(error);
84 $scope.showLoader=false;
88 $scope.getSelfProfileDetail = function(){
89 $scope.showLoader=true;
90 SelfProfileService.getSelfProfileDetail().then(function(data){
91 $scope.showLoader=false;
93 $scope.data = JSON.parse(j.data);
94 $scope.profile =JSON.parse($scope.data.profile);
95 $scope.oriProfile=JSON.parse($scope.data.profile); /*original value*/
96 $scope.profileId = $scope.profile.id;
97 $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles);
98 $scope.ociTimeZones=JSON.parse($scope.data.timeZones);
99 $scope.ociCountries=JSON.parse($scope.data.countries);
100 stateList=JSON.parse($scope.data.stateList);
102 if($scope.ociavailableRoles)
103 $.each($scope.ociavailableRoles, function(i, a){
104 var availableRole = a;
105 availableRole.selected = false;
106 $.each($scope.profile.roles, function(j, b){
108 availableRole.selected = true;
110 $scope.isUserSystemAdmin = true;
114 $scope.availableRoles.push(availableRole);
117 if($scope.ociTimeZones){
118 $.each($scope.ociTimeZones, function(i, a){
119 var timeZone = {"index":i, "value":a.value, "title":a.label};
120 $scope.timeZones.push(timeZone);
121 if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){
122 $scope.selectedTimeZone = timeZone;
126 if($scope.ociCountries)
127 $.each($scope.ociCountries, function(i, a){
128 var country = {"index":i, "value":a.value, "title":a.label};
129 $scope.countries.push(country);
130 if(a.value === $scope.profile.country){
131 $scope.selectedCountry = country;
135 stateList = stateList== null? []: stateList;
136 var selectedState= $scope.profile.state ? $scope.profile.state:"";
137 $scope.stateList = initDropdownWithLookUp(stateList,selectedState );
139 $scope.errorPopUp(error);
140 $scope.showLoader=false;
145 $scope.removeRole = function(data) {
146 var modalInstance = $modal.open({
147 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/role-del-confirm.html',
148 controller: ModalInstanceCtrl,
149 sizeClass: 'modal-small',
154 roleId:$scope.profileId,
161 $scope.addNewRoleFunctionModalPopup = function(data) {
162 var modalInstance = $modal.open({
163 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/role-add.html',
164 controller: ModalInstanceCtrl,
165 windowClass:'modal-docked',
166 sizeClass: 'modal-medium',
171 roleId:$scope.profileId,
172 availableRoleFunctions:$scope.ociavailableRoles
181 $scope.successPopUp = function () {
182 var modalInstance = $modal.open({
183 templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html',
184 controller: ModalInstanceCtrl,
185 sizeClass: 'modal-small',
194 $scope.errorPopUp = function (msg) {
195 var modalInstance = $modal.open({
196 templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html',
197 controller: ModalInstanceCtrl,
198 sizeClass: 'modal-small',
206 $scope.saveProfile = function() {
207 $scope.errorMsg = '';
208 if($scope.oriProfile.orgUserId != $scope.profile.orgUserId){
209 $scope.errorPopUp('Organization User ID cannot be changed');
212 if($scope.oriProfile.orgManagerUserId != $scope.profile.orgManagerUserId){
213 $scope.errorPopUp('Organization Manager ID cannot be changed');
216 if($scope.oriProfile.loginId != $scope.profile.loginId){
217 $scope.errorPopUp('Login ID cannot be changed');
220 if($scope.oriProfile.loginPwd != $scope.profile.loginPwd){
221 $scope.errorPopUp('Login Password cannot be changed');
226 profile: $scope.profile,
227 selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"",
228 selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"",
229 selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:""
231 SelfProfileService.saveProfile(postData, $scope.profileId).then(function(msg){
232 $scope.successPopUp();
234 $scope.errorPopUp(error);
237 /* updating role tables after adding or deleting*/
238 $rootScope.$on('updateRoles',function(e,d){
239 $scope.profile.roles = d.data;
241 /*****init call*****/
243 if ($scope.pageType==2){
244 $scope.getProfileDetail($scope.profileIdParam);
246 $scope.getSelfProfileDetail();
250 /****************************************************************popup modal*************************************************************/
251 var ModalInstanceCtrl = function ($scope, $modalInstance, items,$rootScope) {
252 $scope.roleFun=items;
254 $scope.activateRoleConfirmPopUp = function (selected, availableRole) {
255 $scope.msg.roleFun = availableRole.name;
256 $scope.msg.selected = selected;
257 $scope.msg.availableRole = availableRole;
258 var modalInstance = $modal.open({
259 templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/role-add-confirm.html',
260 controller: ModalInstanceCtrl,
261 sizeClass: 'modal-small',
269 $scope.confirmRoleDel = function(role,profileId){
270 var postData={role:role};
271 SelfProfileService.removeRole(postData,profileId).then(function(msg){
273 $scope.roleTableRefresh(profileId);
275 $scope.errorPopUp(error);
278 $scope.confirmRoleFunAdd = function(availableRole,profileId){
279 var postData={role:availableRole};
280 SelfProfileService.addRole(postData,profileId).then(function(msg){
282 $scope.roleTableRefresh(profileId);
284 $scope.errorPopUp(error);
288 // confirm Role Function Remove
289 $scope.confirmRoleFunRemove = function(availableRole,profileId){
290 var postData={role:availableRole};
291 SelfProfileService.deRole(postData,profileId).then(function(msg){
293 $scope.roleTableRefresh(profileId);
295 $scope.errorPopUp(error);
299 $scope.cancel = function () {
300 $modalInstance.dismiss('cancel');
303 $scope.cancelRoleFunSwitch = function (msg) {
304 $scope.msg.availableRole.selected = !$scope.msg.availableRole.selected;
305 $modalInstance.dismiss('cancel');
308 $scope.selfProfileRoleRefresh = function(){
309 SelfProfileService.getSelfProfileDetail().then(function(data){
311 $scope.data = JSON.parse(j.data);
312 $scope.profileTemp =JSON.parse($scope.data.profile);
313 $rootScope.$broadcast('updateRoles',{data:$scope.profileTemp.roles});
316 $scope.profileRoleRefresh = function(profileId){
317 SelfProfileService.getProfileDetail(profileId).then(function(data){
319 $scope.data = JSON.parse(j.data);
320 $scope.profileTemp =JSON.parse($scope.data.profile);
321 $rootScope.$broadcast('updateRoles',{data:$scope.profileTemp.roles});
324 $scope.roleTableRefresh = function (profileId) {
325 if($scope.pageType==1)
326 $scope.selfProfileRoleRefresh();
328 $scope.profileRoleRefresh(profileId);
334 function initDropdownWithLookUp(arr,selectedValue){
335 var dropdownArray=[];
338 for(var i = 0,l = arr.length; i < l; i++) {
341 "value" : arr[i].value,
342 "title" : arr[i].label
344 dropdownArray.push(option);
345 if(arr[i].value === selectedValue){
351 dropDown.options = dropdownArray;
352 dropDown.selected = selected!=null?selected:{"index":'',"value":"","title":""};