Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / controllers / broadcast-list-controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 app.controller('broadcastListController', function ($scope, modalService, $modal,AdminService){
21         //$scope.broadcastMessage=${broadcastMessage};
22         //$scope.broadcastSites=${broadcastSites};
23         //console.log($scope.broadcastMessage);
24         var messagesMap = {};
25         AdminService.getBroadcastList().then(function(data){ 
26                         
27                         var j = data;
28                         $scope.data = JSON.parse(j.data);
29                         $scope.messagesList=(($scope.data.messagesList===null) ? [""]:$scope.data.messagesList);
30                         $scope.messageLocations=(($scope.data.messageLocations===null) ? [""]:$scope.data.messageLocations);
31                         console.log("messages: "+$scope.messagesList);
32                         console.log("location: "+$scope.messageLocations);
33                         $.each($scope.messageLocations, function(i, a){ 
34                                 //var result = [];
35                             angular.forEach($scope.messagesList, function(value, key) {
36                                 if (key+'' === a.value+'') {
37                                         //var objsJSON = JSON.parse(value);
38                                         
39                                         $.each(value, function(i, a){ 
40                                                 var startDateLong = a.startDate;
41                                                 var tempStartDate = new Date(startDateLong);
42                                                 tempStartDate = moment(tempStartDate).format('DD MMM YYYY hh:mmA zz');//03 Jun 2013 04:15PM EDT
43                                                 a.displayStartDate=tempStartDate.toString();
44                                                 
45                                                 var endDateLong = a.endDate;
46                                                 var tempEndDate = new Date(endDateLong);
47                                                 tempEndDate = moment(tempEndDate).format('DD MMM YYYY hh:mmA zz');//03 Jun 2013 04:15PM EDT
48                                                 a.displayEndDate=tempEndDate.toString();
49                                         });
50                                         a.messages = value;
51                                 }
52                             }); 
53                             console.log(a.messages);
54                         });     
55                         
56                         //$scope.resetMenu();
57                 
58                 },function(error){
59                         console.log("failed");
60                         reloadPageOnce();
61         });
62         
63         
64         $scope.editMessage = function(location) {
65                 
66                 editMessage(location.value, location.label);
67         };
68         
69         $scope.toggleActive = function(broadcastMessage) {
70
71                 //alert('deleted'+role.name);
72                 var uuu = "broadcast_list/toggleActive";
73                   var postData={broadcastMessage:broadcastMessage};
74                   $.ajax({
75                          type : 'POST',
76                          url : uuu,
77                          dataType: 'json',
78                          contentType: 'application/json',
79                          data: JSON.stringify(postData),
80                          success : function(data){
81                                 //window.location.reload();  
82                          },
83                          error : function(data){
84                                  console.log(data);
85                                  modalService.showFailure("Fail","Error while toggling: "+ data.responseText);
86                                  
87                          }
88                   });
89         
90         
91         };
92         
93         $scope.remove = function(broadcastMessage) {
94
95                         //alert('deleted'+role.name);
96                           var uuu = "broadcast_list/remove";
97                           var postData={broadcastMessage:broadcastMessage};
98                           $.ajax({
99                                  type : 'POST',
100                                  url : uuu,
101                                  dataType: 'json',
102                                  contentType: 'application/json',
103                                  data: JSON.stringify(postData),
104                                  success : function(data){
105                                         window.location.reload();  
106                                  },
107                                  error : function(data){
108                                          console.log(data);
109                                          modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
110                                  }
111                           });
112                 
113                 
114         };
115         
116 });
117
118 function editMessage(messageLocationId, messageLocation, messageId) {
119     window.location='admin#/broadcast/'+messageLocationId + '/' + messageLocation + ((messageId != null) ? '/' + messageId : '');
120 }