Ask the user before loading the template picker

This commit is contained in:
yflory
2017-09-08 16:21:12 +02:00
parent 684a12ce2e
commit fc069dac48
5 changed files with 37 additions and 19 deletions

View File

@@ -442,27 +442,37 @@ define([
UI.openTemplatePicker = function (common) {
var metadataMgr = common.getMetadataMgr();
var type = metadataMgr.getMetadataLazy().type;
var first = true; // We can only pick a template once (for a new document)
var fileDialogCfg = {
onSelect: function (data) {
if (data.type === type && first) {
Cryptpad.addLoadingScreen({hideTips: true});
var sframeChan = common.getSframeChannel();
sframeChan.query('Q_TEMPLATE_USE', data.href, function () {
first = false;
Cryptpad.removeLoadingScreen();
common.feedback('TEMPLATE_USED');
});
return;
var sframeChan = common.getSframeChannel();
var onConfirm = function (yes) {
if (!yes) { return; }
var first = true; // We can only pick a template once (for a new document)
var fileDialogCfg = {
onSelect: function (data) {
if (data.type === type && first) {
Cryptpad.addLoadingScreen({hideTips: true});
sframeChan.query('Q_TEMPLATE_USE', data.href, function () {
first = false;
Cryptpad.removeLoadingScreen();
common.feedback('TEMPLATE_USED');
});
return;
}
}
};
common.initFilePicker(fileDialogCfg);
var pickerCfg = {
types: [type],
where: ['template']
};
common.openFilePicker(pickerCfg);
};
sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) {
if (data) {
Cryptpad.confirm(Messages.useTemplate, onConfirm);
}
};
common.initFilePicker(common, fileDialogCfg);
var pickerCfg = {
types: [type],
where: ['template']
};
common.openFilePicker(common, pickerCfg);
});
};
return UI;