From de825af47a528df09434647d10093abdc19ca784 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 28 Feb 2024 18:37:15 +0100 Subject: [PATCH] New support: load legacy tickets --- www/admin/inner.js | 2 + www/common/inner/sidebar-layout.js | 1 + www/moderation/inner.js | 69 ++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/www/admin/inner.js b/www/admin/inner.js index d2c4c044c..3c0f43fc3 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -2631,6 +2631,8 @@ Example create['support-list'] = function () { if (!supportKey || !APP.privateKey || !checkAdminKey(APP.privateKey)) { return; } + // XXX NO NEED ANYMORE + return; var $container = makeBlock('support-list'); // Msg.admin_supportListHint, .admin_supportListTitle var $div = $(h('div.cp-support-container')).appendTo($container); diff --git a/www/common/inner/sidebar-layout.js b/www/common/inner/sidebar-layout.js index a6253a2f2..d89ac0205 100644 --- a/www/common/inner/sidebar-layout.js +++ b/www/common/inner/sidebar-layout.js @@ -136,6 +136,7 @@ define([ sidebar.addItem = (key, get, options) => { const safeKey = keyToCamlCase(key); get((content, config) => { + if (content === false) { return; } config = config || {}; options = options || {}; const title = options.noTitle ? undefined : h('label.cp-item-label', { diff --git a/www/moderation/inner.js b/www/moderation/inner.js index ed4b5ef15..ab1f41c86 100644 --- a/www/moderation/inner.js +++ b/www/moderation/inner.js @@ -268,6 +268,12 @@ define([ 'open-ticket' ] }, + 'legacy': { + icon: undefined, + content: [ + 'legacy' + ] + }, 'refresh': { icon: undefined, onClick: refreshAll @@ -377,6 +383,69 @@ define([ cb(div); }); + // XXX + Messages.support_legacyTitle = "View old support data"; + Messages.support_legacyHint = "View tickets from the legacy system. You'll be able to recreate thse tickets on the new support system."; + Messages.support_legacyButton = "Start"; + Messages.support_legacyClear = "Delete from my account"; + sidebar.addItem('legacy', cb => { + if (!APP.privateKey) { return void cb(false); } + + let start = blocks.button('primary', 'fa-paper-plane', Messages.support_legacyButton); + let clean = blocks.button('danger', 'fa-trash-o', Messages.support_legacyClear); + let content = h('div.cp-support-container'); + let nav = blocks.nav([start, clean]); + + UI.confirmButton(clean, { classes: 'btn-danger' }, function () { + // XXX TODO remove my supportadmin mailbox + console.error('NOT IMPLEMENTED'); + }); + + let run = () => { + let $div = $(content); + $div.empty(); + common.mailbox.subscribe(['supportadmin'], { + onMessage: function (data) { + /* + Get ID of the ticket + If we already have a div for this ID + Push the message to the end of the ticket + If it's a new ticket ID + Make a new div for this ID + */ + var msg = data.content.msg; + var hash = data.content.hash; + var content = msg.content; + console.error(content, msg, hash); + var id = content.id; + var $ticket = $div.find('.cp-support-list-ticket[data-id="'+id+'"]'); + + if (msg.type === 'CLOSE') { + // A ticket has been closed by the admins... + if (!$ticket.length) { return; } + $ticket.addClass('cp-support-list-closed'); + $ticket.append(APP.support.makeCloseMessage(content, hash)); + return; + } + if (msg.type !== 'TICKET') { return; } + $ticket.removeClass('cp-support-list-closed'); + + if (!$ticket.length) { + $ticket = APP.support.makeTicket({id, content}); + $div.append($ticket); + } + $ticket.append(APP.support.makeMessage(content)); + $ticket.find('.cp-support-showdata').attr('onclick', `showData();`); + $ticket.find('.cp-support-showdata button').attr('onclick', `copyData();`); + } + }); + }; + Util.onClickEnter($(start), run); + + let div = blocks.form([content], nav); + cb(div); + }); + sidebar.makeLeftside(categories); };