FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
license.js
1 /*
2  Copyright (C) 2014-2015, Siemens AG
3  Author: Daniele Fognini, Johannes Najjar, Steffen Weber
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 function addArsGo(formid, selectid)
20 {
21  var selectobj = document.getElementById(selectid);
22  var agentId = selectobj.options[selectobj.selectedIndex].value;
23  document.getElementById(formid).action = '$action' + '&agent=' + agentId;
24  document.getElementById(formid).submit();
25  return;
26 }
27 
28 jQuery.extend(jQuery.fn.dataTableExt.oSort, {
29  "num-html-pre": function (a) {
30  var x = String(a).replace(/<[\s\S]*?>/g, "");
31  return parseFloat(x);
32  },
33  "num-html-asc": function (a, b) {
34  return ((a < b) ? -1 : ((a > b) ? 1 : 0));
35  },
36  "num-html-desc": function (a, b) {
37  return ((a < b) ? 1 : ((a > b) ? -1 : 0));
38  }
39 });
40 
41 $(document).ready(function () {
42  if (typeof createLicHistTable === 'function') {
43  createLicHistTable();
44  }
45 
46  searchField = $('#dirlist_filter input');
47  var dirListFilter = getCookie('dirListFilter');
48  filterLicense(dirListFilter);
49  searchField.keyup(function () {
50  setCookie('dirListFilter', $(this).val());
51  });
52 
53  var scanFilter = getCookie('scanFilter');
54  if(scanFilter==="") {
55  scanFilter = 0;
56  }
57  $('#scanFilter option[value='+scanFilter+']').parent().val(scanFilter);
58  $('#scanFilter').change(function (){ filterScan($(this).val(),'scan'); });
59 
60  var conFilter = getCookie('conFilter');
61  if(conFilter==="") {
62  conFilter = 0;
63  }
64  $('#conFilter option[value='+conFilter+']').parent().val(conFilter);
65  $('#conFilter').change(function (){ filterScan($(this).val(),'con'); });
66 
67  var openFilter = getCookie('openFilter');
68  if(openFilter==='true' || openFilter==='checked') {
69  $('#openCBoxFilter').prop('checked',openFilter);
70  }
71  $('#openCBoxFilter').click(function (){
72  setCookie('openFilter', $(this).prop('checked'));
73  otable.fnFilter('');
74  });
75 
76  if (typeof createDirlistTable === 'function') {
77  createDirlistTable();
78  }
79  $("form[data-autosubmit] select").change(function () {
80  $(this).closest('form').submit();
81  });
82 });
83 
84 
85 function filterLicense(licenseShortName) {
86  var searchField = $('#dirlist_filter input');
87  searchField.val(licenseShortName);
88  resetFilters();
89  searchField.trigger('keyup');
90 }
91 
92 function clearSearchLicense() {
93  var searchField = $('#lichistogram_filter input');
94  searchField.val('');
95  resetFilters();
96  searchField.trigger('keyup.DT');
97 }
98 
99 function clearSearchFiles() {
100  $('#dirlist_filter_license').val('');
101  var searchField = $('#dirlist_filter input');
102  searchField.val('');
103  resetFilters();
104  searchField.trigger('keyup');
105 }
106 
107 
108 function scheduleScan(upload, agentName, resultEntityKey) {
109  var post_data = {
110  "agentName": agentName,
111  "uploadId": upload
112  };
113 
114  var resultEntity = $(resultEntityKey);
115  resultEntity.hide();
116 
117  $.ajax({
118  type: "POST",
119  url: "?mod=scheduleAgentAjax",
120  data: post_data,
121  success: function (data) {
122  var jqPk = data.jqid;
123  if (jqPk) {
124  resultEntity.html("scan scheduled as " + linkToJob(jqPk) + "<br/>");
125  $('#' + agentName.replace("agent_", "") + "_span").hide();
126  queueUpdateCheck(jqPk, function () {
127  resultEntity.html(agentName.replace("agent_", "") + " done.<br/>");
128  }, function () {
129  resultEntity.html(agentName.replace("agent_", "") + " failed!<br/>");
130  }
131  );
132  }
133  else {
134  resultEntity.html("Bad response from server. <br/>");
135  }
136  resultEntity.show();
137  },
138  error: function (responseobject) {
139  var error = responseobject.responseJSON.error;
140  resultEntity.html((error ? "error: " + error : "error") + "<br/>");
141  resultEntity.show();
142  }
143  });
144 }
145 
146 function dressContents(data, type, full) {
147  if (type === 'display') {
148  return '<a href=\'#\' onclick=\'filterScan(' + data[1] + ',\"scan\")\'>' + data[0] + '</a>';
149  }
150  return data;
151 }
152 
153 function filterScan(id,keyword) {
154  if(keyword==='scan'){
155  $('#scanFilter').val(id);
156  setCookie('scanFilter', id);
157  }
158  else if(keyword==='con')
159  {
160  $('#conFilter').val(id);
161  setCookie('conFilter', id);
162  }
163  otable.fnFilter('');
164 }
165 
166 function resetFilters()
167 {
168  $('#scanFilter').val(0);
169  $('#conFilter').val(0);
170  $('#openCBoxFilter').attr('checked',false);
171 }