Add badges to rule status
[flowspy] / templates / user_routes.html
index b520f4e..984e513 100644 (file)
 {% if user.is_authenticated %}
 <script type="text/javascript" src="{% url load-js 'poller' %}"></script>
 {% endif %}
-<script type="text/javascript" src="/static/js/jquery.dataTables.js"></script>
+<script type="text/javascript" src="/fodstatic/js/jquery.dataTables.js"></script>
+<script type="text/javascript" src="/fodstatic/js/datatables_bootstrap.js"></script>
+
 <script type="text/javascript">
-       $(document).ready( function(){
-               var noaction = readCookie('noaction');
-               $( "#hide_noaction" ).button();
-               if (noaction == 'true'){
-                       $('#hide_noaction').attr('checked','checked');
-                       $("#hide_noaction").button( "option", "label", "Show Expired, AdminInactive, Error" );
-               }
-               $("#hid_mid").val('');
-               $('#dialog').dialog({
-                       height: 220,
-            width: 300,
-                       modal: true,
-                       autoOpen: false,
-                       buttons: {
-               'Delete': function() {
-               route = $('#route_to_delete').text();
-               route_url_id = '#del_route_'+route;
-               url = $(route_url_id).attr('href');
-                       $.ajax({
-                       url: url ,
-                       cache: false,
-                       success: function(data) {
-                               $('#dialog').dialog('close');
-                               window.setTimeout('location.reload()', 1000);
-                         }
-               });
-               },
-               Cancel: function() {
-                       $('#dialog').dialog('close');
-               },
-               
 
-       },
-       close: function() {
-        update_val = $("#hid_mid").val();
-               if (update_val == 'UPDATED'){
-                       $("#hid_mid").val('');
-                       window.setTimeout('location.reload()', 500);
-               }
-    }
-               });
-               $('#console').dialog({
-                       height: 250,
-            width: 800,
-                       modal: true,
-                       autoOpen: false,
-                       close: function() {
-                       update_val = $("#hid_mid").val();
-                               if (update_val == 'UPDATED'){
-                                       $("#hid_mid").val('');
-                                       window.setTimeout('location.reload()', 500);
-                               }
-                   }
-               });
-                       
-               $('#routes_table').dataTable({
-                       "bJQueryUI": true,
-                       "aoColumns": [ 
-                               {"bVisible": false, "bSearchable": false,"bSortable": false },
-                               {"bSearchable": true,"bSortable": true},
-                               {"bSearchable": true,"bSortable": true},
-                               {"bSearchable": true,"bSortable": true},
-                               {"bSearchable": true,"bSortable": true},
-                               {"bSearchable": true,"bSortable": true},
-                               {"bSearchable": true,"bSortable": true},
-                               {"bSearchable": true,"bSortable": true},
-                               {"bVisible": true, "bSearchable": false,"bSortable": false}
-                       ],
-                        "aaSorting": [[0,'desc']],
-                       "oLanguage": {
-                               "sLengthMenu": '{% trans "Display" %} <select><option value="25">25</option><option value="50">50</option><option value="-1">{% trans "All" %}</option></select> rules'
-                       },
-                       "iDisplayLength": 25,
-       });
-       $.fn.dataTableExt.afnFiltering = new Array();
-       $.fn.dataTableExt.afnFiltering.push(
-       function( oSettings, aData, iDataIndex ) {
-               // 4 here is the column where my statuses are.
-               var status_middle = $(aData[4]);
-               var status = $(status_middle[0]).text();
-               if (( status == "EXPIRED" || status == "ADMININACTIVE" || status == "ERROR") && ($('#hide_noaction').attr('checked'))) {
-                       return false;
-               }
-               else {
-                       return true;
-               }
-               
-       });
-       var oTable = $('#routes_table').dataTable();
-       oTable.fnDraw();
-       $('#hide_noaction').change( function(){
-                       var noaction = $('#hide_noaction').attr('checked');
-                       if (noaction == true){
-                               $("#hide_noaction").button( "option", "label", "Show Expired, AdminInactive, Error" );
-                               }
-                       else{
-                               $("#hide_noaction").button( "option", "label", "Hide Expired, AdminInactive, Error" );
-                       }
-                       createCookie("noaction", noaction, 30);
-                       oTable.fnDraw(); 
-               });
-       
-       $( ".button_place #routebutton" ).button({
-            icons: {
-                primary: "ui-icon-circle-plus"
+$(document).ready(function(){
+       $('[rel=tooltip]').tooltip();
+    $("#hid_mid").val('');
+    $('#dialog').dialog({
+        height: 250,
+        width: 340,
+        modal: true,
+        autoOpen: false,
+        buttons: {
+            '{% trans "Deactivate" %}': function(){
+                route = $('#route_to_delete').text();
+                route_url_id = '#del_route_' + route;
+                url = $(route_url_id).attr('href');
+                $.ajax({
+                    url: url,
+                    cache: false,
+                    success: function(data){
+                        $('#dialog').dialog('close');
+                        window.setTimeout('location.reload()', 1000);
+                    }
+                });
             },
-                       });
-               $( " .edit_button" ).button({
-            icons: {
-                primary: "ui-icon-wrench"
+            '{% trans "Cancel" %}': function(){
+                $('#dialog').dialog('close');
             },
-                       });
-               $( " .del_button" ).button({
-            icons: {
-                primary: "ui-icon-circle-close"
-            },
-                       })
-                       .click(function(){
-                               $('#dialog').dialog('open');
-                               return false;
-                       });
-               $("#consolebutton").button({
-            icons: {
-                primary: "ui-icon-image"
-            },
-                       })
-                       .click(function(){
-                               $("#consolebutton").stop().stop();
-                               $("#consolebutton").css('color', '#555555');
-                               $('#console').dialog('open');
-                               return false;
-                       });
-                       
-               $(".expiresclass").tooltip();
+        },
+        close: function(){
+            update_val = $("#hid_mid").val();
+            if (update_val == 'UPDATED') {
+                $("#hid_mid").val('');
+                window.setTimeout('location.reload()', 500);
+            }
+        }
+    });
+    $('#console').dialog({
+        height: 250,
+        width: 800,
+        modal: true,
+        autoOpen: false,
+               overlay: { opacity: 0.5, background: 'black'},
+        close: function(){
+            update_val = $("#hid_mid").val();
+            if (update_val == 'UPDATED') {
+                $("#hid_mid").val('');
+                window.setTimeout('location.reload()', 500);
+            }
+        }
+    });
+    $('#console').parent().css('opacity', 0.9);
+       $('#console').parent().css('filter', 'alpha(opacity=90)');
+       $(".button_place #routebutton").button({
+        icons: {
+            primary: "ui-icon-circle-plus"
+        },
+    });
+    $(".edit_button").button({
+        icons: {
+            primary: "ui-icon-wrench"
+        },
+    }).css('margin-bottom','2px');
+    $(" .del_button").button({
+        icons: {
+            primary: "ui-icon-circle-close"
+        },
+    }).click(function(){
+        $('#dialog').dialog('open');
+        return false;
+    });
+    $("#consolebutton").button().click(function(){
+        $("#consolebutton").stop().stop();
+        $('#console').dialog('open');
+        return false;
+    });
+
+
+    var oTable = $('#routes_table').dataTable({
+       "sPaginationType": "bootstrap",
+       "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
+        "aoColumns": [{
+            "bVisible": false,
+            "bSearchable": false,
+            "bSortable": false
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bSearchable": true,
+            "bSortable": true
+        }, {
+            "bVisible": true,
+            "bSearchable": false,
+            "bSortable": false
+        }],
+        "aaSorting": [[0, 'desc']],
+        "iDisplayLength": 25,
+        "oSearch": {"bSmart": false, "bRegex":true},
+        "oLanguage": {
+               "sLengthMenu": '{% trans "Display" %} <select><option value="25">25</option><option value="50">50</option><option value="-1">{% trans "All" %}</option></select> {% trans "rules" %}',
+            "sProcessing":   "Processing...",
+            "sZeroRecords": '{% trans "No records to display" %}',
+            "sInfo":         "Showing _START_ to _END_ of _TOTAL_ entries",
+            "sInfoEmpty":    "{% trans "Showing 0 to 0 of 0 entries" %}",
+            "sInfoFiltered": "(filtered from _MAX_ total entries)",
+            "sInfoPostFix":  "",
+            "sSearch":       '{% trans "Search:" %}',
+            "sUrl":          "",
+            "oPaginate": {
+                "sFirst":    '{% trans "First" %}',
+                "sPrevious": '{% trans "Previous" %}',
+                "sNext":     '{% trans "Next" %}',
+                "sLast":     '{% trans "Last" %}'
+            }
+        }
+    });
 
-               });
+    oTable.fnDraw();
+    
+    var reg_exp = '';
+    var checkboxs = document.getElementsByName('status_filter');
+    for (var i = 0, inp; inp = checkboxs[i]; i++) {
+        checkCookie = readCookie("cookie_" + inp.value);
+        if (checkCookie) {
+            if (checkCookie == 'true') {
+                $(inp).addClass('active');
+            }
+            else {
+                $(inp).removeClass('active');
+            }
+        }
+        
+        if (inp.type.toLowerCase() == 'button' && $(inp).hasClass('active')) {
+            reg_exp = reg_exp + inp.value + '|';
+        }
+        
+    }
+       if (reg_exp == '') {
+            reg_exp = '|'
+        }
+       
+       
+    oTable.fnFilter(reg_exp.slice(0, -1), 4, true);
+    
+    
+    $('button[name="status_filter"]').click(function(){
+       var reg_exp = '';
+        var checkboxs = document.getElementsByName('status_filter');
+        $(this).button('toggle');
+        for (var i = 0, inp; inp = checkboxs[i]; i++) {
+            if (inp.type.toLowerCase() == 'button' && $(inp).hasClass('active')) {
+                reg_exp = reg_exp + inp.value + '|';
+            }
+            createCookie("cookie_" + inp.value, $(inp).hasClass('active'), 30);
+        }
+        //passing an empty string will result in no filter
+        //thus, it must be set to something that will not exist in the column
+        if (reg_exp == '') {
+            reg_exp = '|'
+        }
+        oTable.fnFilter(reg_exp.slice(0, -1), 4, regex=true);
+        return false;
+    });
+
+    
+});
                
 function delete_route(route){
        route_name = route;
@@ -161,36 +207,43 @@ function delete_route(route){
        .message {
                font-family: monospace !important;
        }
-       .tooltip {
-       display:none;
-       background:transparent url(/static/black_arrow.png);
-       font-size:12px;
-       height:70px;
-       width:160px;
-       padding:25px;
-       color:#fff;     
-}
+       
        
 </style>
 {% endblock %}
 {% block title %}{% trans "My rules" %}{% endblock %}
 {% block content %}
+{% csrf_token %}
+<div class="row-fluid">
+<div class="span2">
 <div style="float:left">
-       <h3 style="margin-top: 0px;">{% trans "My rules" %}</h3>
+       <h4>{% trans "My rules" %}</h4>
 </div>
+</div>
+
+<div class="span10">
 <div class='button_place' style="float:right">
-       <button id="consolebutton">Console</button> <a href="{% url add-route %}" id="routebutton">Add Rule</a>
+       <button id="consolebutton" class="btn btn-inverse">
+               <i class="icon-tasks icon-white" style="align:left;"></i>{% trans "Console" %}</button>
+               <a href="{% url add-route %}" id="routebutton" class="btn btn-primary"><i class="icon-plus-sign icon-white"></i>{% trans "Add Rule" %}</a>
 </div>
-<br><br>
-<table cellpadding="0" cellspacing="0" border="0" style="width:220px; clear:both;">
-       <tbody>
-               <tr>
-                       <td align="left"><input type="checkbox" id="hide_noaction" name="hide_noaction" value="Hide" /><label for="hide_noaction">Hide Expired, AdminInactive, Error</label></td>
-               </tr>
-       </tbody>
-</table>
-<br>
-<table class="display" width="100%" id="routes_table">
+</div>
+</div>
+<hr>
+<div class="row-fluid" style="padding-top:30px;">
+
+<div id='itoggle' class="span12" style="text-align:center;">
+   <div class="btn-group" data-toggle="buttons-checkbox">
+    <button type="button" class="btn btn-small" name="status_filter" value="ACTIVE" id="show_active">Active</button>
+    <button type="button" class="btn btn-small" name="status_filter" value="DEACTIVATED" id="show_inactive">Deactivated</button>
+    <button type="button" class="btn btn-small" name="status_filter" value="ERROR" id="show_error">Error</button>
+    <button type="button" class="btn btn-small" name="status_filter" value="PENDING" id="show_pending">Pending</button>
+    </div>
+                       </div>
+
+</div>
+
+<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" width="100%" id="routes_table">
 <thead>
 <tr>
        <th>Id</th>
@@ -209,38 +262,71 @@ function delete_route(route){
 <tbody>
 {% for route in routes %}
 
-<tr {% ifequal route.status 'ACTIVE' %} class="GradeA" {% else %} class="GradeX" {% endifequal %}>
+<tr class="GradeC" >
        <td>{{ route.pk }}</td>
-       <td>{{ route.name }}</td>
+       
+       <td {% if route.comments %}style="color: #0088CC;"{% endif %}>{% if route.comments %}<span rel="tooltip" data-placement="top" title="{{route.comments}}">{{ route.name }}</span>{% else %}{{ route.name }}{% endif %}</td>
+       
        <td>{{ route.get_match|safe|escape }}</td>
+       
        <td style="text-align: center;">{{route.get_then|safe|escape}}</td>
-       <td style="text-align: center; ">
-               <span 
-               {% if route.days_to_expire %}
-               class="expiresclass" 
-               style="border-bottom:2px dashed red;" 
-        title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}"
-               {% endif %}>{{route.status}}</span>
-       </td>
+       
+       <td style="text-align: center; ">{% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}
+               {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}<span class="label">DEACTIVATED</span>{% else %}{% if route.status == 'OUTOFSYNC' %}<span class="label label-important">ERROR</span>{% else %}{{route.status}}{% endif %}{% endif %}{% else %}{% if route.status == 'ACTIVE' %}<span class="label label-success">{{route.status}}</span>{% else %}{% if route.status == 'PENDING' %}<span class="label label-info">{{route.status}}</span>{% else %}<span class="label label-important">{{route.status}}</span>{% endif %}{% endif %}{% endif %}</td>
+               
        {% comment %}<td style="text-align: center;">{{ route.response }}</td>{% endcomment %}
+       
        <td style="text-align: center;">{{ route.applier }}</td>
-       <td style="text-align: center;">{{ route.expires }}</td>
-       <td style="text-align: center;">{{ route.response }}</td>
+       
+       <td style="text-align: center;" nowrap>
+               <span {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}{% else %}{% if route.days_to_expire %}
+               data-placement="top"
+               rel = 'tooltip'
+               style="border-bottom:1px dashed red;" 
+        title="Expires {% ifequal route.days_to_expire '0' %}today{% else%}in {{route.days_to_expire}} day{{ route.days_to_expire|pluralize }}{% endifequal %}"
+               {% endif %}{% endif %}>{{ route.expires|date:"d M y" }}</span></td>
+               
+       <td style="text-align: center; {% if route.status == 'EXPIRED' %} color: #0088CC; {% endif %}">
+               {% if route.status == 'EXPIRED' %}
+               <span rel="tooltip"
+                       {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' or route.status == 'OUTOFSYNC'%}  
+                       data-placement="top" 
+                       title = "{% ifequal route.status 'INACTIVE' %}
+                                               {% trans 'Deactivated by user' %}
+                                        {% else %}
+                                               {% ifequal route.status 'ADMININACTIVE' %}
+                                                       {% trans 'Deactivated by administrator' %}
+                                               {% else %}
+                                                       {% ifequal route.status 'EXPIRED' %}
+                                                               {% trans 'Deactivated due to expiration' %}
+                                                       {% else %}
+                                                               {% ifequal route.status 'OUTOFSYNC' %}
+                                                                       {% trans 'Syncronization error. Configuration in device differs from rule' %}
+                                                               {% endifequal %}
+                                                       {% endifequal %}
+                                               {% endifequal %}
+                                        {% endifequal %}"
+                       {% endif %}>{% trans "Rule expired" %}</span>{% else %}{% if route.status == 'OUTOFSYNC' %}{% trans 'Syncronization error. Configuration in device differs from rule' %}{% else %}{% if route.status == 'ADMININACTIVE' %}{% trans "Deactivated by administrator" %}{% else %}{% if route.status == 'INACTIVE' %}{% trans "Deactivated by user" %}{% else %}{{ route.response }}{% if route.status == 'PENDING' %}<img src="/fodstatic/dots.gif">{% endif %}{% endif %}{% endif %}{% endif %}{% endif %}</td>
+                       
        <td style="text-align: center; width:180px;">
                {% ifequal route.status 'ACTIVE' %}
-               <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Edit</a> 
-               <button class="del_button" id="{{route.name}}" onclick="javascript:delete_route(this.id)">Del</button>
-               <a href="{% url delete-route route.name %}" style="display:none" id="del_route_{{route.name}}"></a>
+               <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "Edit" %}</a> 
+               <button class="del_button btn btn-small" id="{{route.name}}" onclick="javascript:delete_route(this.id)">{% trans "Deactivate" %}</button>
+               <a href="{% url delete-route route.name %}" style="display:none" id="del_route_{{route.name}}" class="btn btn btn-danger btn-small"></a>
                {% else %}
-               {% ifequal route.status 'INACTIVE' %}
-               <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">Reactivate</a>
+               {% if route.status == 'EXPIRED' or route.status == 'ADMININACTIVE' or route.status == 'INACTIVE' %}
+               <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "Reactivate" %}</a>
                {% else %}
                {% ifequal route.status 'OUTOFSYNC' %}
-               <a href="{% url edit-route route.name %}" class="edit_button" id="edit_button_{{route.pk}}">ReSync</a>
+               <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "ReSync" %}</a>
+               {% else %}
+               {% ifequal route.status 'ERROR' %}
+               <a href="{% url edit-route route.name %}" class="edit_button btn btn-small" id="edit_button_{{route.pk}}">{% trans "Fix it!" %}</a>
                {% else %}
                -
                {% endifequal %}
                {% endifequal %}
+               {% endif %}
                {% endifequal %}
                </td>
 </tr>
@@ -248,13 +334,12 @@ function delete_route(route){
 {% endfor %}
 </tbody>
 </table>
-
-<div id="dialog" title="Delete Route">
-               <p>You are about to delete rule <strong><span id="route_to_delete"></span></strong></p>
-               <p>Deleting the rule will automatically remove the configuration from the network and mark this route as inactive.</p>
-               <p>Are you sure you want to proceed?</p>
+<div id="dialog" title="{% trans "Deactivate Rule" %}">
+               <p>{% blocktrans %}You are about to deactivate rule{% endblocktrans %} <strong><span id="route_to_delete"></span></strong></p>
+               <p>{% blocktrans %}Deactivating the rule will automatically remove the configuration from the network and mark this rule as inactive.{% endblocktrans %}</p>
+               <p>{% blocktrans %}Are you sure you want to proceed?{% endblocktrans %}</p>
 </div>
-<div id="console" title="Console">
+<div id="console" title="{% trans "Console" %}">
                                        {% include "poll.html" %}
 </div>
 {% endblock %}