Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / jsp / broadcast_list.jsp
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 <%@ page import="java.util.*" %>
21 <%@ page import="com.fasterxml.jackson.databind.ObjectMapper" %>
22 <%@ page import="org.json.JSONObject" %>
23 <%@ page import="java.io.StringWriter" %>
24 <%@ page import="org.openecomp.portalsdk.core.web.support.ControllerProperties" %>
25 <%@ taglib prefix="c"      uri="http://java.sun.com/jsp/jstl/core" %>
26 <%@ taglib prefix="fmt"    uri="http://java.sun.com/jsp/jstl/fmt" %>
27 <%@ taglib prefix="fn"     uri="http://java.sun.com/jsp/jstl/functions" %>
28
29   <script src="static/fusion/raptor/dy3/js/moment.min.js"></script>
30   <script>
31     function editMessage(messageLocationId, messageLocation, messageId) {
32       window.location='broadcast.htm?message_location_id='+messageLocationId + '&message_location=' + messageLocation + ((messageId != null) ? '&message_id=' + messageId : '');
33     }
34   </script>
35
36   <div class="pageTitle">
37   <h3>
38     Broadcast Messages
39     </h3>
40   </div>
41
42   <%-- Display a table for the broadcast messages of each message location --%>
43 <div ng-controller="broadcastListController" >  
44
45         <div ng-repeat="location in messageLocations" >
46                 {{location.label}} Messages
47                 <div title="{{location.label}} Messages" >
48
49                         <table att-table table-data="location.messages" current-page="1">
50                                 <thead att-table-row type="header">
51                                         <tr>
52                                                 <th att-table-header sortable="false" width="10%">No.</th>
53                                                 <th att-table-header sortable="false" width="30%">Message Text</th>
54                                                 <th att-table-header sortable="false" width="10%">Start Date</th>
55                                                 <th att-table-header sortable="false" width="10%">End Date</th>
56                                                 <th att-table-header sortable="false" width="10%">Sort Order</th>
57                                                 <th att-table-header sortable="false" width="10%">Server</th>
58                                                 <th att-table-header sortable="false" width="10%">Active?</th>
59                                                 <th att-table-header sortable="false" width="10%">Delete?</th>
60                                         </tr>
61                                 </thead>
62                                 <tbody att-table-row type="body" row-repeat="message in location.messages" style="max-height: 980px;" ><!-- background colors will alternate not properly with multiple tbody-->
63                                   <tr>
64                                    {{message.id}}
65                                     <td width="10%"><a href="javascript:editMessage({{location.value}},'{{location.label}}',{{message.id}});">{{$index+1}}</a></td>
66                                     <td width="30%">{{message.messageText}}</td>
67                                     <td width="10%">
68                                         {{message.displayStartDate}}
69                                     </td>
70                                     <td width="10%">{{message.displayEndDate}}</td>
71                                     <td width="10%">{{message.sortOrder}}</td>
72                                     <td width="10%">{{message.siteCd}}</td>
73                                     <td width="10%">
74                                         <div ng-click="toggleActive(message);">
75                                                 <input type="checkbox" ng-model="message.active" att-toggle-main>
76                                         </div>
77                                     </td>
78                                      <td att-table-body width="10%">
79                                             <div ng-click="remove(message);" style="font-size:20px;"><a href="javascript:void(0)" class="ion-trash-b"></a></div>
80                                      </td>
81                                   </tr>
82                                  
83                                 </tbody>
84                         </table>
85                 </div>
86                 <input att-button btn-type="primary" size="small" class="button" type="button" value="Add" ng-click="editMessage(location);"/>
87           <br/><br/><br/>
88         </div>
89 </div>
90
91 <script>
92 app.controller('broadcastListController', function ($scope){
93         //$scope.model.messagesList=${model.messagesList};
94         var messagesMap = {};
95         <%
96                 ObjectMapper mapper = new ObjectMapper();
97                 HashMap hmMessages = new HashMap();
98             
99                 HashMap objModel = (HashMap)request.getAttribute("model");
100                 
101             Object objMessages = objModel.get("messagesList");
102             //System.out.println("messagesList: "+objMessages);
103             if((objMessages!=null) && (objMessages instanceof HashMap))
104             {
105                 hmMessages= (HashMap)objMessages;
106               Iterator it = hmMessages.entrySet().iterator();
107               while (it.hasNext()) {
108                   Map.Entry pair = (Map.Entry)it.next();
109                   //System.out.println(pair.getKey() + " = " + pair.getValue());
110                   String pairValue = mapper.writeValueAsString(pair.getValue());
111                   //System.out.println(pairValue);
112                   %>
113                   messagesMap['<%=pair.getKey()%>'] = '<%=pairValue%>'
114                   <%
115               }
116             }
117             
118             Object messageLocationsObject =  objModel.get("messageLocations");
119             //System.out.println("messageLocations: "+messageLocationsObject);
120                 String messageLocationsString = mapper.writeValueAsString(messageLocationsObject);
121                 //System.out.println(messageLocationsString);
122         %>
123         $scope.messagesList=messagesMap;        
124         $scope.messageLocations=<%=messageLocationsString%>;
125         console.log($scope.messageLocations);
126         
127         $.each($scope.messageLocations, function(i, a){ 
128                 //var result = [];
129             angular.forEach($scope.messagesList, function(value, key) {
130                 if (key+'' === a.value+'') {
131                         var objsJSON = JSON.parse(value);
132                         
133                         $.each(objsJSON, function(i, a){ 
134                                 var startDateLong = a.startDate;
135                                 var tempStartDate = new Date(startDateLong);
136                                 tempStartDate = moment(tempStartDate).format('DD MMM YYYY');//03 Jun 2013 04:15PM EDT - 'DD MMM YYYY hh:mmA zz'
137                                 a.displayStartDate=tempStartDate.toString();
138                                 
139                                 var endDateLong = a.endDate;
140                                 var tempEndDate = new Date(endDateLong);
141                                 tempEndDate = moment(tempEndDate).format('DD MMM YYYY');//03 Jun 2013 04:15PM EDT
142                                 a.displayEndDate=tempEndDate.toString();
143                         });
144                         a.messages = objsJSON;
145                 }
146             }); 
147             console.log(a.messages);
148         });     
149         ;
150         
151         $scope.editMessage = function(location) {
152                 editMessage(location.value, location.label);
153         };
154         
155         $scope.toggleActive = function(broadcastMessage) {
156
157                 //alert('deleted'+role.name);
158                 var uuu = "broadcast_list/toggleActive";
159                   var postData={broadcastMessage:broadcastMessage};
160                   $.ajax({
161                          type : 'POST',
162                          url : uuu,
163                          dataType: 'json',
164                          contentType: 'application/json',
165                          data: JSON.stringify(postData),
166                          success : function(data){
167                                 //window.location.reload();  
168                          },
169                          error : function(data){
170                                  console.log(data);
171                                  alert("Error while toggling: "+ data.responseText);
172                          }
173                   });
174         
175         
176         };
177         
178         $scope.remove = function(broadcastMessage) {
179
180                         //alert('deleted'+role.name);
181                         var uuu = "broadcast_list/remove";
182                           var postData={broadcastMessage:broadcastMessage};
183                           $.ajax({
184                                  type : 'POST',
185                                  url : uuu,
186                                  dataType: 'json',
187                                  contentType: 'application/json',
188                                  data: JSON.stringify(postData),
189                                  success : function(data){
190                                         window.location.reload();  
191                                  },
192                                  error : function(data){
193                                          console.log(data);
194                                          alert("Error while deleting: "+ data.responseText);
195                                  }
196                           });
197                 
198                 
199         };
200 });
201 </script>