Clean the support UI code

pull/1/head
yflory 6 years ago
parent 8193a1997c
commit f111be72e6

@ -199,13 +199,13 @@ define([
// A ticket has been closed by the admins... // A ticket has been closed by the admins...
if (!$ticket.length) { return; } if (!$ticket.length) { return; }
$ticket.addClass('cp-support-list-closed'); $ticket.addClass('cp-support-list-closed');
$ticket.append(Support.makeCloseMessage(common, content, hash)); $ticket.append(APP.support.makeCloseMessage(content, hash));
return; return;
} }
if (msg.type !== 'TICKET') { return; } if (msg.type !== 'TICKET') { return; }
if (!$ticket.length) { if (!$ticket.length) {
$ticket = Support.makeTicket($div, common, content, function () { $ticket = APP.support.makeTicket($div, content, function () {
var error = false; var error = false;
hashesById[id].forEach(function (d) { hashesById[id].forEach(function (d) {
common.mailbox.dismiss(d, function (err) { common.mailbox.dismiss(d, function (err) {
@ -218,7 +218,7 @@ define([
if (!error) { $ticket.remove(); } if (!error) { $ticket.remove(); }
}); });
} }
$ticket.append(Support.makeMessage(common, content, hash, true)); $ticket.append(APP.support.makeMessage(content, hash));
} }
}); });
return $div; return $div;
@ -349,6 +349,7 @@ define([
APP.privateKey = privateData.supportPrivateKey; APP.privateKey = privateData.supportPrivateKey;
APP.origin = privateData.origin; APP.origin = privateData.origin;
APP.readOnly = privateData.readOnly; APP.readOnly = privateData.readOnly;
APP.support = Support.create(common, true);
// Content // Content
var $rightside = APP.$rightside; var $rightside = APP.$rightside;

@ -107,13 +107,13 @@ define([
// A ticket has been closed by the admins... // A ticket has been closed by the admins...
if (!$ticket.length) { return; } if (!$ticket.length) { return; }
$ticket.addClass('cp-support-list-closed'); $ticket.addClass('cp-support-list-closed');
$ticket.append(Support.makeCloseMessage(common, content, hash)); $ticket.append(APP.support.makeCloseMessage(content, hash));
return; return;
} }
if (msg.type !== 'TICKET') { return; } if (msg.type !== 'TICKET') { return; }
if (!$ticket.length) { if (!$ticket.length) {
$ticket = Support.makeTicket($div, common, content, function () { $ticket = APP.support.makeTicket($div, content, function () {
var error = false; var error = false;
hashesById[id].forEach(function (d) { hashesById[id].forEach(function (d) {
common.mailbox.dismiss(d, function (err) { common.mailbox.dismiss(d, function (err) {
@ -126,7 +126,7 @@ define([
if (!error) { $ticket.remove(); } if (!error) { $ticket.remove(); }
}); });
} }
$ticket.append(Support.makeMessage(common, content, hash, false)); $ticket.append(APP.support.makeMessage(content, hash));
} }
}); });
return $div; return $div;
@ -137,7 +137,7 @@ define([
var key = 'form'; var key = 'form';
var $div = makeBlock(key, true); var $div = makeBlock(key, true);
var form = Support.makeForm(); var form = APP.support.makeForm();
$div.find('button').before(form); $div.find('button').before(form);
@ -147,7 +147,7 @@ define([
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var user = metadataMgr.getUserData(); var user = metadataMgr.getUserData();
var sent = Support.sendForm(common, id, form, { var sent = APP.support.sendForm(id, form, {
channel: privateData.support, channel: privateData.support,
curvePublic: user.curvePublic curvePublic: user.curvePublic
}); });
@ -244,6 +244,7 @@ define([
APP.origin = privateData.origin; APP.origin = privateData.origin;
APP.readOnly = privateData.readOnly; APP.readOnly = privateData.readOnly;
APP.support = Support.create(common, false);
// Content // Content
var $rightside = APP.$rightside; var $rightside = APP.$rightside;

@ -8,7 +8,8 @@ define([
'/customize/messages.js', '/customize/messages.js',
], function ($, ApiConfig, h, UI, Hash, Util, Messages) { ], 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 supportKey = ApiConfig.supportMailbox;
var supportChannel = Hash.getChannelIdFromKey(supportKey); var supportChannel = Hash.getChannelIdFromKey(supportKey);
var metadataMgr = common.getMetadataMgr(); 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 $title = $(form).find('.cp-support-form-title');
var $content = $(form).find('.cp-support-form-msg'); var $content = $(form).find('.cp-support-form-msg');
@ -53,7 +54,7 @@ define([
$content.val(''); $content.val('');
$title.val(''); $title.val('');
send(common, id, 'TICKET', { send(ctx, id, 'TICKET', {
title: title, title: title,
message: content, message: content,
}, dest); }, dest);
@ -97,7 +98,7 @@ define([
return form; return form;
}; };
var makeTicket = function ($div, common, content, onHide) { var makeTicket = function (ctx, $div, content, onHide) {
var ticketTitle = content.title + ' (#' + content.id + ')'; var ticketTitle = content.title + ' (#' + content.id + ')';
var answer = h('button.btn.btn-primary.cp-support-answer', Messages.support_answer); 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); var close = h('button.btn.btn-danger.cp-support-close', Messages.support_close);
@ -117,7 +118,7 @@ define([
])); ]));
$(close).click(function () { $(close).click(function () {
send(common, content.id, 'CLOSE', {}, content.sender); send(ctx, content.id, 'CLOSE', {}, content.sender);
}); });
$(hide).click(function () { $(hide).click(function () {
@ -129,7 +130,7 @@ define([
$ticket.find('.cp-support-form-container').remove(); $ticket.find('.cp-support-form-container').remove();
$(actions).hide(); $(actions).hide();
var form = makeForm(function () { var form = makeForm(function () {
var sent = sendForm(common, content.id, form, content.sender); var sent = sendForm(ctx, content.id, form, content.sender);
if (sent) { if (sent) {
$(actions).show(); $(actions).show();
$(form).remove(); $(form).remove();
@ -142,7 +143,9 @@ define([
return $ticket; 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 metadataMgr = common.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); 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 metadataMgr = common.getMetadataMgr();
var privateData = metadataMgr.getPrivateData(); var privateData = metadataMgr.getPrivateData();
var fromMe = content.sender && content.sender.edPublic === privateData.edPublic; 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 { return {
sendForm: sendForm, create: create
makeForm: makeForm,
makeTicket: makeTicket,
makeMessage: makeMessage,
makeCloseMessage: makeCloseMessage
}; };
}); });

Loading…
Cancel
Save