trustedDevices.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*eslint-disable no-unused-vars*/
  2. $('#myTabs a').click(function (e) {
  3. e.preventDefault();
  4. $(this).tab('show');
  5. });
  6. var revokeDevice = function (key) {
  7. $.ajax({
  8. type: 'post',
  9. url: urls.revokeRecord,
  10. data: {'key': key},
  11. success: function () {
  12. var table = $('#trustedDevicesTable').DataTable();
  13. table
  14. .rows($('#' + key).parents('tr'))
  15. .remove()
  16. .draw();
  17. },
  18. error: function () {
  19. //console.log('Could not remove record');
  20. }
  21. });
  22. };
  23. var trustedDevices = (function () {
  24. var getData = function () {
  25. $.getJSON(urls.getRecords, function (data) {
  26. trustedDevicesTable(data);
  27. });
  28. };
  29. var trustedDevicesTable = function (jsonData) {
  30. var t = $('#trustedDevicesTable').DataTable({
  31. 'order': [[2, 'desc']],
  32. columnDefs: [
  33. {'width': '20%', 'targets': 0},
  34. {'width': '10%', 'targets': 1},
  35. {'width': '60%', 'targets': 2},
  36. {'width': '10%', 'targets': 3},
  37. {'width': '30%', 'targets': 4}
  38. ]
  39. });
  40. for (var i = 0; i < jsonData.length; i++) {
  41. var rec = jsonData[i];
  42. t.row.add([
  43. rec.name,
  44. rec.principal,
  45. new Date(rec.date),
  46. rec.geography,
  47. '<button id=\'' + rec.key + '\' class=\'btn btn-sm btn-danger\' type=\'button\' value=\'ALL\' onclick=\'revokeDevice("' + rec.key + '")\'>Revoke</button>'
  48. ]).draw(false);
  49. }
  50. };
  51. // initialization *******
  52. (function init() {
  53. getData();
  54. })();
  55. })();