blob: 26c15091d3ec3eb7b1c732ef9ba771a76d9d685e [file] [log] [blame]
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001jQuery(function($){
2
Matthias Andreas Benkardd1f5b682023-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 Benkard1ba53812022-12-27 17:32:58 +01008
9
Matthias Andreas Benkardd1f5b682023-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 Benkard1ba53812022-12-27 17:32:58 +010011
Matthias Andreas Benkardd1f5b682023-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 Benkard1ba53812022-12-27 17:32:58 +010018 }
Matthias Andreas Benkardd1f5b682023-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 Benkard1ba53812022-12-27 17:32:58 +010028
Matthias Andreas Benkardd1f5b682023-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) {
51 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailqitems" name="multi_select" value="' + item.queue_id + '" />';
52 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">' +
57 '<a href="#" data-bs-toggle="modal" data-bs-target="#showQueuedMsg" data-queue-id="' + encodeURI(item.queue_id) + '" class="btn btn-xs btn-secondary">' + lang.show_message + '</a>' +
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010058 '</div>';
59 });
60 return data;
61 }
62 },
63 columns: [
Matthias Andreas Benkardd1f5b682023-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',
82 defaultContent: ''
83 },
84 {
85 title: 'Queue',
86 data: 'queue_name',
87 defaultContent: ''
88 },
89 {
90 title: lang_admin.arrival_time,
91 data: 'arrival_time',
92 defaultContent: '',
93 render: function (data, type){
94 var date = new Date(data ? data * 1000 : 0);
95 return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
96 }
97 },
98 {
99 title: lang_admin.message_size,
100 data: 'message_size',
101 defaultContent: '',
102 render: function (data, type){
103 return humanFileSize(data);
104 }
105 },
106 {
107 title: lang_admin.sender,
108 data: 'sender',
109 defaultContent: ''
110 },
111 {
112 title: lang_admin.recipients,
113 data: 'recipients',
114 defaultContent: ''
115 },
116 {
117 title: lang_admin.action,
118 data: 'action',
119 className: 'dt-sm-head-hidden dt-text-right',
120 defaultContent: ''
121 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100122 ]
123 });
124 }
125
126 draw_queue();
127
Matthias Andreas Benkardd1f5b682023-11-18 13:18:30 +0100128})