diff --git a/www/admin/inner.js b/www/admin/inner.js index e2edb9ad5..4c335dd12 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -199,13 +199,13 @@ define([ // A ticket has been closed by the admins... if (!$ticket.length) { return; } $ticket.addClass('cp-support-list-closed'); - $ticket.append(Support.makeCloseMessage(common, content, hash)); + $ticket.append(APP.support.makeCloseMessage(content, hash)); return; } if (msg.type !== 'TICKET') { return; } if (!$ticket.length) { - $ticket = Support.makeTicket($div, common, content, function () { + $ticket = APP.support.makeTicket($div, content, function () { var error = false; hashesById[id].forEach(function (d) { common.mailbox.dismiss(d, function (err) { @@ -218,7 +218,7 @@ define([ if (!error) { $ticket.remove(); } }); } - $ticket.append(Support.makeMessage(common, content, hash, true)); + $ticket.append(APP.support.makeMessage(content, hash)); } }); return $div; @@ -349,6 +349,7 @@ define([ APP.privateKey = privateData.supportPrivateKey; APP.origin = privateData.origin; APP.readOnly = privateData.readOnly; + APP.support = Support.create(common, true); // Content var $rightside = APP.$rightside; diff --git a/www/support/inner.js b/www/support/inner.js index 4de6fcb04..ded97b272 100644 --- a/www/support/inner.js +++ b/www/support/inner.js @@ -107,13 +107,13 @@ define([ // A ticket has been closed by the admins... if (!$ticket.length) { return; } $ticket.addClass('cp-support-list-closed'); - $ticket.append(Support.makeCloseMessage(common, content, hash)); + $ticket.append(APP.support.makeCloseMessage(content, hash)); return; } if (msg.type !== 'TICKET') { return; } if (!$ticket.length) { - $ticket = Support.makeTicket($div, common, content, function () { + $ticket = APP.support.makeTicket($div, content, function () { var error = false; hashesById[id].forEach(function (d) { common.mailbox.dismiss(d, function (err) { @@ -126,7 +126,7 @@ define([ if (!error) { $ticket.remove(); } }); } - $ticket.append(Support.makeMessage(common, content, hash, false)); + $ticket.append(APP.support.makeMessage(content, hash)); } }); return $div; @@ -137,7 +137,7 @@ define([ var key = 'form'; var $div = makeBlock(key, true); - var form = Support.makeForm(); + var form = APP.support.makeForm(); $div.find('button').before(form); @@ -147,7 +147,7 @@ define([ var metadataMgr = common.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); var user = metadataMgr.getUserData(); - var sent = Support.sendForm(common, id, form, { + var sent = APP.support.sendForm(id, form, { channel: privateData.support, curvePublic: user.curvePublic }); @@ -244,6 +244,7 @@ define([ APP.origin = privateData.origin; APP.readOnly = privateData.readOnly; + APP.support = Support.create(common, false); // Content var $rightside = APP.$rightside; diff --git a/www/support/ui.js b/www/support/ui.js index ef91c56a1..903a86167 100644 --- a/www/support/ui.js +++ b/www/support/ui.js @@ -8,7 +8,8 @@ define([ '/customize/messages.js', ], function ($, ApiConfig, h, UI, Hash, Util, Messages) { - var send = function (common, id, type, data, dest) { + var send = function (ctx, id, type, data, dest) { + var common = ctx.common; var supportKey = ApiConfig.supportMailbox; var supportChannel = Hash.getChannelIdFromKey(supportKey); var metadataMgr = common.getMetadataMgr(); @@ -38,7 +39,7 @@ define([ }); }; - var sendForm = function (common, id, form, dest) { + var sendForm = function (ctx, id, form, dest) { var $title = $(form).find('.cp-support-form-title'); var $content = $(form).find('.cp-support-form-msg'); @@ -53,7 +54,7 @@ define([ $content.val(''); $title.val(''); - send(common, id, 'TICKET', { + send(ctx, id, 'TICKET', { title: title, message: content, }, dest); @@ -97,7 +98,7 @@ define([ return form; }; - var makeTicket = function ($div, common, content, onHide) { + var makeTicket = function (ctx, $div, content, onHide) { var ticketTitle = content.title + ' (#' + content.id + ')'; var answer = h('button.btn.btn-primary.cp-support-answer', Messages.support_answer); var close = h('button.btn.btn-danger.cp-support-close', Messages.support_close); @@ -117,7 +118,7 @@ define([ ])); $(close).click(function () { - send(common, content.id, 'CLOSE', {}, content.sender); + send(ctx, content.id, 'CLOSE', {}, content.sender); }); $(hide).click(function () { @@ -129,7 +130,7 @@ define([ $ticket.find('.cp-support-form-container').remove(); $(actions).hide(); var form = makeForm(function () { - var sent = sendForm(common, content.id, form, content.sender); + var sent = sendForm(ctx, content.id, form, content.sender); if (sent) { $(actions).show(); $(form).remove(); @@ -142,7 +143,9 @@ define([ return $ticket; }; - var makeMessage = function (common, content, hash, isAdmin) { + var makeMessage = function (ctx, content, hash) { + var common = ctx.common; + var isAdmin = ctx.isAdmin; var metadataMgr = common.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); @@ -169,7 +172,8 @@ define([ ]); }; - var makeCloseMessage = function (common, content, hash) { + var makeCloseMessage = function (ctx, content, hash) { + var common = ctx.common; var metadataMgr = common.getMetadataMgr(); var privateData = metadataMgr.getPrivateData(); var fromMe = content.sender && content.sender.edPublic === privateData.edPublic; @@ -185,11 +189,30 @@ define([ ]); }; + var create = function (common, isAdmin) { + var ui = {}; + var ctx = { + common: common, + isAdmin: isAdmin + }; + + ui.sendForm = function (id, form, dest) { + return sendForm(ctx, id, form, dest); + }; + ui.makeForm = makeForm; + ui.makeTicket = function ($div, content, onHide) { + return makeTicket(ctx, $div, content, onHide); + }; + ui.makeMessage = function (content, hash) { + return makeMessage(ctx, content, hash); + }; + ui.makeCloseMessage = function (content, hash) { + return makeCloseMessage(ctx, content, hash); + }; + return ui; + }; + return { - sendForm: sendForm, - makeForm: makeForm, - makeTicket: makeTicket, - makeMessage: makeMessage, - makeCloseMessage: makeCloseMessage + create: create }; });