JSON canvas initial
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// canvas-actions.js — creating a canvas from a normal page.
|
||||
//
|
||||
// The canvas view itself owns everything else (rename, delete, editing); this
|
||||
// only covers the one action that has to start from the page, since a folder
|
||||
// with no canvases has no canvas view to reach.
|
||||
//
|
||||
// Reuses openModal and postReplace from page/actions.js, which the page
|
||||
// template loads first.
|
||||
|
||||
// validCanvasName mirrors canvasNameRe in canvas.go. Checking here only buys a
|
||||
// better error message — the server rejects the same set regardless.
|
||||
function validCanvasName(name) {
|
||||
if (!name || name.length > 100) return false;
|
||||
if (name.charAt(0) === '.') return false;
|
||||
return !/[\/\\]/.test(name);
|
||||
}
|
||||
|
||||
function newCanvas() {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'text';
|
||||
input.className = 'input';
|
||||
input.placeholder = 'Canvas name';
|
||||
|
||||
openModal({
|
||||
title: 'New canvas',
|
||||
body: input,
|
||||
confirm: {
|
||||
label: 'CREATE',
|
||||
onConfirm: function () {
|
||||
var name = input.value.trim();
|
||||
if (!validCanvasName(name)) {
|
||||
alert('A canvas name cannot be empty, start with a dot, or contain a slash.');
|
||||
return;
|
||||
}
|
||||
closeModal();
|
||||
var base = window.location.pathname;
|
||||
if (base.slice(-1) !== '/') base += '/';
|
||||
var target = base + '?canvas=' + encodeURIComponent(name);
|
||||
postReplace(target + '&create=1', null, target);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user