aboutsummaryrefslogtreecommitdiffstats
path: root/lib/srtgui/templates/published-select-toastertable.html
blob: 2509a4dd933759893dadd4b23389ebd05158b746 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
{% 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>
  {% if request.user.is_creator %}{% else %}<meta http-equiv="refresh" content="0; url=/" />{% endif %}

  <style>
  /* Style the execution buttons */
  button.execute { height:50px;width:210px;background-color:#4CAF50;text-align:center; border:2px #f69c55;border-radius: 12px; }

  button:disabled {
    cursor: not-allowed;
  }

  /* Create two equal columns that floats next to each other */
  .column {
      float: left;
      width: 350px;
      padding: 10px;
  }

  /* Clear floats after the columns */
  .row:after {
      content: "";
      display: table;
      clear: both;
  }
  </style>

{% endblock %}

{% block title %} Publish Reqested CVE's - SRTool {% 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><a href="{% url 'publish' %}">Publish</a></li><span class="divider">&rarr;</span>
			<li>Publish Requested Update CVE's</li>
  		</ul>
  	</div>
  </div>

  <div id="change-publish-state" > <!--class="form-inline" -->
    <b><big>Actions: </big></b>
    <button id="select-these" class="btn btn-default" type="button">Select these</button>
    <button id="unselect-these" class="btn btn-default" type="button">Un-select these</button>
    <button id="select-publish" class="btn btn-default" type="button">Update ...</button>
    <!--<button id="collect-publish" class="btn btn-default" type="button">Collect Publishable CVEs</button> -->
  </div>

  <div id="details-publish" style="display:none;">
  	<p><p>
    <button class="execute" id="submit-publish"> Update Publish CVE State </button>
    <p><b><big>New Publish State: </big></b>
    <select name="Publish" id="select-publish-state">
    <option value="0"         >Unpublished</option>
    <option value="1"         >Not to be Published</option>
    <option value="2" selected>Published</option>
    <option value="3"         >Publish Request (New)</option>
    <option value="4"         >Publish Request (Update)</option>
    <option value="5"         >Publish Submitted</option>
    </select>
  </div>

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

  	{% url '' as xhr_table_url %}
  	{% include 'toastertable.html' %}
    </div>
  </div>

  <!-- Javascript support -->
  <script>

  //# sourceURL=somename.js

  // global variables
  var selected_publish=false;
  var cve_total=0;

  $(document).ready(function() {

    function onCommitAjaxSuccess(data, textstatus) {
      if (window.console && window.console.log) {
        console.log("XHR returned:", data, "(" + textstatus + ")");
      } else {
        alert("NO CONSOLE:\n");
        return;
      }
      if (data.error != "ok") {
        alert("error on request:\n" + data.error);
        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 + ")");
    }

	/* ensure cookie exists {% csrf_token %} */
	function postCommitAjaxRequest(reqdata) {
		var ajax = $.ajax({
				type:"POST",
				data: reqdata,
				url:"{% url 'xhr_cve_publish_commit' %}",
				headers: { 'X-CSRFToken': $.cookie("csrftoken")},
				success: onCommitAjaxSuccess,
				error: onCommitAjaxError,
		})
	}

    function update_publish_status() {
      var cve_count = 0;
      var cve_checked_count = 0;
      $('#updatepublishedtable input').each(function(){
        cve_count = cve_count + 1;
        if ($(this).is(':checked')) {
          cve_checked_count = cve_checked_count + 1;
        }
      });
      if (cve_total > cve_count) {
          document.getElementById("select-these").innerText = "Select "+(cve_count-cve_checked_count)+" unchecked ("+(cve_total-cve_count)+" offpage)";
      } else {
          document.getElementById("select-these").innerText = "Select "+(cve_count-cve_checked_count)+" unchecked";
      }
      document.getElementById("unselect-these").innerText = "Un-select "+cve_checked_count+" checked";
      if (0 == cve_checked_count) {
        //$("#submit-publish").attr("disabled","disabled");
        document.getElementById("submit-publish").disabled = true;
      } else {
        //$("#submit-publish").removeAttr("disabled");
        document.getElementById("submit-publish").disabled = false;
      }
    }

    $('#select-these').click(function(){
      $('#updatepublishedtable input').each(function(){
        $(this).prop('checked', true);
      });
      update_publish_status();
    });

    $('#unselect-these').click(function(){
      $('#updatepublishedtable input').each(function(){
        $(this).prop('checked', false);
      });
      update_publish_status();
    });

    // Open Publish Action
    $('#select-publish').click(function(){
      if (selected_publish) {
        selected_publish=false;
        $("#select-these").removeAttr("disabled");
        $("#unselect-these").removeAttr("disabled");
	    $("#details-publish").slideUp();
      } else {
        selected_publish=true;
        $("#select-these").attr("disabled","disabled");
        $("#unselect-these").attr("disabled","disabled");
        update_publish_status();
        $("#details-publish").slideDown();
      }
    });

    $('#submit-publish').click(function(){
      var cve_list="";
      $('#updatepublishedtable input').each(function(){
        if ($(this).is(':checked')) {
          cve_list +=$(this).prop('name') + ",";
        }
      });
      if ("" == cve_list) {
        alert("No CVE's were selected");
        return;
      }
      publish_state=$('#select-publish-state').val();
	  postCommitAjaxRequest({
		"publish_state" : publish_state,
		"cve_list"      : cve_list,
		});

//      $.post("/srtgui/export/publish_cve", {parent_page:'publish_cve',cve_list:cve_list,report_type:$('#report_type').val(),report_format:$('#report_format').val(),csrfmiddlewaretoken:'{{ csrf_token }}'}, function(result){
//        alert(result);
//      });

    });

    // When change in CVE selections, update labels and enables
    $(document).on("change", "#updatepublishedtable :checkbox", function() {
      update_publish_status();
    });


    // Standard Toaster Table enablement

      var tableElt = $("#{{table_name}}");
      var titleElt = $("[data-role='page-title']");

      tableElt.on("table-done", function (e, total, tableParams) {
        var title = "Publish Requested CVE's";

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

        titleElt.text(title);
        cve_total = total;
        update_publish_status();

        /* Set the report link */
        var record_list=""
        $(".name > a").each(function(){
          var this_id=$(this).prop('id');
          if (this_id.startsWith("dataid_")) {
            record_list += this_id.replace(/dataid_/,"") + ",";
          }
        });
        $('#report_link').attr('href',"{% url 'report' request.resolver_match.url_name %}?record_list="+record_list);

      });
    });
  </script>
{% endblock %}