From c38ba1936e0222feb80176cd2d0ff74c0644aafd Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 10 Mar 2021 13:02:36 +0100 Subject: [PATCH] Preview instance broadcast before sending --- www/admin/app-admin.less | 3 +++ www/admin/inner.js | 39 +++++++++++++++++++++++------ www/common/notifications.js | 3 ++- www/common/sframe-common-mailbox.js | 7 +++++- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/www/admin/app-admin.less b/www/admin/app-admin.less index 64f977eca..2875c0a27 100644 --- a/www/admin/app-admin.less +++ b/www/admin/app-admin.less @@ -223,6 +223,9 @@ margin-right: 20px; } } + .cp-broadcast-preview { + vertical-align: bottom !important; + } } } diff --git a/www/admin/inner.js b/www/admin/inner.js index 7d260e681..b6d1988e5 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -973,10 +973,36 @@ define([ UI.log(Messages.saved); }); }; + $button.click(function () { send(); }); + var onPreview = function (l) { + var data = getData(); + if (data === false) { return void UI.warn(Messages.error); } + var msg = { + uid: Util.uid(), + type: 'BROADCAST_'+key.toUpperCase(), + content: data + }; + common.mailbox.onMessage({ + lang: l, + type: 'broadcast', + content: { + msg: msg, + hash: 'LOCAL|' + JSON.stringify(msg).slice(0,58) + } + }, function () { + UI.log(Messages.saved); + }); + }; + var preview = h('button.cp-broadcast-preview.btn.btn-secondary', Messages.share_linkOpen); + $(preview).click(function () { + onPreview(); + }); + + if (key === 'custom') { (function () { var container = h('div.cp-broadcast-container'); @@ -984,10 +1010,6 @@ define([ var languages = Messages._languages; var keys = Object.keys(languages).sort(); - var onPreview = function (l) { -// XXX - }; - var reorder = function () { $container.find('.cp-broadcast-lang').each(function (i, el) { var $el = $(el); @@ -1117,7 +1139,8 @@ define([ h('label', Messages.broadcast_end), end, h('br'), - button + button, + preview ]); })(); return; @@ -1139,7 +1162,8 @@ define([ $form.append([ $cbox[0], h('br'), - button + button, + preview ]); })(); return; @@ -1166,7 +1190,8 @@ define([ label, input, h('br'), - button + button, + preview ]); })(); return; diff --git a/www/common/notifications.js b/www/common/notifications.js index 93da2d9b9..bc7e353da 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -454,8 +454,9 @@ define([ var msg = content.msg.content; var text = msg.content; var defaultL = msg.defaultLanguage; + var myLang = data.lang || Messages._languageUsed; // Check if our language is available - var toShow = text[Messages._languageUsed]; + var toShow = text[myLang]; // Otherwise, fallback to the default language if it exists if (!toShow && defaultL) { toShow = text[defaultL]; } // No translation available, dismiss diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index 5f35b5a2c..174777449 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -142,7 +142,7 @@ define([ removeFromHistory(data.type, data.hash); }; - var onMessage = function (data, cb) { + var onMessage = mailbox.onMessage = function (data, cb) { // data = { type: 'type', content: {msg: 'msg', hash: 'hash'} } pushMessage(data); if (data.content && typeof (data.content.getFormatText) === "function") { @@ -160,6 +160,11 @@ define([ hash: data.content.hash, type: data.type }; + if (/^LOCAL|/.test(dataObj.hash)) { + onViewed(dataObj); + cb(); + return; + } execCommand('DISMISS', dataObj, function (obj) { if (obj && obj.error) { return void cb(obj.error); } onViewed(dataObj);