5236001f61e1e7feb5f3697ee70d803be06533ea
[portal/sdk.git] /
1 appDS2.controller('profileSearchCtrlDS2', function($scope, $log, $modal, ProfileServiceDS2){
2     $scope.showInput = true;
3     $scope.totalPages1 = 0;
4     $scope.viewPerPage1 = 8;
5     $scope.currentPage1 = 1;
6     $scope.showLoader = false;
7
8     var debug = false;
9     
10         $scope.$watch('viewPerPage1', function(val) {
11                 $scope.showLoader = true;
12                 ProfileServiceDS2.getProfilePagination($scope.currentPage1, val).then(function(data){
13                 var j = data;
14                 $scope.data = JSON.parse(j.data);
15                 $scope.tableData =JSON.parse($scope.data.profileList);                  
16                 $scope.totalPages1 =JSON.parse($scope.data.totalPage);
17                 $scope.showLoader = false;
18         },function(error){
19                 console.log("watch of viewPerPage1 failed");
20                 reloadPageOnce();
21         });
22                 
23         });
24             
25         $scope.customHandler = function(num) {
26                 $scope.currentPage1 = num;       
27                 $scope.showLoader = true;
28                 ProfileServiceDS2.getProfilePagination($scope.currentPage1,$scope.viewPerPage1).then(function(data){
29                         var j = data;
30                         $scope.data = JSON.parse(j.data);
31                         $scope.tableData =JSON.parse($scope.data.profileList);
32                         $scope.totalPages1 =JSON.parse($scope.data.totalPage);
33                         $scope.showLoader = false;
34                 },function(error){
35                         console.log("customHandler failed");
36                         reloadPageOnce();
37                 });
38
39             };
40
41         $scope.editRow = function(profileId){
42         window.location = 'userProfile#/profile/' + profileId;
43     };
44    
45         var ModalInstanceCtrl = function ($scope, $log, $modalInstance, items) {
46                 $scope.msg = items;
47         
48                 $scope.toggleUserStatus = function(id) {
49                         if (debug)
50                                 $log.debug('profileSearchCtrlDS2:ModalInstanceCtrl:toggleUserStatus: data is ' + id);
51                         ProfileServiceDS2.toggleProfileStatus(id);
52                 $modalInstance.close();
53                 };
54     
55                 $scope.cancelUserStatusToggle = function(rowData) {
56                         if (debug)
57                                 $log.debug('profileSearchCtrlDS2:ModalInstanceCtrl: cancelUserStatusToggle: data is ' + JSON.stringify(rowData));
58                         // Undo the toggle of the checkbox
59                         rowData.active = ! rowData.active;
60                         $modalInstance.dismiss('cancel');
61                 }       
62                 
63         }
64
65         // user activation/deactivation
66         $scope.toggleProfileActive = function(rowData) {
67                 if (debug)
68                         $log.debug('profileSearchCtrlDS2:toggleProfileActive: id is ' + rowData.id 
69                                 + ', active is ' + rowData.active);
70                 var toggleType = null;
71                 // The checkbox is already in the desired state,
72                 // so the sense of the "if" is reversed here.
73                 if (rowData.active)
74                         toggleType = "activate";
75                 else
76                         toggleType = "deactivate";
77                 var modalInstance = $modal.open({
78                         templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-profile/modals/profile-confirm-toggle.html',
79                         controller: ModalInstanceCtrl,
80                         sizeClass: 'modal-small', 
81                         resolve: {
82                                 items: function () {
83                                         var message = {
84                                                 text : toggleType,
85                                                 rowData : rowData
86                                         };
87                                         return message;
88                                 }
89                 }
90                 });
91         };
92     
93 });