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('profileController', 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;
33 ProfileService.getProfileDetail($routeParams.profileId).then(function(data){
35 $scope.data = JSON.parse(j.data);
36 $scope.profile =JSON.parse($scope.data.profile);
37 $scope.ociavailableRoles =JSON.parse($scope.data.availableRoles);
38 $scope.ociTimeZones=JSON.parse($scope.data.timeZones);
39 $scope.ociCountries=JSON.parse($scope.data.countries);
40 stateList=JSON.parse($scope.data.stateList);
41 $scope.orgUserId=$scope.profile.orgUserId;
42 $scope.orgManagerUserId=$scope.profile.orgManagerUserId;
45 if($scope.ociavailableRoles)
46 $.each($scope.ociavailableRoles, function(i, a){
47 var availableRole = a;
48 availableRole.selected = false;
49 $.each($scope.profile.roles, function(j, b){
51 availableRole.selected = true;
54 $scope.availableRoles.push(availableRole);
58 /*$scope.ociTimeZones = ${model.timeZones};*/
60 if($scope.ociTimeZones){
61 $.each($scope.ociTimeZones, function(i, a){
62 var timeZone = {"index":i, "value":a.value, "title":a.label};
63 $scope.timeZones.push(timeZone);
64 if($scope.profile.timeZoneId !== null && a.value === $scope.profile.timeZoneId.toString()){
65 $scope.selectedTimeZone = timeZone;
70 /*$scope.ociCountries = ${model.countries};*/
72 //alert($scope.ociCountries[0].label);
73 if($scope.ociCountries)
74 $.each($scope.ociCountries, function(i, a){
75 var country = {"index":i, "value":a.value, "title":a.label};
76 $scope.countries.push(country);
77 if(a.value === $scope.profile.country){
78 $scope.selectedCountry = country;
83 /*var stateList=${model.stateList};*/
84 //alert(stateList[0].label);
85 stateList = stateList== null? []: stateList;
86 var selectedState= $scope.profile.state ? $scope.profile.state:"";
87 $scope.stateList = initDropdownWithLookUp(stateList,selectedState );
91 console.log("failed");
95 /*$scope.profile=${model.profile};*/
96 $scope.orgUserId=$scope.profile.orgUserId;
97 $scope.orgManagerUserId=$scope.profile.orgManagerUserId;
99 $scope.viewPerPage = 2;
100 $scope.currentPage = 1;
102 $scope.searchCategory = "";
103 $scope.searchString = "";
105 $( "#dialog" ).hide();
107 /*$scope.ociavailableRoles=${model.availableRoles};*/
108 //modalService.showFailure('Error','') ;
111 $scope.saveProfile = function() {
112 var uuu = "profile/saveProfile?profile_id=" + $routeParams.profileId;
113 var postData={profile: $scope.profile,
114 selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"",
115 selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"",
116 selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:""
122 contentType: 'application/json',
123 data: JSON.stringify(postData),
124 success : function(data){
125 modalService.showSuccess("Success","Update Successful.");
127 error : function(data){
128 modalService.showFailure("Fail","Error while saving.");
133 $scope.addNewRolePopup = function(role) {
134 $( "#dialog" ).dialog({
139 $(".ui-dialog").css("z-index",2001);
140 $(".ui-dialog-titlebar").hide();
143 $scope.toggleRole = function(selected,availableRole) {
144 $scope.profileTemp=$scope.profile;
146 //alert('toggleRole: '+selected);
149 var uuu = "profile/removeRole?profile_id=" + $routeParams.profileId;
150 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?",
152 var postData={role:availableRole};
157 contentType: 'application/json',
158 data: JSON.stringify(postData),
159 success : function(data){
160 $scope.$apply(function(){$scope.profile=data;});
162 error : function(data){
163 $scope.$apply(function(){$scope.profile=$scope.profileTemp;});
164 modalService.showFailure("Fail","Error while saving.");
169 availableRole.selected=!availableRole.selected;
175 var uuu = "profile/addNewRole?profile_id=" + $routeParams.profileId;
176 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?",
178 var postData={role:availableRole};
183 contentType: 'application/json',
184 data: JSON.stringify(postData),
185 success : function(data){
186 $scope.$apply(function(){$scope.profile=data;});
188 error : function(data){
189 $scope.$apply(function(){$scope.profile=$scope.profileTemp;});
190 modalService.showFailure("Fail","Error while saving.");
195 availableRole.selected=!availableRole.selected;
203 $scope.removeRole = function(role) {
206 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?",
208 $scope.profileTemp=$scope.profile;
210 var uuu = "profile/removeRole?profile_id=" + $routeParams.profileId;
211 var postData={role:role};
216 contentType: 'application/json',
217 data: JSON.stringify(postData),
218 success : function(data){
219 $scope.$apply(function(){
221 $.each($scope.availableRoles, function(k, c){
222 if(c.id === role.id) {
229 error : function(data){
230 $scope.$apply(function(){$scope.profile=$scope.profileTemp;});
231 modalService.showFailure("Fail","Error while saving.");
240 function initDropdownWithLookUp(arr,selectedValue){
241 var dropdownArray=[];
244 for(var i = 0,l = arr.length; i < l; i++) {
247 "value" : arr[i].value,
248 "title" : arr[i].label
250 dropdownArray.push(option);
251 if(arr[i].value === selectedValue){
257 dropDown.options = dropdownArray;
258 dropDown.selected = selected;
262 $scope.doRolePopup = function() {
263 var modalInstance = $modal.open({
264 templateUrl: 'roles_popup.html',
265 controller: 'rolepopupController',
267 message: function () {
269 availableRoles: $scope.availableRoles
275 modalInstance.result.then(function (opts) {
277 $scope.profile=opts.profile;
282 $scope.close = function(){
283 $('#dialog').dialog('close');