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 '#FF00C0', // hot pink
'#800080', // purple '#800080', // purple
]; ];
config.enableTemplates = true;
return config; return config;
}); });

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

@ -219,7 +219,8 @@ define([
// Categories dislayed in the menu // Categories dislayed in the menu
// _WORKGROUP_ : do not display unsorted // _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]; } if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; }
var lastSelectTime; var lastSelectTime;

@ -3,6 +3,7 @@ define([
'/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-listmap/chainpad-listmap.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/cryptget.js',
'/bower_components/hyperjson/hyperjson.js', '/bower_components/hyperjson/hyperjson.js',
'render.js', 'render.js',
'/common/toolbar.js', '/common/toolbar.js',
@ -10,7 +11,7 @@ define([
'/common/notify.js', '/common/notify.js',
'/bower_components/file-saver/FileSaver.min.js', '/bower_components/file-saver/FileSaver.min.js',
'/bower_components/jquery/dist/jquery.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 $ = window.jQuery;
var Messages = Cryptpad.Messages; var Messages = Cryptpad.Messages;
@ -525,6 +526,11 @@ define([
debug('userid: %s', userid); debug('userid: %s', userid);
var proxy = APP.proxy; var proxy = APP.proxy;
var isNew = false;
var userDoc = JSON.stringify(proxy);
if (userDoc === "" || userDoc === "{}") { isNew = true; }
var uncommitted = APP.uncommitted = {}; var uncommitted = APP.uncommitted = {};
prepareProxy(proxy, copyObject(Render.Example)); prepareProxy(proxy, copyObject(Render.Example));
prepareProxy(uncommitted, copyObject(Render.Example)); prepareProxy(uncommitted, copyObject(Render.Example));
@ -676,6 +682,9 @@ define([
addToUserData(myData); addToUserData(myData);
APP.$userNameButton.click(); APP.$userNameButton.click();
} }
if (isNew) {
Cryptpad.selectTemplate('poll', info.realtime, Cryptget);
}
}); });
}; };
@ -747,6 +756,17 @@ define([
// set the hash // set the hash
if (!readOnly) { Cryptpad.replaceHash(editHash); } 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.onDisplayNameChanged(setName);
Cryptpad.getPadTitle(function (err, title) { Cryptpad.getPadTitle(function (err, title) {

@ -11,13 +11,14 @@ define([
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/cryptget.js',
'/common/visible.js', '/common/visible.js',
'/common/notify.js', '/common/notify.js',
'/customize/application_config.js', '/customize/application_config.js',
'/bower_components/secure-fabric.js/dist/fabric.min.js', '/bower_components/secure-fabric.js/dist/fabric.min.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
'/bower_components/file-saver/FileSaver.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 saveAs = window.saveAs;
var Messages = Cryptpad.Messages; var Messages = Cryptpad.Messages;
@ -330,6 +331,17 @@ define([
var $rightside = $bar.find('.' + Toolbar.constants.rightside); var $rightside = $bar.find('.' + Toolbar.constants.rightside);
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername)); 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); var $export = Cryptpad.createButton('export', true, {}, saveImage);
$rightside.append($export); $rightside.append($export);
@ -501,6 +513,10 @@ define([
realtime: realtime realtime: realtime
}); });
var isNew = false;
var userDoc = module.realtime.getUserDoc();
if (userDoc === "" || userDoc === "{}") { isNew = true; }
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();
setEditable(true); setEditable(true);
initializing = false; initializing = false;
@ -531,6 +547,9 @@ define([
onLocal(); onLocal();
module.$userNameButton.click(); module.$userNameButton.click();
} }
if (isNew) {
Cryptpad.selectTemplate('whiteboard', info.realtime, Cryptget);
}
}); });
}; };

Loading…
Cancel
Save