/** * How one in-game mail row is shown on the Mail page and in a character's mailbox: who sent it and to whom (linked to * their characters and accounts), its subject and body as the client shows them (locale keys translated), the * attachment with its icon, and its state (unread, read, attachment waiting or claimed, deleted by the player). * Rows come from /api/tables/mail and /api/characters/:id/mail. */ (function () { 'use strict'; function account(id) { return id ? ' (account)' : ''; } var MailView = { // Sender: a player's character, the game, or a staff member ("[GM] name") sender: function (m, withAccount) { if (m.sender_id && m.sender_id !== '0') return fmt.character(m.sender_id, m.sender_name) + (withAccount ? account(m.sender_account_id) : ''); return '' + esc(m.sender_text) + ' ' + fmt.badge(m.sender_kind === 'staff' ? 'Staff' : 'Game', m.sender_kind === 'staff' ? 'warning' : 'secondary'); }, receiver: function (m, withAccount) { return fmt.character(m.receiver_id, m.receiver_name) + (withAccount ? account(m.receiver_account_id) : ''); }, attachment: function (m, large) { var a = m.attachment; if (!a) return '-'; var size = large ? 40 : 28; var icon = a.lot ? '' : ''; var name = a.lot ? esc(a.count) + '× ' + esc(a.name || ('LOT ' + a.lot)) + ' (' + esc(a.lot) + ')' : esc(a.count) + ' item(s)'; var state = a.claimed ? ' ' + fmt.badge('Claimed', 'secondary') : ' ' + fmt.badge('Waiting', 'info'); return '' + icon + name + '' + state; }, state: function (m) { if (m.deleted_at) return '' + fmt.badge('Deleted', 'danger') + ''; return m.read ? fmt.badge('Read', 'secondary') : fmt.badge('Unread', 'primary'); }, // The subject as shown, with the stored text on hover when it had locale keys subject: function (m) { var title = m.subject_text !== m.subject ? ' title="Stored as ' + esc(m.subject) + '"' : ''; return '' + esc(m.subject_text || '(no subject)') + ''; }, // The whole mail, for a dialog or a mailbox list card: function (m) { var stored = m.subject_text !== m.subject || m.body_text !== m.body || m.sender_text !== m.sender_name; var a = m.attachment; var rows = [ ['From', MailView.sender(m, true)], ['To', MailView.receiver(m, true)], ['Sent', esc(fmt.unix(m.time_sent))], ['State', m.deleted_at ? fmt.badge('Deleted by the player', 'danger') + ' ' + esc(fmt.unix(m.deleted_at)) + ' (' + (m.read ? 'read' : 'never read') + ' before; the player no longer sees it)' : (m.read ? fmt.badge('Read', 'secondary') : fmt.badge('Unread', 'primary'))] ]; if (a) { rows.push(['Attachment', MailView.attachment(m, true)]); if (a.id && a.id !== '0') rows.push(['Item ID', '' + esc(a.id) + '' + (a.subkey && a.subkey !== '0' ? ' subkey ' + esc(a.subkey) + '' : '')]); if (a.config) rows.push(['Item data', '
' + esc(a.config) + '
']); } return '
' + '
' + MailView.subject(m) + '#' + esc(m.id) + '
' + '
' + rows.map(function (r) { return '
' + r[0] + '
' + r[1] + '
'; }).join('') + '
' + '
' + esc(m.body_text) + '
' + (stored ? '
Stored text (locale keys)
' + esc('From: ' + m.sender_name + '\nSubject: ' + m.subject + '\n\n' + m.body) + '
' : '') + '
'; } }; window.MailView = MailView; })();