FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
admin-license-std-comments.js
1 /*
2  * Copyright (C) 2019, Siemens AG
3  *
4  * Author: Gaurav Mishra, <mishra.gaurav@siemens.com>
5  *
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 function showTheMessage(message) {
21  $("html, body").animate({ scrollTop: 0 }, "slow");
22  $("#messageSpace").html(message + "<hr />").fadeIn(500).delay(5000).fadeOut(500);
23 }
24 
25 $(document).ready(function() {
26 
27  var form = $('form#adminLicenseCommentForm');
28 
29  var t = $("#adminLicenseCommentTable").DataTable({
30  "processing": true,
31  "paginationType": "listbox",
32  "order": [[ 1, 'asc' ]],
33  "autoWidth": false,
34  "columnDefs": [{
35  "createdCell": function (cell) {
36  $(cell).attr("style", "text-align:center");
37  },
38  "searchable": false,
39  "targets": [0]
40  },{
41  "orderable": false,
42  "targets": [0,2,3]
43  },{
44  "orderable": true,
45  "targets": [1]
46  }],
47  });
48 
49  t.on('order.dt search.dt', function () {
50  t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
51  cell.innerHTML = i+1;
52  });
53  }).draw();
54 
55  form.find("input[type=text],textarea").on("change", function(){
56  $(this).addClass("inputChanged");
57  });
58 
59  form.submit(function(event) {
60  var updatedFields = form.find(".inputChanged").serializeArray();
61  var insertedFields = form.find(".newCommentInputs").serializeArray();
62  if (updatedFields.length > 0 || insertedFields.length > 0) {
63  var itemsToSend = $.merge(updatedFields, insertedFields);
64  itemsToSend.push({"name": "formUpdated", "value": 1});
65  $.ajax({
66  url : '?mod=admin_license_std_comments',
67  type : 'post',
68  dataType : 'json',
69  data : itemsToSend,
70  success : function(data) {
71  var message = "";
72  if (data.updated == -1) {
73  message = "No comments updated";
74  } else if (data.updated > 0) {
75  form.find(".inputChanged").removeClass("inputChanged");
76  message = "Comments updated succesfully";
77  } else {
78  message = data.updated;
79  }
80  var messageIns = [];
81  if (data.inserted.status != 0) {
82  if (data.inserted.status & 1) {
83  form.find(".newCommentInputs").each(function(){
84  if ($(this).val().trim()) {
85  $(this).removeClass("newCommentInputs");
86  }
87  });
88  messageIns.push("Comments inserted successfully");
89  }
90  if (data.inserted.status & 1<<1) {
91  messageIns.push("errors during insertion");
92  }
93  if (data.inserted.status & 1<<2) {
94  messageIns.push("exceptions during insertion");
95  }
96  }
97  showTheMessage(message + ".<br />" + messageIns.join(" with some ") + ".");
98  },
99  error : function(data) {
100  showTheMessage(data);
101  }
102  });
103  }
104  event.preventDefault();
105  });
106 
107  $("#addStdLicComment").on('click', function(){
108  t.row.add([
109  null,
110  '<input type="text" name="insertStdLicNames[]" ' +
111  'placeholder="Please enter a name for the comment" ' +
112  'class="newCommentInputs" />',
113  '<textarea rows="7" cols="80" name="insertStdLicComments[]" ' +
114  'placeholder="Please enter a comment statement" ' +
115  'class="newCommentInputs"></textarea>',
116  '<input type="checkbox" checked disabled />'
117  ]).draw(false);
118  });
119 
120  $(".licStdCommentToggle").change(function(){
121  var changedBox = $(this);
122  var boxName = changedBox.attr("name");
123  var idRegex = /stdLicCommentEnabled\[(\d+)\]/g;
124  var commId = idRegex.exec(boxName);
125  commId = commId[1];
126  $.ajax({
127  url : '?mod=ajax_license_std_comments',
128  type : 'post',
129  dataType : 'json',
130  data : {"toggle": commId},
131  success : function(data) {
132  if (data.status != true) {
133  // Not updated, revert the UI
134  var current = changedBox.prop("checked");
135  changedBox.prop("checked", !current);
136  }
137  }
138  });
139  });
140 });
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695