2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 app.controller('selfProfileController', function ($scope,$http,ProfileService,$routeParams,modalService){
23 $scope.ociavailableRoles=[];
27 $scope.availableRoles = [];
28 $scope.timeZones = [];
29 $scope.selectedTimeZone = null;
30 $scope.countries = [];
31 $scope.selectedCountry = null;
32 $scope.isUserSystemAdmin = false;
34 ProfileService.getSelfProfileDetail().then(function(data){
36 $scope.data = JSON.parse(j.data);
37 $scope.profile =JSON.parse($scope.data.profile);
38 $scope.profileId = $scope.profile.id;
39 $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles);
40 $scope.ociTimeZones=JSON.parse($scope.data.timeZones);
41 $scope.ociCountries=JSON.parse($scope.data.countries);
42 stateList=JSON.parse($scope.data.stateList);
43 $scope.orgUserId=$scope.profile.orgUserId;
44 $scope.orgManagerUserId=$scope.profile.orgManagerUserId;
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);
62 /*$scope.ociTimeZones = ${model.timeZones};*/
64 if($scope.ociTimeZones){
65 $.each($scope.ociTimeZones, function(i, a){
66 var timeZone = {"index":i, "value":a.value, "title":a.label};
67 $scope.timeZones.push(timeZone);
68 if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){
69 $scope.selectedTimeZone = timeZone;
74 /*$scope.ociCountries = ${model.countries};*/
76 //alert($scope.ociCountries[0].label);
77 if($scope.ociCountries)
78 $.each($scope.ociCountries, function(i, a){
79 var country = {"index":i, "value":a.value, "title":a.label};
80 $scope.countries.push(country);
81 if(a.value === $scope.profile.country){
82 $scope.selectedCountry = country;
87 /*var stateList=${model.stateList};*/
88 //alert(stateList[0].label);
89 stateList = stateList== null? []: stateList;
90 var selectedState= $scope.profile.state ? $scope.profile.state:"";
91 $scope.stateList = initDropdownWithLookUp(stateList,selectedState );
95 console.log("failed");
99 /*$scope.profile=${model.profile};*/
100 $scope.orgUserId=$scope.profile.orgUserId;
101 $scope.orgManagerUserId=$scope.profile.orgManagerUserId;
103 $scope.viewPerPage = 2;
104 $scope.currentPage = 1;
106 $scope.searchCategory = "";
107 $scope.searchString = "";
109 $( "#dialog" ).hide();
111 /*$scope.ociavailableRoles=${model.availableRoles};*/
112 //modalService.showFailure('Error','') ;
115 $scope.saveProfile = function() {
116 var uuu = "profile/saveProfile?profile_id=" + $scope.profileId;;
117 var postData={profile: $scope.profile,
118 selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"",
119 selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"",
120 selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:""
126 contentType: 'application/json',
127 data: JSON.stringify(postData),
128 success : function(data){
129 modalService.showSuccess("Success","Update Successful.");
131 error : function(data){
132 modalService.showFailure("Fail","Error while saving.");
137 $scope.addNewRolePopup = function(role) {
138 $( "#dialog" ).dialog({
144 $(".ui-dialog").css("z-index",10002);
145 $(".ui-dialog-titlebar").hide();
148 $scope.toggleRole = function(selected,availableRole) {
149 //alert('toggleRole: '+selected);
152 var uuu = "profile/removeRole?profile_id=" + $scope.profileId;;
153 modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the role "+availableRole.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?",
155 var postData={role:availableRole};
160 contentType: 'application/json',
161 data: JSON.stringify(postData),
162 success : function(data){
163 $scope.$apply(function(){$scope.profile=data;});
165 error : function(data){
166 modalService.showFailure("Fail","Error while saving.");
171 availableRole.selected=!availableRole.selected;
177 var uuu = "profile/addNewRole?profile_id=" + $scope.profileId;;
178 modalService.popupConfirmWinWithCancel("Confirm","You are about to add the role "+availableRole.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?",
180 var postData={role:availableRole};
185 contentType: 'application/json',
186 data: JSON.stringify(postData),
187 success : function(data){
188 $scope.$apply(function(){$scope.profile=data;});
190 error : function(data){
191 modalService.showFailure("Fail","Error while saving.");
196 availableRole.selected=!availableRole.selected;
204 $scope.removeRole = function(role) {
207 modalService.popupConfirmWin("Confirm","You are about to remove the role "+role.name+" from the profile for "+$scope.profile.firstName+" "+$scope.profile.lastName+". Do you want to continue?",
209 var uuu = "profile/removeRole?profile_id=" + $scope.profileId;;
210 var postData={role:role};
215 contentType: 'application/json',
216 data: JSON.stringify(postData),
217 success : function(data){
218 $scope.$apply(function(){
220 $.each($scope.availableRoles, function(k, c){
221 if(c.id === role.id) {
228 error : function(data){
229 modalService.showFailure("Fail","Error while saving.");
238 function initDropdownWithLookUp(arr,selectedValue){
239 var dropdownArray=[];
242 for(var i = 0,l = arr.length; i < l; i++) {
245 "value" : arr[i].value,
246 "title" : arr[i].label
248 dropdownArray.push(option);
249 if(arr[i].value === selectedValue){
255 dropDown.options = dropdownArray;
256 dropDown.selected = selected;
260 $scope.doRolePopup = function() {
261 var modalInstance = $modal.open({
262 templateUrl: 'roles_popup.html',
263 controller: 'rolepopupController',
265 message: function () {
267 availableRoles: $scope.availableRoles
273 modalInstance.result.then(function (opts) {
275 $scope.profile=opts.profile;
280 $scope.close = function(){
281 $('#dialog').dialog('close');