Initial commit for OpenECOMP SDN-C OA&M
[sdnc/oam.git] / admportal / views / resalloc / threshold_alarms.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     $('#threshold_alarms').DataTable( {
13         "order": [[ 0, "asc" ]]
14     } );
15 } );
16 </script>
17
18 </head>
19 <body>
20
21 <div class="well well-sm">
22 <h3>Threshold Alarms</h3>
23 </div>
24
25 <% if ( typeof result != 'undefined' ) {
26                 if (result.code.length > 0) { 
27                         if ( result.code == 'success' ) { %>
28                                 <div class='alert alert-success' role='alert'>
29                                 <%
30                                 for ( x in result.msg ){ %>
31                                         <div><%= result.msg[x] %></div>
32                                 <% } %>
33                                 </div>
34                         <% } else { %> 
35                                 <div class='alert alert-danger' role='danger'>
36                                 <%
37                                 for ( x in result.msg ){ %>
38                                         <div><%= result.msg[x] %></div>
39                                 <% } %>
40                                 </div>
41                         <% } %>
42                 <% } %>
43 <% } %>
44
45 <% if( typeof privilege != 'undefined'){
46     var priv = privilege.privilege;
47 } else {
48     var priv = 'A';
49 } %>
50
51
52 <div class="container-fluid">
53
54         <% if (priv == 'A'){ %>
55                 <div class="actions" style="padding:15px 0px;">
56         <button class="btn btn-primary" data-toggle="modal" data-target="#add_threshold_alarm">
57         Add Threshold Alarm
58         </button>
59                 </div>
60         <% } %>
61
62         <table id="threshold_alarms" class="table table-hover table-condensed">
63       <thead>
64         <tr>
65                   <th>*Resource Threshold ID</th>
66                   <th>*Resource Rule ID</th>
67           <th>Threshold Expression</th>
68                   <th>Threshold Message</th>
69                    <% if(priv == 'A'){ %>
70           <th>Action</th>
71           <% } %>
72         </tr>
73       </thead>
74       <tbody>
75       <% rows.forEach( function(row) { %> 
76         <tr>
77             <td><%= row.resource_threshold_id %></td>
78             <td><%= row.resource_rule_id %></td>
79             <td><%= row.threshold_expression %></td>
80             <td><%= row.threshold_message %></td>
81                         <% if(priv == 'A') { %>
82             <td>
83                                 <button type="button" class="btn btn-default btn-xs"
84                     onclick="updateThresholdAlarm('<%= row.resource_threshold_id %>','<%=row.resource_rule_id %>','<%= row.threshold_expression %>','<%= row.threshold_message %>');">Update</button>
85                                 <button type="button" class="btn btn-default btn-xs"
86                    onclick="deleteThresholdAlarm('<%= row.resource_threshold_id %>');">Delete</button>
87             </td>
88             <% } %>
89
90         </tr>
91     <% }); %>
92       </tbody>
93     </table>
94
95 </div>
96
97 <% include ../partials/threshold_alarm %>
98 <footer>
99     <% include ../partials/footer %>
100 </footer>
101
102 <script type="text/javascript">
103 function submitThresholdAlarm(form)
104 {
105     var resource_rule_id = '';
106         var threshold_expression = '';
107         var threshold_message = '';
108     var errorMsg = '';
109
110     if ( form.name == 'addForm' )
111     {
112                 resource_rule_id = form.nf_resource_rule_id;
113                 threshold_expression = form.nf_threshold_expression;
114                 threshold_message = form.nf_threshold_message;
115     }
116     else
117     {
118                 resource_rule_id = form.uf_resource_rule_id;
119                 threshold_expression = form.uf_threshold_expression;
120                 threshold_message = form.uf_threshold_message;
121     }
122     if ( (resource_rule_id.value == null) || (resource_rule_id.value == "") || isblank(resource_rule_id.value) )
123     {
124         errorMsg += 'Resource Rule ID is required.\n';
125     }
126     if ( (threshold_expression.value == null) || (threshold_expression.value == "") || isblank(threshold_expression.value) )
127     {
128         errorMsg += 'Threshold Expression is required.\n';
129     }
130     if ( (threshold_message.value == null) || (threshold_message.value == "") || isblank(threshold_message.value) )
131     {
132         errorMsg += 'Threshold Message is required.\n';
133     }
134     if( errorMsg.length > 0 ) {
135         alert(errorMsg);
136         return;
137     }
138
139     if ( !isDigit(resource_rule_id.value) )
140     {
141         alert('Resource Rule ID must be a number.');
142         return;
143     }
144
145     form.submit();
146 }
147
148 function updateThresholdAlarm(resource_threshold_id,resource_rule_id,threshold_expression,threshold_message) {
149
150     document.getElementById('uf_resource_threshold_id').value=resource_threshold_id;
151     document.getElementById('uf_resource_rule_id').value=resource_rule_id;
152     document.getElementById('uf_threshold_expression').value=threshold_expression;
153     document.getElementById('uf_threshold_message').value=threshold_message;
154
155     document.getElementById('uf_key_resource_threshold_id').value=resource_threshold_id;
156
157     $('#update_threshold_alarm').modal('show');
158 }
159
160 function deleteThresholdAlarm(resource_threshold_id) {
161
162     bootbox.confirm({
163         message: "Are you sure you want to delete Threshold Alarm [" + resource_threshold_id + "]",
164         callback: function(result) {
165             if ( result )
166             {
167                                 location.assign("/resalloc/deleteThresholdAlarm?resource_threshold_id=" + resource_threshold_id);
168             }
169             return;
170         },
171         buttons: {
172             cancel: {
173                 label: "Cancel"
174             },
175             confirm: {
176                 label: "Yes"
177             }
178         }
179     });
180 }
181
182 </script>
183
184 </body>
185 </html>
186