// Retention rules (admin/domainadmin mailbox page): list with the last nightly run, domain choices of the add modal.
// The log of the runs is on the dashboard (draw_retention_logs). Loaded via $js_minifier.
var mailcowRetention = (function($) {
'use strict';
// lang.retention of the mailbox page, '' if missing
function L(key) {
var src = (typeof lang !== 'undefined' && lang && lang.retention) ? lang.retention : {};
return (src[key] !== undefined && src[key] !== null) ? src[key] : '';
}
function esc(s) {
return escapeHtml(s === null || s === undefined ? '' : s);
}
// replaces the %s of a text one after the other
function fill(text) {
var args = Array.prototype.slice.call(arguments, 1);
return text.replace(/%s/g, function() { return args.length ? args.shift() : ''; });
}
function folderLabel(folder) {
return folder.indexOf('folder:') === 0 ? folder.substr(7) : (L('folder_' + folder) || folder);
}
function foldersCell(item) {
return (item.folders || []).map(function(folder) { return esc(folderLabel(folder)); }).join(' ');
}
function periodCell(item) {
return esc(fill(L('days_short'), item.days)) + (item.keep_flagged == 1 ? '
' + esc(L('keep_flagged')) + '
' : '');
}
function modeCell(mode) {
return mode === 'delete' ? '' + esc(L('mode_delete')) + ''
: '' + esc(L('simulated')) + '';
}
function assignedCell(item) {
var list = [];
if (item.all_mailboxes == 1) list.push(esc(L('all_mailboxes')));
(item.mailboxes || []).slice(0, 3).forEach(function(mailbox) { list.push(esc(mailbox)); });
if ((item.mailboxes || []).length > 3) list.push('+' + (item.mailboxes.length - 3) + '');
if ((item.groups || []).length) list.push(' ' + esc(L('groups')) + ': ' + item.groups.length);
return list.length ? list.join(' ') : '' + esc(L('assigned_none')) + '';
}
function lastRunCell(run) {
if (!run) return '' + esc(L('never_run')) + '';
var text = run.simulated == 1 ? fill(L('run_simulated'), run.mailboxes, run.matched) : fill(L('run_deleted'), run.mailboxes, run.deleted);
return esc(run.created) + '