Statistics
| Branch: | Tag: | Revision:

root / templates / user_routes.html @ bd647319

History | View | Annotate | Download (12.6 kB)

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="/fodstatic/js/jquery.dataTables.js"></script>
8
<script type="text/javascript" src="/fodstatic/js/datatables_bootstrap.js"></script>
9

    
10
<script type="text/javascript">
11

12
$(document).ready(function(){
13
        $('[rel=tooltip]').tooltip();
14
    $("#hid_mid").val('');
15
    $('#dialog').dialog({
16
        height: 250,
17
        width: 340,
18
        modal: true,
19
        autoOpen: false,
20
        buttons: {
21
            '{% trans "Suspend" %}': function(){
22
                route = $('#route_to_delete').text();
23
                route_url_id = '#del_route_' + route;
24
                url = $(route_url_id).attr('href');
25
                $.ajax({
26
                    url: url,
27
                    cache: false,
28
                    success: function(data){
29
                        $('#dialog').dialog('close');
30
                        window.setTimeout('location.reload()', 1000);
31
                    }
32
                });
33
            },
34
            '{% trans "Cancel" %}': function(){
35
                $('#dialog').dialog('close');
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
        $(".button_place #routebutton").button({
63
        icons: {
64
            primary: "ui-icon-circle-plus"
65
        },
66
    });
67
    $(".edit_button").button({
68
        icons: {
69
            primary: "ui-icon-wrench"
70
        },
71
    }).css('margin-bottom','2px');
72
    $(" .del_button").button({
73
        icons: {
74
            primary: "ui-icon-circle-close"
75
        },
76
    }).click(function(){
77
        $('#dialog').dialog('open');
78
        return false;
79
    });
80
    $("#consolebutton").button().click(function(){
81
        $("#consolebutton").stop().stop();
82
        $('#console').dialog('open');
83
        return false;
84
    });
85

86

87
    var oTable = $('#routes_table').dataTable({
88
            "sPaginationType": "bootstrap",
89
            "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
90
        "aoColumns": [{
91
            "bVisible": false,
92
            "bSearchable": false,
93
            "bSortable": false
94
        }, {
95
            "bSearchable": true,
96
            "bSortable": true
97
        }, {
98
            "bSearchable": true,
99
            "bSortable": true
100
        }, {
101
            "bSearchable": true,
102
            "bSortable": true
103
        }, {
104
            "bSearchable": true,
105
            "bSortable": true
106
        }, {
107
            "bSearchable": true,
108
            "bSortable": true
109
        }, {
110
            "bSearchable": true,
111
            "bSortable": true
112
        }, {
113
            "bSearchable": true,
114
            "bSortable": true
115
        }, {
116
            "bVisible": true,
117
            "bSearchable": false,
118
            "bSortable": false
119
        }],
120
        "aaSorting": [[0, 'desc']],
121
        "iDisplayLength": 25,
122
        "oSearch": {"bSmart": false, "bRegex":true},
123
        "oLanguage": {
124
                "sLengthMenu": '{% trans "Display" %} <select><option value="25">25</option><option value="50">50</option><option value="-1">{% trans "All" %}</option></select> {% trans "rules" %}',
125
            "sProcessing":   "Processing...",
126
            "sZeroRecords": '{% trans "No records to display" %}',
127
            "sInfo":         "Showing _START_ to _END_ of _TOTAL_ entries",
128
            "sInfoEmpty":    "{% trans "Showing 0 to 0 of 0 entries" %}",
129
            "sInfoFiltered": "(filtered from _MAX_ total entries)",
130
            "sInfoPostFix":  "",
131
            "sSearch":       '{% trans "Search:" %}',
132
            "sUrl":          "",
133
            "oPaginate": {
134
                "sFirst":    '{% trans "First" %}',
135
                "sPrevious": '{% trans "Previous" %}',
136
                "sNext":     '{% trans "Next" %}',
137
                "sLast":     '{% trans "Last" %}'
138
            }
139
        }
140
    });
141

142
    oTable.fnDraw();
143
    
144
    var reg_exp = '';
145
    var checkboxs = document.getElementsByName('status_filter');
146
    for (var i = 0, inp; inp = checkboxs[i]; i++) {
147
        checkCookie = readCookie("cookie_" + inp.value);
148
        if (checkCookie) {
149
            if (checkCookie == 'true') {
150
                $(inp).addClass('active');
151
            }
152
            else {
153
                $(inp).removeClass('active');
154
            }
155
        }
156
        
157
        if (inp.type.toLowerCase() == 'button' && $(inp).hasClass('active')) {
158
            reg_exp = reg_exp + inp.value + '|';
159
        }
160
        
161
    }
162
        if (reg_exp == '') {
163
            reg_exp = '|'
164
        }
165
        console.log(reg_exp.slice(0, -1))
166
    oTable.fnFilter(reg_exp.slice(0, -1), 4, true);
167
    
168
    
169
    $('button[name="status_filter"]').click(function(){
170
            var reg_exp = '';
171
        var checkboxs = document.getElementsByName('status_filter');
172
        $(this).button('toggle');
173
        for (var i = 0, inp; inp = checkboxs[i]; i++) {
174
            if (inp.type.toLowerCase() == 'button' && $(inp).hasClass('active')) {
175
                reg_exp = reg_exp + inp.value + '|';
176
            }
177
            createCookie("cookie_" + inp.value, $(inp).hasClass('active'), 30);
178
        }
179
        //passing an empty string will result in no filter
180
        //thus, it must be set to something that will not exist in the column
181
        if (reg_exp == '') {
182
            reg_exp = '|'
183
        }
184
        oTable.fnFilter(reg_exp.slice(0, -1), 4, regex=true);
185
        console.log(reg_exp.slice(0, -1))
186
        return false;
187
    });
188

189
    
190
});
191
                
192
function delete_route(route){
193
        route_name = route;
194
        $('#route_to_delete').text(route_name);
195
        return false;
196
}                
197
                
198
                
199

    
200
</script>
201
<style type="text/css">
202
        #console {
203
                background: none repeat scroll 0 0 #36102a !important;
204
                color: #edeae8 !important;
205
                font-family: monospace !important;
206
        }
207
        .message {
208
                font-family: monospace !important;
209
        }
210
        
211
        
212
</style>
213
{% endblock %}
214
{% block title %}{% trans "My rules" %}{% endblock %}
215
{% block content %}
216
{% csrf_token %}
217
<div class="row-fluid">
218
<div class="span2">
219
<div style="float:left">
220
        <h4>{% trans "My rules" %}</h4>
221
</div>
222
</div>
223

    
224
<div class="span10">
225
<div class='button_place' style="float:right">
226
        <button id="consolebutton" class="btn btn-small btn-inverse">
227
                <i class="icon-tasks icon-white" style="align:left;"></i>{% trans "Console" %}</button>
228
                <a href="{% url add-route %}" id="routebutton" class="btn btn-small btn-inverse"><i class="icon-plus-sign icon-white"></i>{% trans "Add Rule" %}</a>
229
</div>
230
</div>
231
</div>
232
<hr>
233
<div class="row-fluid" style="padding-top:30px;">
234

    
235
<div id='itoggle' class="span12" style="text-align:center;">
236
   <div class="btn-group" data-toggle="buttons-checkbox">
237
    <button type="button" class="btn btn-small" name="status_filter" value="ACTIVE" id="show_active">Active</button>
238
    <button type="button" class="btn btn-small" name="status_filter" value="SUSPENDED" id="show_inactive">Suspended</button>
239
    <button type="button" class="btn btn-small" name="status_filter" value="ERROR" id="show_error">Error</button>
240
    <button type="button" class="btn btn-small" name="status_filter" value="PENDING" id="show_pending">Pending</button>
241
    </div>
242
                        </div>
243

    
244
</div>
245

    
246
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" width="100%" id="routes_table">
247
<thead>
248
<tr>
249
        <th>Id</th>
250
        <th>{% trans "Name" %}</th>
251
        <th>{% trans "Match" %}</th>
252
        <th style="text-align: center;">{% trans "Then" %}</th>
253
        <th style="text-align: center; ">{% trans "Status" %}</th>
254
        {% comment %}<th style="text-align: center;">{% trans "Details" %}</th>{% endcomment %}
255
        <th style="text-align: center;">{% trans "Applier" %}</th>
256
        <th style="text-align: center;">{% trans "Expires" %}</th>
257
        <th style="text-align: center;">{% trans "Response" %}</th>
258
        <th style="text-align: center; width:180px;">{% trans "Actions" %}</th>
259
</tr>
260
</thead>
261

    
262
<tbody>
263
{% for route in routes %}
264

    
265
<tr class="GradeC" >
266
        <td>{{ route.pk }}</td>
267
        <td><span {% if  %} class="commentclass" style="border-bottom:1px dotted red;" title="{{route.comments}}"        {% endif %}>{{ route.name }}</span></td>
268
        <td>{{ route.get_match|safe|escape }}</td>
269
        <td style="text-align: center;">{{route.get_then|safe|escape}}</td>
270
        <td style="text-align: center; ">{% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}
271
                <a href="#" rel="tooltip" 
272
                        {% if  == 'EXPIRED' or  == 'ADMININACTIVE' or  == 'INACTIVE' or  == 'OUTOFSYNC'%}  
273
                        data-placement="top" 
274
                        title = "{% ifequal route.status 'INACTIVE' %}
275
                                                {% trans 'Suspended by user' %}
276
                                         {% else %}
277
                                                {% ifequal route.status 'ADMININACTIVE' %}
278
                                                        {% trans 'Suspended by administrator' %}
279
                                                {% else %}
280
                                                        {% ifequal route.status 'EXPIRED' %}
281
                                                                {% trans 'Suspended due to expiration' %}
282
                                                        {% else %}
283
                                                                {% ifequal route.status 'OUTOFSYNC' %}
284
                                                                        {% trans 'Syncronization error. Configuration in device deffers from rule' %}
285
                                                                {% endifequal %}
286
                                                        {% endifequal %}
287
                                                {% endifequal %}
288
                                         {% endifequal %}"
289
                        {% 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 %}</a>
290
                {% else %}{{route.status}}{% endif %}</td>
291
        {% comment %}<td style="text-align: center;">{{ route.response }}</td>{% endcomment %}
292
        <td style="text-align: center;">{{ route.applier }}</td>
293
        <td style="text-align: center;">
294
                <span {% if  == 'EXPIRED' or  == 'ADMININACTIVE' or  == 'INACTIVE' or  == 'OUTOFSYNC'%}{% else %}{% if  %}
295
                class="expiresclass" 
296
                style="border-bottom:2px dashed red;" 
297
        title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}"
298
                {% endif %}{% endif %}>{{ route.expires }}</span></td>
299
        <td style="text-align: center;">{% if route.status == 'EXPIRED' %}{% trans "Rule expired" %}{% else %}{% if route.status == 'ADMININACTIVE' %}{% trans "Suspended by administrator" %}{% else %}{% if route.status == 'INACTIVE' %}{% trans "Suspended by user" %}{% else %}{{ route.response }}{% if route.status == 'PENDING' %}<img src="/fodstatic/dots.gif">{% endif %}{% endif %}{% endif %}{% endif %}</td>
300
        <td style="text-align: center; width:180px;">
301
                {% ifequal route.status 'ACTIVE' %}
302
                <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "Edit" %}</a> 
303
                <button class="del_button btn btn-small" id="{{route.name}}" onclick="javascript:delete_route(this.id)">{% trans "Suspend" %}</button>
304
                <a href="{% url delete-route route.name %}" style="display:none" id="del_route_{{route.name}}" class="btn btn btn-danger btn-small"></a>
305
                {% else %}
306
                {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}
307
                <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "Reactivate" %}</a>
308
                {% else %}
309
                {% ifequal route.status 'OUTOFSYNC' %}
310
                <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "ReSync" %}</a>
311
                {% else %}
312
                {% ifequal route.status 'ERROR' %}
313
                <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "Fix it!" %}</a>
314
                {% else %}
315
                -
316
                {% endifequal %}
317
                {% endifequal %}
318
                {% endif %}
319
                {% endifequal %}
320
                </td>
321
</tr>
322

    
323
{% endfor %}
324
</tbody>
325
</table>
326
<div id="dialog" title="{% trans "Suspend " %}">
327
                <p>{% blocktrans %}You are about to suspend rule{% endblocktrans %} <strong><span id="route_to_delete"></span></strong></p>
328
                <p>{% blocktrans %}Suspending the rule will automatically remove the configuration from the network and mark this rule as inactive.{% endblocktrans %}</p>
329
                <p>{% blocktrans %}Are you sure you want to proceed?{% endblocktrans %}</p>
330
</div>
331
<div id="console" title="{% trans "Console" %}">
332
                                        {% include "poll.html" %}
333
</div>
334
{% endblock %}