Added new modules to help prevent Cross Site Request Forgery
[sdnc/oam.git] / admportal / views / mobility / vnfPreloadNetworkData.ejs
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4   <meta charset="UTF-8" />
5   <meta http-equiv="X-UA-Compatible" content="IE=edge">
6   <% include ../partials/head %>
7   <% include ../partials/header %>
8   <script type="text/javascript" src="/javascripts/admportal.js" async></script>
9   <title>SDN-C AdminPortal</title>
10 <script class="init">
11     $(document).ready(function() {
12     $('#preload_vnf_data').DataTable( {
13         "order": [[ 0, "asc" ]]
14     } );
15 } );
16 </script>
17
18
19 </head>
20 <body>
21
22 <div class="well well-sm">
23 <h3>Pre-load VNF Network Data</h3>
24 </div>
25
26 <% if ( typeof result != 'undefined' ) {
27                 if (result.code.length > 0) { 
28                         if ( result.code == 'success' ) { %>
29                                 <div class='alert alert-success' role='alert'>
30                                 <%
31                                 for ( x in result.msg ){ %>
32                                         <div><%= result.msg[x] %></div>
33                                 <% } %>
34                                 </div>
35                         <% } else { %> 
36                                 <div class='alert alert-danger' role='danger'>
37                                 <%
38                                 for ( x in result.msg ){ %>
39                                         <div><%= result.msg[x] %></div>
40                                 <% } %>
41                                 </div>
42                         <% } %>
43                 <% } %>
44 <% } %>
45
46 <% if( typeof privilege != 'undefined'){
47     var priv = privilege.privilege;
48 } else {
49     var priv = 'A';
50 } %>
51
52
53 <div class="container-fluid">
54
55         <table id="preload_vnf_data" class="table table-hover table-condensed">
56       <thead>
57         <tr>
58                   <th>ID</th>
59                   <th>SVC_REQUEST_ID</th>
60                   <th>NETWORK_NAME</th>
61                   <th>NETWORK_TYPE</th>
62                   <th>SVC_ACTION</th>
63                   <th>UPLOAD STATUS</th>
64           <th>FILENAME</th>
65           <th>IMPORT/UPLOAD TIMESTAMP</th>
66                   <% if(priv == 'A'){ %>
67           <th>Action</th>
68           <% } %>
69         </tr>
70       </thead>
71       <tbody>
72                 <% var i=0; retData.forEach( function(rowObj) { %>
73         <tr>
74             <td><%= rowObj.row.id %></td>
75             <td><a href="javascript:getVnfNetworkData('<%= rowObj.network_name %>','<%= rowObj.network_type %>');"><%= rowObj.row.svc_request_id %></a></td>
76                         <td><%= rowObj.network_name %></td>
77                         <td><%= rowObj.network_type %></td>
78             <td><%= rowObj.row.svc_action %></td>
79             <td><%= rowObj.row.status %></td>
80                         <td>
81                 <a data-toggle="collapse"
82                     href="#collapseExample<%= i %>" aria-expanded="false"
83                     aria-controls="collapseExample"><%= rowObj.row.filename %>
84                 </a>
85                 <div class="collapse" id="collapseExample<%= i %>">
86                     <div class="well">
87                         <pre><%= JSON.stringify(rowObj.filecontent,null,4) %></pre>
88                     </div>
89                 </div>
90            </td>
91
92             <td><%= rowObj.row.ts %></td>
93                         <% if(priv == 'A' ) { %>
94             <td>
95                                 <button type="button" class="btn btn-default btn-xs"
96                 onclick="deleteVnfNetworkData('<%= rowObj.row.id %>','<%= rowObj.row.svc_request_id %>','<%= rowObj.row.filename %>','<%= rowObj.row.status %>','<%= rowObj.network_name %>','<%= rowObj.network_type %>');">Delete</button>
97             <% if (typeof rowObj.network_name != 'undefined' || typeof rowObj.network_type != 'undefined'){ %>
98                                 <button type="button" class="btn btn-default btn-xs"
99                 onclick="loadVnfNetworkData('<%= rowObj.row.id %>','<%= rowObj.row.svc_request_id %>','<%= rowObj.row.svc_action %>','<%= rowObj.row.status %>','<%= rowObj.row.filename %>','<%= rowObj.row.ts %>');">Load Data</button>
100             <% } %>
101                         </td>
102             <% } %>
103         </tr>
104                 <% i++; }); %>
105       </tbody>
106     </table>
107
108         <% if(priv == 'A'){ %>
109 <div class="row">
110     <div class="col-md-8  col-md-push-4">
111     <form method="POST" action="/mobility/uploadVnfNetworkData" enctype="multipart/form-data">
112         <div class="form-group">
113             <label for="dest">Upload pre processed JSON file.</label>
114             <input name="filename" type="file" id="dest" />
115             <p class="help-block">Choose a JSON file to upload.</p>
116             <button type="button" class="btn btn-default"
117                 data-toggle="tooltip" data-placement="bottom"
118                 title="Upload a JSON file that has already been pre processed."
119                 onclick="uploadFile(this.form);">Upload JSON File
120                         </button>
121         </div>
122     </form>
123     </div>
124     <div class="col-md-4 col-md-pull-8">
125     <form method="POST" action="/preload/uploadNetworkCsv" enctype="multipart/form-data">
126         <div class="form-group">
127             <label for="dest">Upload Worksheet CSV files from the <%= preloadImportDirectory %> directory.</label>
128             <input name="filename" type="file" id="dest" multiple />
129             <p class="help-block">Choose Worksheet CSV files to upload.</p>
130             <button type="button" class="btn btn-default"
131                 data-toggle="tooltip" data-placement="bottom"
132                 title="Must upload all the VNF CSV files from <%= preloadImportDirectory %>"
133                 onclick="importWorksheet(this.form);">Upload Network Worksheet CSV files
134             </button>
135         </div>
136     </form>
137     </div>
138 </div>
139     <% } %>
140 </div>
141
142 <footer>
143     <% include ../partials/footer %>
144 </footer>
145
146 <script type="text/javascript">
147
148 function importWorksheet(form)
149 {
150     if ( form.filename.value.length == 0)
151     {
152         bootbox.alert('Must select a file.');
153         return false;
154     }
155     else {
156
157         bootbox.confirm({
158             message: "Are you sure you want to import Network WORKSHEET .csv files from <%= preloadImportDirectory %>",
159             callback: function(result) {
160                 if ( result )
161                 {
162                     form.submit();
163                 }
164                 return;
165             },
166             buttons: {
167                 cancel: {
168                     label: "Cancel"
169                 },
170                 confirm: {
171                     label: "Yes"
172                 }
173             }
174         });
175     }
176 }
177
178 function getVnfNetworkData(network_name,network_type)
179 {
180         location.assign("/mobility/viewVnfNetworkData?network_name=" + network_name + "&network_type=" + network_type );
181         return;
182 }
183 function loadVnfNetworkData(id,svc_request_id,svc_action,status,filename,ts)
184 {
185         if ( status != 'pending' )
186         {
187                 bootbox.alert("Upload Status must be in 'pending' state.");
188                 return;
189         }
190         bootbox.confirm({
191         message: "Are you sure you want to load file [" + filename + "]? ",
192         callback: function(result) {
193             if ( result )
194             {
195                                 location.assign("/mobility/loadVnfNetworkData?id=" + id + "&svc_request_id=" + svc_request_id + "&filename=" + filename + "&status=" + status);
196             }
197             return;
198         },
199         buttons: {
200             cancel: {
201                 label: "Cancel"
202             },
203             confirm: {
204                 label: "Yes"
205             }
206         }
207     });
208 }
209
210 function deleteVnfNetworkData(id,svc_request_id,filename,status,network_name,network_type) {
211
212     bootbox.confirm({
213         message: "Are you sure you want to delete uploaded file [" + filename + "]? ",
214         callback: function(result) {
215             if ( result )
216             {
217                                 location.assign("/mobility/deleteVnfNetworkData?id=" 
218                                         + id 
219                                         + "&svc_request_id=" + svc_request_id 
220                                         + "&filename=" + filename 
221                                         + "&status=" + status
222                                         + "&network_name=" + network_name
223                                         + "&network_type=" + network_type);
224             }
225             return;
226         },
227         buttons: {
228             cancel: {
229                 label: "Cancel"
230             },
231             confirm: {
232                 label: "Yes"
233             }
234         }
235     });
236 }
237
238 </script>
239
240 </body>
241 </html>
242