a78e346f0337a8dd9c3ae63ee02a45f0970c0d3b
[flowspy] / templates / user_routes.html
1 {% extends "base.html" %}
2 {% load i18n %}
3 {% block extrahead %}
4 {% if user.is_authenticated %}
5 <script type="text/javascript" src="{% url load-js 'poller' %}"></script>
6 {% endif %}
7 <script type="text/javascript" src="/static/js/jquery.dataTables.js"></script>
8 <link rel="stylesheet" type="text/css" href="/static/css/engage.itoggle.css"/>
9 <script type="text/javascript" src="/static/js/engage.itoggle-min.js"></script>
10 <script type="text/javascript">
11 $(document).ready(function(){
12     $("#hid_mid").val('');
13     $('#dialog').dialog({
14         height: 250,
15         width: 340,
16         modal: true,
17         autoOpen: false,
18         buttons: {
19             'Suspend': function(){
20                 route = $('#route_to_delete').text();
21                 route_url_id = '#del_route_' + route;
22                 url = $(route_url_id).attr('href');
23                 $.ajax({
24                     url: url,
25                     cache: false,
26                     success: function(data){
27                         $('#dialog').dialog('close');
28                         window.setTimeout('location.reload()', 1000);
29                     }
30                 });
31             },
32             Cancel: function(){
33                 $('#dialog').dialog('close');
34             },
35         
36         
37         },
38         close: function(){
39             update_val = $("#hid_mid").val();
40             if (update_val == 'UPDATED') {
41                 $("#hid_mid").val('');
42                 window.setTimeout('location.reload()', 500);
43             }
44         }
45     });
46     $('#console').dialog({
47         height: 250,
48         width: 800,
49         modal: true,
50         autoOpen: false,
51                 overlay: { opacity: 0.5, background: 'black'},
52         close: function(){
53             update_val = $("#hid_mid").val();
54             if (update_val == 'UPDATED') {
55                 $("#hid_mid").val('');
56                 window.setTimeout('location.reload()', 500);
57             }
58         }
59     });
60     $('#console').parent().css('opacity', 0.9);
61         $('#console').parent().css('filter', 'alpha(opacity=90)');
62     var oTable = $('#routes_table').dataTable({
63         "bJQueryUI": true,
64         "aoColumns": [{
65             "bVisible": false,
66             "bSearchable": false,
67             "bSortable": false
68         }, {
69             "bSearchable": true,
70             "bSortable": true
71         }, {
72             "bSearchable": true,
73             "bSortable": true
74         }, {
75             "bSearchable": true,
76             "bSortable": true
77         }, {
78             "bSearchable": true,
79             "bSortable": true
80         }, {
81             "bSearchable": true,
82             "bSortable": true
83         }, {
84             "bSearchable": true,
85             "bSortable": true
86         }, {
87             "bSearchable": true,
88             "bSortable": true
89         }, {
90             "bVisible": true,
91             "bSearchable": false,
92             "bSortable": false
93         }],
94         "aaSorting": [[0, 'desc']],
95         "oLanguage": {
96             "sLengthMenu": '{% trans "Display" %} <select><option value="25">25</option><option value="50">50</option><option value="-1">{% trans "All" %}</option></select> rules'
97         },
98         "iDisplayLength": 25,
99     });
100     
101     oTable.fnDraw();
102     
103     $('input[name="status_filter"]').click(function(){
104     
105         //slice off the last '|' or it doesn't work
106         //also be sure to use the third parameter
107     });
108     
109     $(".button_place #routebutton").button({
110         icons: {
111             primary: "ui-icon-circle-plus"
112         },
113     });
114     $(".edit_button").button({
115         icons: {
116             primary: "ui-icon-wrench"
117         },
118     }).css('width','100px');;
119     $(" .del_button").button({
120         icons: {
121             primary: "ui-icon-circle-close"
122         },
123     }).click(function(){
124         $('#dialog').dialog('open');
125         return false;
126     }).css('width','100px');
127     $("#consolebutton").button({
128         icons: {
129             primary: "ui-icon-image"
130         },
131     }).click(function(){
132         $("#consolebutton").stop().stop();
133         $("#consolebutton").css('color', '#555555');
134         $('#console').dialog('open');
135         return false;
136     });
137     
138         $(".statustootipclass").tooltip();
139     $(".expiresclass").tooltip();
140         $(".commentclass").tooltip();
141     var reg_exp = '';
142     var checkboxs = document.getElementsByName('status_filter');
143     for (var i = 0, inp; inp = checkboxs[i]; i++) {
144         checkCookie = readCookie("cookie_" + inp.value);
145         if (checkCookie) {
146             if (checkCookie == 'true') {
147                 $(inp).attr('checked', true);
148             }
149             else {
150                 $(inp).attr('checked', false);
151             }
152         }
153         
154         if (inp.type.toLowerCase() == 'checkbox' && inp.checked == true) {
155             reg_exp = reg_exp + inp.value + '|';
156         }
157         
158     }
159         if (reg_exp == '') {
160             reg_exp = 'XXX|'
161         }
162     oTable.fnFilter(reg_exp.slice(0, -1), 4, true);
163     
164     $('input[name="status_filter"]').iToggle({
165         type: 'checkbox',
166         onSlide: function(){
167             var reg_exp = '';
168             var checkboxs = document.getElementsByName('status_filter');
169             
170             for (var i = 0, inp; inp = checkboxs[i]; i++) {
171                 if (inp.type.toLowerCase() == 'checkbox' && inp.checked) {
172                     reg_exp = reg_exp + inp.value + '|';
173                 }
174                 createCookie("cookie_" + inp.value, inp.checked, 30);
175             }
176             //passing an empty string will result in no filter
177             //thus, it must be set to something that will not exist in the column
178             if (reg_exp == '') {
179                 reg_exp = 'X|'
180             }
181             oTable.fnFilter(reg_exp.slice(0, -1), 4, true);
182         },
183     });
184 });
185                 
186 function delete_route(route){
187         route_name = route;
188         $('#route_to_delete').text(route_name);
189         return false;
190 }               
191                 
192                 
193
194 </script>
195 <style type="text/css">
196         #console {
197                 background: none repeat scroll 0 0 #36102a !important;
198                 color: #edeae8 !important;
199                 font-family: monospace !important;
200         }
201         .message {
202                 font-family: monospace !important;
203         }
204         .tooltip {
205         display:none;
206         background:transparent url(/static/black_arrow.png);
207         font-size:12px;
208         height:70px;
209         width:160px;
210         padding:25px;
211         color:#fff;     
212 }
213         
214 </style>
215 {% endblock %}
216 {% block title %}{% trans "My rules" %}{% endblock %}
217 {% block content %}
218 <div style="float:left">
219         <h3 style="margin-top: 0px;">{% trans "My rules" %}</h3>
220 </div>
221 <div class='button_place' style="float:right">
222         <button id="consolebutton">Console</button> <a href="{% url add-route %}" id="routebutton">Add Rule</a>
223 </div>
224 <br><br>
225
226 <div id='itoggle'>
227 <table cellpadding="0" cellspacing="0" border="0" class="display" style='width:200px;'>
228                                 <tbody>
229                                         <tr>
230                                         <th>ACTIVE</th><th>SUSPENDED</th><th>ERROR</th><th>PENDING</th>
231                                         </tr>
232                                         <tr class="on_off">
233                                         <td>
234                                             <input type="checkbox" class="onoff" name="status_filter" value="ACTIVE" checked id="show_active"/>
235                                         </td>
236                                     
237                                         <td>
238                                             <input type="checkbox" class="onoff" name="status_filter" value="SUSPENDED" id="show_inactive"/>
239                                         </td>                               
240                                         <td>
241                                             <input type="checkbox" class="onoff" name="status_filter" value="ERROR" id="show_error"/>
242                                         </td>
243                                    
244                                         <td>
245                                             <input type="checkbox" class="onoff" name="status_filter" value="PENDING" id="show_pending"/>
246                                         </td>
247                                     </tr>
248                                 </tbody>
249                         </table>
250                         </div>
251         <table class="display" width="100%" id="nodes_table">
252 <table class="display" width="100%" id="routes_table">
253 <thead>
254 <tr>
255         <th>Id</th>
256         <th>{% trans "Name" %}</th>
257         <th>{% trans "Match" %}</th>
258         <th style="text-align: center;">{% trans "Then" %}</th>
259         <th style="text-align: center; ">{% trans "Status" %}</th>
260         {% comment %}<th style="text-align: center;">{% trans "Details" %}</th>{% endcomment %}
261         <th style="text-align: center;">{% trans "Applier" %}</th>
262         <th style="text-align: center;">{% trans "Expires" %}</th>
263         <th style="text-align: center;">{% trans "Response" %}</th>
264         <th style="text-align: center; width:180px;">{% trans "Actions" %}</th>
265 </tr>
266 </thead>
267
268 <tbody>
269 {% for route in routes %}
270
271 <tr class="GradeC" >
272         <td>{{ route.pk }}</td>
273         <td><span {% if route.comments %}
274         class="commentclass" 
275                 style="border-bottom:1px dotted red;" 
276         title="{{route.comments}}"
277                 {% endif %}>{{ route.name }}</span></td>
278         <td>{{ route.get_match|safe|escape }}</td>
279         <td style="text-align: center;">{{route.get_then|safe|escape}}</td>
280         <td style="text-align: center; "><span 
281                 {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}
282             class="statustootipclass" 
283                 style="border-bottom:1px dotted red;" 
284                 title = "{% ifequal route.status 'INACTIVE' %}Suspended by user{% else %}{% ifequal route.status 'ADMININACTIVE' %}Suspended by administrator{% else %}{% ifequal route.status 'EXPIRED' %}Suspended due to expiration{% else %}{% ifequal route.status 'OUTOFSYNC' %}Syncronization error. Configuration in device deffers from rule{% endifequal %}{% endifequal %}{% endifequal %}{% endifequal %}"{% endif %}>{% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}SUSPENDED{% else %}{% if route.status == 'OUTOFSYNC' %}ERROR{% else %}{{route.status}}{% endif %}{% endif %}</span></td>
285         {% comment %}<td style="text-align: center;">{{ route.response }}</td>{% endcomment %}
286         <td style="text-align: center;">{{ route.applier }}</td>
287         <td style="text-align: center;"><span {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}{% else %}{% if route.days_to_expire %}
288                 class="expiresclass" 
289                 style="border-bottom:2px dashed red;" 
290         title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}"
291                 {% endif %}{% endif %}>{{ route.expires }}</span></td>
292         <td style="text-align: center;">{% if route.status == 'EXPIRED' %}Rule expired{% else %}{% if route.status == 'ADMININACTIVE' %}Suspended by administrator{% else %}{% if route.status == 'INACTIVE' %}Suspended by user{% else %}{{ route.response }}{% endif %}{% endif %}{% endif %}</td>
293         <td style="text-align: center; width:180px;">
294                 {% ifequal route.status 'ACTIVE' %}
295                 <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Edit</a> 
296                 <button class="del_button" id="{{route.name}}" onclick="javascript:delete_route(this.id)">Suspend</button>
297                 <a href="{% url delete-route route.name %}" style="display:none" id="del_route_{{route.name}}"></a>
298                 {% else %}
299                 {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}
300                 <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Reactivate</a>
301                 {% else %}
302                 {% ifequal route.status 'OUTOFSYNC' %}
303                 <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">ReSync</a>
304                 {% else %}
305                 -
306                 {% endifequal %}
307                 {% endif %}
308                 {% endifequal %}
309                 </td>
310 </tr>
311
312 {% endfor %}
313 </tbody>
314 </table>
315
316 <div id="dialog" title="Suspend Rule">
317                 <p>You are about to suspend rule <strong><span id="route_to_delete"></span></strong></p>
318                 <p>Suspending the rule will automatically remove the configuration from the network and mark this rule as inactive.</p>
319                 <p>Are you sure you want to proceed?</p>
320 </div>
321 <div id="console" title="Console">
322                                         {% include "poll.html" %}
323 </div>
324 {% endblock %}