Add templates to pad2

pull/1/head
yflory 7 years ago
parent 8d020833af
commit f40d2c0b20

@ -1061,6 +1061,19 @@ define([
}
});
};
var saveAsTemplate = common.saveAsTemplate = function (Cryptput, data, cb) {
var p = parsePadUrl(window.location.href);
if (!p.type) { return; }
var hash = createRandomHash();
var href = '/' + p.type + '/#' + hash;
Cryptput(hash, data.toSave, function (e) {
if (e) { throw new Error(e); }
common.addTemplate(makePad(href, data.title));
whenRealtimeSyncs(getStore().getProxy().info.realtime, function () {
cb();
});
});
};
common.createButton = function (type, rightside, data, callback) {
var button;
var size = "17px";
@ -1149,17 +1162,12 @@ define([
console.error("Parse error while setting the title", e);
}
}
var p = parsePadUrl(window.location.href);
if (!p.type) { return; }
var hash = createRandomHash();
var href = '/' + p.type + '/#' + hash;
data.Crypt.put(hash, toSave, function (e) {
if (e) { throw new Error(e); }
common.addTemplate(makePad(href, title));
whenRealtimeSyncs(getStore().getProxy().info.realtime, function () {
common.alert(Messages.templateSaved);
common.feedback('TEMPLATE_CREATED');
});
saveAsTemplate(data.Crypt.put, {
title: title,
toSave: toSave
}, function () {
common.alert(Messages.templateSaved);
common.feedback('TEMPLATE_CREATED');
});
};
common.prompt(Messages.saveTemplatePrompt, title || document.title, todo);

@ -32,6 +32,8 @@ define([], function () {
};
metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
}
if (!metadataObj.users) { metadataObj.users = {}; }
if (!metadataLazyObj.users) { metadataLazyObj.users = {}; }
var mdo = {};
// We don't want to add our user data to the object multiple times.
//var containsYou = false;

@ -138,11 +138,11 @@ define([
}
break;
case 'template':
if (!AppConfig.enableTemplates) { return; }
//if (!AppConfig.enableTemplates) { return; }
button = $('<button>', {
title: Messages.saveTemplateButton,
}).append($('<span>', {'class':'fa fa-bookmark', style: 'font:'+size+' FontAwesome'}));
if (data.rt && data.Crypt) {
if (data.rt) {
button
.click(function () {
var title = data.getTitle() || document.title;
@ -172,20 +172,15 @@ define([
console.error("Parse error while setting the title", e);
}
}
var p = parsePadUrl(window.location.href);
if (!p.type) { return; }
var hash = createRandomHash();
var href = '/' + p.type + '/#' + hash;
data.Crypt.put(hash, toSave, function (e) {
if (e) { throw new Error(e); }
common.addTemplate(makePad(href, title));
whenRealtimeSyncs(getStore().getProxy().info.realtime, function () {
common.alert(Messages.templateSaved);
common.feedback('TEMPLATE_CREATED');
});
ctx.sframeChan.query('Q_SAVE_AS_TEMPLATE', {
title: title,
toSave: toSave
}, function () {
Cryptpad.alert(Messages.templateSaved);
funcs.feedback('TEMPLATE_CREATED');
});
};
common.prompt(Messages.saveTemplatePrompt, title || document.title, todo);
Cryptpad.prompt(Messages.saveTemplatePrompt, title, todo);
});
}
break;

@ -69,5 +69,9 @@ define({
// Callback is called when the FULL_HISTORY_END message is received in the outside.
'Q_GET_FULL_HISTORY': true,
// When a (full) history message is received from the server.
'EV_RT_HIST_MESSAGE': true
'EV_RT_HIST_MESSAGE': true,
// Save a pad as a template using the toolbar button
'Q_SAVE_AS_TEMPLATE': true,
});

@ -539,6 +539,15 @@ define([
var $hist = common.createButton('history', true, {histConfig: histConfig});
$drawer.append($hist);
//if (!Cryptpad.isTemplate(window.location.href)) {
var templateObj = {
rt: info.realtime,
getTitle: function () { return metadataMgr.getMetadata().title; }
};
var $templateButton = common.createButton('template', true, templateObj);
$rightside.append($templateButton);
//}
/* add an export button */
var $export = Cryptpad.createButton('export', true, {}, exportFile);
$drawer.append($export);
@ -641,7 +650,7 @@ define([
}*/
/* add a history button */
var histConfig = {
/*var histConfig = {
onLocal: realtimeOptions.onLocal,
onRemote: realtimeOptions.onRemote,
setHistory: setHistory,
@ -650,7 +659,7 @@ define([
};
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$drawer.append($hist);
*/
/* save as template */
if (!Cryptpad.isTemplate(window.location.href)) {
var templateObj = {

@ -1,8 +1,9 @@
define([
'/api/config',
'jquery',
'/common/requireconfig.js'
], function (ApiConfig, $, RequireConfig) {
'/common/requireconfig.js',
'/common/cryptget.js'
], function (ApiConfig, $, RequireConfig, Cryptget) {
$(function () {
var req = {
cfg: RequireConfig,
@ -136,6 +137,11 @@ define([
Cryptpad.moveToTrash(cb);
});
sframeChan.on('Q_SAVE_AS_TEMPLATE', function (data, cb) {
Cryptpad.saveAsTemplate(Cryptget.put, data, cb);
});
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
var network = Cryptpad.getNetwork();
var hkn = network.historyKeeper;

Loading…
Cancel
Save