Preview instance broadcast before sending

pull/1/head
yflory 4 years ago
parent fee8a88169
commit c38ba1936e

@ -223,6 +223,9 @@
margin-right: 20px; margin-right: 20px;
} }
} }
.cp-broadcast-preview {
vertical-align: bottom !important;
}
} }
} }

@ -973,10 +973,36 @@ define([
UI.log(Messages.saved); UI.log(Messages.saved);
}); });
}; };
$button.click(function () { $button.click(function () {
send(); 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') { if (key === 'custom') {
(function () { (function () {
var container = h('div.cp-broadcast-container'); var container = h('div.cp-broadcast-container');
@ -984,10 +1010,6 @@ define([
var languages = Messages._languages; var languages = Messages._languages;
var keys = Object.keys(languages).sort(); var keys = Object.keys(languages).sort();
var onPreview = function (l) {
// XXX
};
var reorder = function () { var reorder = function () {
$container.find('.cp-broadcast-lang').each(function (i, el) { $container.find('.cp-broadcast-lang').each(function (i, el) {
var $el = $(el); var $el = $(el);
@ -1117,7 +1139,8 @@ define([
h('label', Messages.broadcast_end), h('label', Messages.broadcast_end),
end, end,
h('br'), h('br'),
button button,
preview
]); ]);
})(); })();
return; return;
@ -1139,7 +1162,8 @@ define([
$form.append([ $form.append([
$cbox[0], $cbox[0],
h('br'), h('br'),
button button,
preview
]); ]);
})(); })();
return; return;
@ -1166,7 +1190,8 @@ define([
label, label,
input, input,
h('br'), h('br'),
button button,
preview
]); ]);
})(); })();
return; return;

@ -454,8 +454,9 @@ define([
var msg = content.msg.content; var msg = content.msg.content;
var text = msg.content; var text = msg.content;
var defaultL = msg.defaultLanguage; var defaultL = msg.defaultLanguage;
var myLang = data.lang || Messages._languageUsed;
// Check if our language is available // Check if our language is available
var toShow = text[Messages._languageUsed]; var toShow = text[myLang];
// Otherwise, fallback to the default language if it exists // Otherwise, fallback to the default language if it exists
if (!toShow && defaultL) { toShow = text[defaultL]; } if (!toShow && defaultL) { toShow = text[defaultL]; }
// No translation available, dismiss // No translation available, dismiss

@ -142,7 +142,7 @@ define([
removeFromHistory(data.type, data.hash); 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'} } // data = { type: 'type', content: {msg: 'msg', hash: 'hash'} }
pushMessage(data); pushMessage(data);
if (data.content && typeof (data.content.getFormatText) === "function") { if (data.content && typeof (data.content.getFormatText) === "function") {
@ -160,6 +160,11 @@ define([
hash: data.content.hash, hash: data.content.hash,
type: data.type type: data.type
}; };
if (/^LOCAL|/.test(dataObj.hash)) {
onViewed(dataObj);
cb();
return;
}
execCommand('DISMISS', dataObj, function (obj) { execCommand('DISMISS', dataObj, function (obj) {
if (obj && obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }
onViewed(dataObj); onViewed(dataObj);

Loading…
Cancel
Save