aboutsummaryrefslogtreecommitdiffstats
path: root/lib/srtgui/templates/package-filters-toastertable.html
blob: 3ec05c8114d3ed5775e05a96f24a44257f19e01a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{% extends 'base.html' %}
{% load static %}

{% block extraheadcontent %}
  <link rel="stylesheet" href="{% static 'css/jquery-ui.min.css' %}" type='text/css'>
  <link rel="stylesheet" href="{% static 'css/jquery-ui.structure.min.css' %}" type='text/css'>
  <link rel="stylesheet" href="{% static 'css/jquery-ui.theme.min.css' %}" type='text/css'>
  <script src="{% static 'js/jquery-ui.min.js' %}">
  </script>
{% endblock %}

{% block title %} Package Filters {% endblock %}

{% block pagecontent %}

<div class="row">
  <!-- Breadcrumbs -->
    <div class="col-md-12">
        <ul class="breadcrumb" id="breadcrumb">
            <li><a href="{% url 'landing' %}">Home</a></li><span class="divider">&rarr;</span>
            <li><a href="{% url 'manage' %}">Management</a></li><span class="divider">&rarr;</span>
            <li>Package Filters</li>
        </ul>
    </div>
</div>

<div > <!--class="form-inline" -->
  <b><big>Actions: </big></b>
  <button id="submit-notification" class="btn btn-default" type="button">Delete Selected</button>
  <button id="submit-update-counts" class="btn btn-default" type="button">Update Counts</button>
</div>

<div class="row">
  <div class="col-md-12">
    <div class="page-header">
      <h1 class="top-air" data-role="page-title"></h1>
    </div>

    {# xhr_table_url is just the current url so leave it blank #}
    {% url '' as xhr_table_url %}
    {% include 'toastertable.html' %}
  </div>
</div>

  <!-- Javascript support -->
  <script>
    $(document).ready(function () {
      var tableElt = $("#{{table_name}}");
      var titleElt = $("[data-role='page-title']");

      tableElt.on("table-done", function (e, total, tableParams) {
        var title = "Package Filters";

        if (tableParams.search || tableParams.filter) {
          if (total === 0) {
            title = "Pending Notifications found";
          }
          else if (total > 0) {
            title = total + " Package Filter" + (total > 1 ? 's' : '') + " found";
          }
        }

        titleElt.text(title);
      });

      function onCommitAjaxSuccess(data, textstatus) {
      	/* Re-enable buttons after execution */
      	$('#submit-notification').removeAttr("disabled");
      	$('#submit-update-counts').removeAttr("disabled");

        if (data.error != "ok") {
          alert("error on request:\n" + data.error);
          return;
        }
        if (window.console && window.console.log) {
          console.log("XHR returned:", data, "(" + textstatus + ")");
        } else {
          alert("NO CONSOLE:\n");
          return;
        }
        // reload the page with the updated tables
        location.reload(true);
      }

      function onCommitAjaxError(jqXHR, textstatus, error) {
        console.log("ERROR:"+error+"|"+textstatus);
        alert("XHR errored1:\n" + error + "\n(" + textstatus + ")");
      	/* Re-enable buttons after execution */
      	$('#submit-notification').removeAttr("disabled");
      	$('#submit-update-counts').removeAttr("disabled");
      }

      /* ensure cookie exists {% csrf_token %} */
      function postCommitAjaxRequest(reqdata) {
      	/* Disable buttons during execution */
      	$('#submit-notification').attr("disabled","disabled");
      	$('#submit-update-counts').attr("disabled","disabled");

        var ajax = $.ajax({
          type:"POST",
          data: reqdata,
          url:"{% url 'xhr_packages'%}",
          headers: { 'X-CSRFToken': $.cookie("csrftoken")},
          success: onCommitAjaxSuccess,
          error: onCommitAjaxError,
        })
      }

      $('#submit-notification').click(function(){
        filter_list = "";
        $('#notificationstable input').each(function(){
          if ($(this).is(':checked')) {
            filter_list += $(this).prop('value') + ",";
          }
        });
        if ("" != notify_list) {
          postCommitAjaxRequest({
            "action"      : 'delete-filters',
            "filter_list" : filter_list
          });
        }
      });


      $('#submit-update-counts').click(function(){
          postCommitAjaxRequest({
            "action"      : 'update-counts'
          });
      });


    }); <!-- $(document).ready() -->

  </script>
{% endblock %}