[Web] Fix temporary email aliases sorting

This commit is contained in:
FreddleSpl0it 2023-04-21 12:26:50 +02:00
parent 73570cc8b5
commit cf1cc24e33
No known key found for this signature in database
GPG Key ID: 00E14E7634F4BEC5
3 changed files with 29 additions and 16 deletions

View File

@ -1,3 +1,13 @@
const LOCALE = undefined;
const DATETIME_FORMAT = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
};
$(document).ready(function() { $(document).ready(function() {
// mailcow alert box generator // mailcow alert box generator
window.mailcow_alert_box = function(message, type) { window.mailcow_alert_box = function(message, type) {

View File

@ -1,13 +1,3 @@
const LOCALE = undefined;
const DATETIME_FORMAT = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
};
$(document).ready(function() { $(document).ready(function() {
// Parse seconds ago to date // Parse seconds ago to date
// Get "now" timestamp // Get "now" timestamp

View File

@ -127,6 +127,20 @@ jQuery(function($){
} }
} }
function createSortableDate(td, cellData, date_string = false) {
if (date_string)
var date = new Date(cellData);
else
var date = new Date(cellData ? cellData * 1000 : 0);
var timestamp = date.getTime();
$(td).attr({
"data-order": timestamp,
"data-sort": timestamp
});
$(td).html(date.toLocaleDateString(LOCALE, DATETIME_FORMAT));
}
function draw_tla_table() { function draw_tla_table() {
// just recalc width if instance already exists // just recalc width if instance already exists
if ($.fn.DataTable.isDataTable('#tla_table') ) { if ($.fn.DataTable.isDataTable('#tla_table') ) {
@ -144,6 +158,7 @@ jQuery(function($){
"tr" + "tr" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
language: lang_datatables, language: lang_datatables,
order: [[4, 'desc']],
ajax: { ajax: {
type: "GET", type: "GET",
url: "/api/v1/get/time_limited_aliases", url: "/api/v1/get/time_limited_aliases",
@ -191,18 +206,16 @@ jQuery(function($){
title: lang.alias_valid_until, title: lang.alias_valid_until,
data: 'validity', data: 'validity',
defaultContent: '', defaultContent: '',
render: function (data, type) { createdCell: function(td, cellData) {
var date = new Date(data ? data * 1000 : 0); createSortableDate(td, cellData)
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
} }
}, },
{ {
title: lang.created_on, title: lang.created_on,
data: 'created', data: 'created',
defaultContent: '', defaultContent: '',
render: function (data, type) { createdCell: function(td, cellData) {
var date = new Date(data.replace(/-/g, "/")); createSortableDate(td, cellData, true)
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
} }
}, },
{ {