queue.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. jQuery(function($){
  2. $(".refresh_table").on('click', function(e) {
  3. e.preventDefault();
  4. var table_name = $(this).data('table');
  5. $('#' + table_name).DataTable().ajax.reload();
  6. });
  7. function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
  8. // Queue item
  9. $('#showQueuedMsg').on('show.bs.modal', function (e) {
  10. $('#queue_msg_content').text(lang.loading);
  11. button = $(e.relatedTarget)
  12. if (button != null) {
  13. $('#queue_id').text(button.data('queue-id'));
  14. }
  15. $.ajax({
  16. type: 'GET',
  17. url: '/api/v1/get/postcat/' + button.data('queue-id'),
  18. dataType: 'text',
  19. complete: function (data) {
  20. console.log(data);
  21. $('#queue_msg_content').text(data.responseText);
  22. }
  23. });
  24. })
  25. function draw_queue() {
  26. // just recalc width if instance already exists
  27. if ($.fn.DataTable.isDataTable('#queuetable') ) {
  28. $('#queuetable').DataTable().columns.adjust().responsive.recalc();
  29. return;
  30. }
  31. $('#queuetable').DataTable({
  32. responsive: true,
  33. processing: true,
  34. serverSide: false,
  35. stateSave: true,
  36. language: lang_datatables,
  37. ajax: {
  38. type: "GET",
  39. url: "/api/v1/get/mailq/all",
  40. dataSrc: function(data){
  41. $.each(data, function (i, item) {
  42. item.chkbox = '<input type="checkbox" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
  43. rcpts = $.map(item.recipients, function(i) {
  44. return escapeHtml(i);
  45. });
  46. item.recipients = rcpts.join('<hr style="margin:1px!important">');
  47. item.action = '<div class="btn-group">' +
  48. '<a href="#" data-bs-toggle="modal" data-bs-target="#showQueuedMsg" data-queue-id="' + encodeURI(item.queue_id) + '" class="btn btn-xs btn-secondary">' + lang.queue_show_message + '</a>' +
  49. '</div>';
  50. });
  51. return data;
  52. }
  53. },
  54. columns: [
  55. {
  56. // placeholder, so checkbox will not block child row toggle
  57. title: '',
  58. data: null,
  59. searchable: false,
  60. orderable: false,
  61. defaultContent: ''
  62. },
  63. {
  64. title: '',
  65. data: 'chkbox',
  66. searchable: false,
  67. orderable: false,
  68. defaultContent: ''
  69. },
  70. {
  71. title: 'QID',
  72. data: 'queue_id',
  73. defaultContent: ''
  74. },
  75. {
  76. title: 'Queue',
  77. data: 'queue_name',
  78. defaultContent: ''
  79. },
  80. {
  81. title: lang_admin.arrival_time,
  82. data: 'arrival_time',
  83. defaultContent: '',
  84. render: function (data, type){
  85. var date = new Date(data ? data * 1000 : 0);
  86. return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
  87. }
  88. },
  89. {
  90. title: lang_admin.message_size,
  91. data: 'message_size',
  92. defaultContent: '',
  93. render: function (data, type){
  94. return humanFileSize(data);
  95. }
  96. },
  97. {
  98. title: lang_admin.sender,
  99. data: 'sender',
  100. defaultContent: ''
  101. },
  102. {
  103. title: lang_admin.recipients,
  104. data: 'recipients',
  105. defaultContent: ''
  106. },
  107. {
  108. title: lang_admin.action,
  109. data: 'action',
  110. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  111. defaultContent: ''
  112. },
  113. ]
  114. });
  115. }
  116. draw_queue();
  117. })