FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
user-edit.js
1 /***********************************************************
2  * Copyright (C) 2019 Siemens AG
3  * Author: Gaurav Mishra <mishra.gaurav@siemens.com>
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 
24 function delayedFadeOut(time, element) {
25  $(element).delay(time).fadeOut();
26 }
27 
28 $(function() {
29  $(".pat-revoke").on('click', function(e) {
30  var button = this;
31  var tokenId = button.id.split('-')[1];
32  var parentTr = $(button).parent().parent();
33  $.ajax({
34  type : "POST",
35  data : {
36  "task" : "revoke",
37  "token-id" : tokenId
38  },
39  url : "?mod=manage-token",
40  success : function(data) {
41  if (data.status == true) {
42  button.disabled = true; // Disable button to prevent new requests
43  parentTr
44  .html("<td colspan='6'>The token is revoked</td>");
45  delayedFadeOut(5000, parentTr);
46  } else {
47  var infoMessage = $("<td>Unable to revoke token</td>");
48  parentTr.append(infoMessage);
49  delayedFadeOut(5000, infoMessage);
50  }
51  },
52  error : function(data) {
53  var infoMessage = $("<td>Some error occured</td>");
54  parentTr.append(infoMessage);
55  delayedFadeOut(5000, infoMessage);
56  }
57  });
58  });
59 
60  $(".pat-reveal").on('click', function(e) {
61  var button = this;
62  var tokenId = button.id.split('-')[1];
63  var parentTr = $(button).parent().parent();
64  $.ajax({
65  type : "POST",
66  data : {
67  "task" : "reveal",
68  "token-id" : tokenId
69  },
70  url : "?mod=manage-token",
71  success : function(data) {
72  if (data.status == true) {
73  button.disabled = true; // Disable button to prevent new requests
74  var tokenDisplay = $("<tr><td colspan='6'>"
75  + "<textarea readonly style='width:100%'>" + data.token
76  + "</textarea></td></tr>");
77  parentTr.after(tokenDisplay);
78  } else {
79  var infoMessage = $("<tr><td colspan='6'>"
80  + "<textarea readonly style='width:100%'>"
81  + "Unable to reveal token</textarea></td></tr>");
82  parentTr.after(infoMessage);
83  delayedFadeOut(5000, infoMessage);
84  }
85  },
86  error : function(data) {
87  var infoMessage = $("<tr><td colspan='6'>"
88  + "<textarea readonly style='width:100%'>"
89  + "Some error occured</textarea></td></tr>");
90  parentTr.after(infoMessage);
91  delayedFadeOut(5000, infoMessage);
92  }
93  });
94  });
95 });