browse.ui.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. window.renderInstanceList = function (result, {col, row, value})
  2. {
  3. if(col.name === 'status')
  4. {
  5. switch(value)
  6. {
  7. case 'running':
  8. var statusClass = 'text-success';
  9. break;
  10. case 'abnormal':
  11. var statusClass = 'text-danger';
  12. break;
  13. default:
  14. var statusClass = '';
  15. }
  16. result[0] = {html: '<span class="' + statusClass + '">' + result[0] + '</span>'};
  17. }
  18. else if(col.name === 'name')
  19. {
  20. if(row.data.type == 'external')
  21. {
  22. result[0] = {html: '<a href="' + $.createLink('instance', 'view', 'id=' + row.data.externalID + '&type=external') + '">' + result[0] + '</a>'};
  23. }
  24. else
  25. {
  26. result[0] = {html: '<a href="' + $.createLink('instance', 'view', 'id=' + row.id) + '">' + result[0] + '</a>'};
  27. }
  28. }
  29. else if(col.name === 'createdAt')
  30. {
  31. if(value.includes('0000-00-00')) result[0] = '';
  32. }
  33. return result;
  34. }
  35. $(function()
  36. {
  37. if(typeof timer !== 'undefined') clearInterval(timer);
  38. if(idList.length === 0) return;
  39. if(inQuickon) timer = setInterval(refreshStatus, 5000);
  40. });
  41. window.onPageUnmount = function()
  42. {
  43. if(typeof timer !== 'undefined') clearInterval(timer);
  44. }
  45. function refreshStatus()
  46. {
  47. const postData = new FormData();
  48. if(idList.length > 0)
  49. {
  50. idList.forEach(function(id){postData.append('idList[]', id)});
  51. }
  52. $.ajaxSubmit({
  53. url: $.createLink('instance', 'ajaxStatus'),
  54. method: 'POST',
  55. data: postData,
  56. onComplete: function(res)
  57. {
  58. if(res.result === 'success')
  59. {
  60. $.each(res.data, function(index, instance)
  61. {
  62. if(statusMap[instance.id] != instance.status)
  63. {
  64. loadTable();
  65. statusMap[instance.id] = instance.status;
  66. return;
  67. }
  68. });
  69. }
  70. }
  71. });
  72. }
  73. window.bindUser = function(externalID, appName)
  74. {
  75. loadPage($.createLink(appName.toLowerCase(), 'bindUser', 'id=' + externalID));
  76. }
  77. window.editApp = function(externalID, appName)
  78. {
  79. if(appName == 'Nexus')
  80. {
  81. $('#editLinkContainer').attr('href', $.createLink('instance', 'editExternalApp', 'id=' + externalID));
  82. }
  83. else
  84. {
  85. $('#editLinkContainer').attr('href', $.createLink(appName.toLowerCase(), 'edit', 'id=' + externalID));
  86. }
  87. $('#editLinkContainer').trigger('click');
  88. }