blob: 9adc79b5f20f91df51107eb3a676960188ddea1d [file] [log] [blame]
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001jQuery(function($){
2
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01003 $(".refresh_table").on('click', function(e) {
4 e.preventDefault();
5 var table_name = $(this).data('table');
6 $('#' + table_name).DataTable().ajax.reload();
7 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01008
9
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010010 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]}
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010011
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010012 // 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'));
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010018 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010019 $.ajax({
20 type: 'GET',
21 url: '/api/v1/get/postcat/' + button.data('queue-id'),
22 dataType: 'text',
23 complete: function (data) {
24 $('#queue_msg_content').text(data.responseText);
25 }
26 });
27 })
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010028
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010029 function draw_queue() {
30 // just recalc width if instance already exists
31 if ($.fn.DataTable.isDataTable('#queuetable') ) {
32 $('#queuetable').DataTable().columns.adjust().responsive.recalc();
33 return;
34 }
35
36 $('#queuetable').DataTable({
37 responsive: true,
38 processing: true,
39 serverSide: false,
40 stateSave: true,
41 pageLength: pagination_size,
42 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
43 "tr" +
44 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
45 language: lang_datatables,
46 ajax: {
47 type: "GET",
48 url: "/api/v1/get/mailq/all",
49 dataSrc: function(data){
50 $.each(data, function (i, item) {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020051 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailqitems" name="multi_select" value="' + escapeHtml(item.queue_id) + '" />';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010052 rcpts = $.map(item.recipients, function(i) {
53 return escapeHtml(i);
54 });
55 item.recipients = rcpts.join('<hr style="margin:1px!important">');
56 item.action = '<div class="btn-group">' +
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020057 '<a href="#" data-bs-toggle="modal" data-bs-target="#showQueuedMsg" data-queue-id="' + escapeHtml(item.queue_id) + '" class="btn btn-xs btn-secondary">' + lang.show_message + '</a>' +
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010058 '</div>';
59 });
60 return data;
61 }
62 },
63 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010064 {
65 // placeholder, so checkbox will not block child row toggle
66 title: '',
67 data: null,
68 searchable: false,
69 orderable: false,
70 defaultContent: ''
71 },
72 {
73 title: '',
74 data: 'chkbox',
75 searchable: false,
76 orderable: false,
77 defaultContent: ''
78 },
79 {
80 title: 'QID',
81 data: 'queue_id',
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020082 defaultContent: '',
83 render: $.fn.dataTable.render.text()
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010084 },
85 {
86 title: 'Queue',
87 data: 'queue_name',
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +020088 defaultContent: '',
89 render: $.fn.dataTable.render.text()
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010090 },
91 {
92 title: lang_admin.arrival_time,
93 data: 'arrival_time',
94 defaultContent: '',
95 render: function (data, type){
96 var date = new Date(data ? data * 1000 : 0);
97 return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
98 }
99 },
100 {
101 title: lang_admin.message_size,
102 data: 'message_size',
103 defaultContent: '',
104 render: function (data, type){
105 return humanFileSize(data);
106 }
107 },
108 {
109 title: lang_admin.sender,
110 data: 'sender',
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200111 defaultContent: '',
112 render: $.fn.dataTable.render.text()
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100113 },
114 {
115 title: lang_admin.recipients,
116 data: 'recipients',
117 defaultContent: ''
118 },
119 {
120 title: lang_admin.action,
121 data: 'action',
122 className: 'dt-sm-head-hidden dt-text-right',
123 defaultContent: ''
124 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100125 ]
126 });
127 }
128
129 draw_queue();
130
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100131})