Preview instance broadcast before sending

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

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

@ -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;

@ -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

@ -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);

Loading…
Cancel
Save