Templates in polls and canvas, and ability to disable templates

pull/1/head
yflory 8 years ago
parent 84d8615cf1
commit bd16e0f0e7

@ -30,6 +30,7 @@ define(function() {
'#FF00C0', // hot pink
'#800080', // purple
];
config.enableTemplates = true;
return config;
});

@ -572,12 +572,15 @@ define([
});
};
var selectTemplate = common.selectTemplate = function (type, rt, Crypt) {
if (!AppConfig.enableTemplates) { return; }
var temps = listTemplates(type);
if (temps.length === 0) { return; }
var $content = $('<div>');
$('<b>').text(Messages.selectTemplate).appendTo($content);
$('<p>', {id:"selectTemplate"}).appendTo($content);
Cryptpad.alert($content.html(), null, true);
var $p = $('#selectTemplate');
listTemplates(type).forEach(function (t) {
temps.forEach(function (t, i) {
$('<a>', {href: t.href, title: t.title}).text(t.title).click(function (e) {
e.preventDefault();
var parsed = parsePadUrl(t.href);
@ -592,6 +595,7 @@ define([
});
});
}).appendTo($p);
if (i !== temps.length) { $('<br>').appendTo($p); }
});
common.findOKButton().text(Messages.cancelButton);
};
@ -1101,6 +1105,7 @@ define([
}
break;
case 'template':
if (!AppConfig.enableTemplates) { return; }
button = $('<button>', {
title: Messages.saveTemplateButton,
}).append($('<span>', {'class':'fa fa-bookmark', style: 'font:'+size+' FontAwesome'}));
@ -1117,8 +1122,10 @@ define([
var parsed = JSON.parse(toSave);
var meta;
if (Array.isArray(parsed) && typeof(parsed[3]) === "object") {
meta = parsed[3].metadata;
} else {
meta = parsed[3].metadata; // pad
} else if (parsed.info) {
meta = parsed.info; // poll
} else {
meta = parsed.metadata;
}
if (typeof(meta) === "object") {

@ -219,7 +219,8 @@ define([
// Categories dislayed in the menu
// _WORKGROUP_ : do not display unsorted
var displayedCategories = [ROOT, UNSORTED, TRASH, SEARCH, TEMPLATE];
var displayedCategories = [ROOT, UNSORTED, TRASH, SEARCH];
if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); }
if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; }
var lastSelectTime;

@ -3,6 +3,7 @@ define([
'/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad-crypto/crypto.js',
'/common/cryptpad-common.js',
'/common/cryptget.js',
'/bower_components/hyperjson/hyperjson.js',
'render.js',
'/common/toolbar.js',
@ -10,7 +11,7 @@ define([
'/common/notify.js',
'/bower_components/file-saver/FileSaver.min.js',
'/bower_components/jquery/dist/jquery.min.js',
], function (TextPatcher, Listmap, Crypto, Cryptpad, Hyperjson, Renderer, Toolbar, Visible, Notify) {
], function (TextPatcher, Listmap, Crypto, Cryptpad, Cryptget, Hyperjson, Renderer, Toolbar, Visible, Notify) {
var $ = window.jQuery;
var Messages = Cryptpad.Messages;
@ -525,6 +526,11 @@ define([
debug('userid: %s', userid);
var proxy = APP.proxy;
var isNew = false;
var userDoc = JSON.stringify(proxy);
if (userDoc === "" || userDoc === "{}") { isNew = true; }
var uncommitted = APP.uncommitted = {};
prepareProxy(proxy, copyObject(Render.Example));
prepareProxy(uncommitted, copyObject(Render.Example));
@ -676,6 +682,9 @@ define([
addToUserData(myData);
APP.$userNameButton.click();
}
if (isNew) {
Cryptpad.selectTemplate('poll', info.realtime, Cryptget);
}
});
};
@ -747,6 +756,17 @@ define([
// set the hash
if (!readOnly) { Cryptpad.replaceHash(editHash); }
/* save as template */
if (!Cryptpad.isTemplate(window.location.href)) {
var templateObj = {
rt: info.realtime,
Crypt: Cryptget,
getTitle: function () { return document.title; }
};
var $templateButton = Cryptpad.createButton('template', true, templateObj);
$rightside.append($templateButton);
}
Cryptpad.onDisplayNameChanged(setName);
Cryptpad.getPadTitle(function (err, title) {

@ -11,13 +11,14 @@ define([
'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/common/cryptget.js',
'/common/visible.js',
'/common/notify.js',
'/customize/application_config.js',
'/bower_components/secure-fabric.js/dist/fabric.min.js',
'/bower_components/jquery/dist/jquery.min.js',
'/bower_components/file-saver/FileSaver.min.js',
], function (Config, Realtime, Crypto, Toolbar, TextPatcher, JSONSortify, JsonOT, Cryptpad, Visible, Notify, AppConfig) {
], function (Config, Realtime, Crypto, Toolbar, TextPatcher, JSONSortify, JsonOT, Cryptpad, Cryptget, Visible, Notify, AppConfig) {
var saveAs = window.saveAs;
var Messages = Cryptpad.Messages;
@ -330,6 +331,17 @@ define([
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
/* save as template */
if (!Cryptpad.isTemplate(window.location.href)) {
var templateObj = {
rt: info.realtime,
Crypt: Cryptget,
getTitle: function () { return document.title; }
};
var $templateButton = Cryptpad.createButton('template', true, templateObj);
$rightside.append($templateButton);
}
var $export = Cryptpad.createButton('export', true, {}, saveImage);
$rightside.append($export);
@ -501,6 +513,10 @@ define([
realtime: realtime
});
var isNew = false;
var userDoc = module.realtime.getUserDoc();
if (userDoc === "" || userDoc === "{}") { isNew = true; }
Cryptpad.removeLoadingScreen();
setEditable(true);
initializing = false;
@ -531,6 +547,9 @@ define([
onLocal();
module.$userNameButton.click();
}
if (isNew) {
Cryptpad.selectTemplate('whiteboard', info.realtime, Cryptget);
}
});
};

Loading…
Cancel
Save