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