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

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

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

@ -69,5 +69,9 @@ define({
// Callback is called when the FULL_HISTORY_END message is received in the outside. // Callback is called when the FULL_HISTORY_END message is received in the outside.
'Q_GET_FULL_HISTORY': true, 'Q_GET_FULL_HISTORY': true,
// When a (full) history message is received from the server. // 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}); var $hist = common.createButton('history', true, {histConfig: histConfig});
$drawer.append($hist); $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 */ /* add an export button */
var $export = Cryptpad.createButton('export', true, {}, exportFile); var $export = Cryptpad.createButton('export', true, {}, exportFile);
$drawer.append($export); $drawer.append($export);
@ -641,7 +650,7 @@ define([
}*/ }*/
/* add a history button */ /* add a history button */
var histConfig = { /*var histConfig = {
onLocal: realtimeOptions.onLocal, onLocal: realtimeOptions.onLocal,
onRemote: realtimeOptions.onRemote, onRemote: realtimeOptions.onRemote,
setHistory: setHistory, setHistory: setHistory,
@ -650,7 +659,7 @@ define([
}; };
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$drawer.append($hist); $drawer.append($hist);
*/
/* save as template */ /* save as template */
if (!Cryptpad.isTemplate(window.location.href)) { if (!Cryptpad.isTemplate(window.location.href)) {
var templateObj = { var templateObj = {

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

Loading…
Cancel
Save