Merge branch 'master' into ckeditor

This commit is contained in:
azivner
2017-12-09 11:56:36 -05:00
34 changed files with 504 additions and 136 deletions

View File

@@ -19,7 +19,7 @@ const contextMenu = (function() {
// just do nothing
}
else {
throw new Error("Unrecognized clipboard mode=" + clipboardMode);
throwError("Unrecognized clipboard mode=" + clipboardMode);
}
clipboardId = null;
@@ -36,7 +36,7 @@ const contextMenu = (function() {
treeChanges.cloneNoteTo(clipboardId, node.data.note_id);
}
else {
throw new Error("Unrecognized clipboard mode=" + mode);
throwError("Unrecognized clipboard mode=" + mode);
}
clipboardId = null;

View File

@@ -27,7 +27,7 @@ const noteHistory = (function() {
historyItems = await server.get('notes-history/' + noteId);
for (const item of historyItems) {
const dateModified = getDateFromTS(item.date_modified_to);
const dateModified = getDateFromTS(item.date_modified_from);
$("#note-history-list").append($('<option>', {
value: item.note_history_id,

View File

@@ -4,7 +4,7 @@ const messaging = (function() {
let ws = null;
function logError(message) {
console.error(message);
console.trace(message);
if (ws && ws.readyState === 1) {
ws.send(JSON.stringify({

View File

@@ -4,7 +4,7 @@ const noteTree = (function() {
const treeEl = $("#tree");
const parentListEl = $("#parent-list");
let startNoteTreeId = null;
let startNotePath = null;
let notesTreeMap = {};
let parentToChildren = {};
@@ -25,7 +25,7 @@ const noteTree = (function() {
let title = noteIdToTitle[noteId];
if (!title) {
throw new Error("Can't find title for noteId='" + noteId + "'");
throwError("Can't find title for noteId='" + noteId + "'");
}
if (parentNoteId !== null) {
@@ -265,7 +265,7 @@ const noteTree = (function() {
const parents = childToParents[noteId];
if (!parents) {
throw new Error("Can't find parents for noteId=" + noteId);
throwError("Can't find parents for noteId=" + noteId);
}
if (parents.length <= 1) {
@@ -278,7 +278,9 @@ const noteTree = (function() {
const list = $("<ul/>");
for (const parentNoteId of parents) {
const notePath = getSomeNotePath(parentNoteId) + '/' + noteId;
const parentNotePath = getSomeNotePath(parentNoteId);
// this is to avoid having root notes leading '/'
const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId;
const title = getNotePathTitle(notePath);
let item;
@@ -303,6 +305,8 @@ const noteTree = (function() {
let parentNoteId = 'root';
for (const noteId of notePath.split('/')) {
console.log('noteId: ' + noteId);
titlePath.push(getNoteTitle(noteId, parentNoteId));
parentNoteId = noteId;
@@ -403,8 +407,8 @@ const noteTree = (function() {
setExpandedToServer(data.node.data.note_tree_id, false);
},
init: (event, data) => {
if (startNoteTreeId) {
activateNode(startNoteTreeId);
if (startNotePath) {
activateNode(startNotePath);
}
else {
showAppIfHidden();
@@ -494,10 +498,10 @@ const noteTree = (function() {
function loadTree() {
return server.get('tree').then(resp => {
startNoteTreeId = resp.start_note_tree_id;
startNotePath = resp.start_note_path;
if (document.location.hash) {
startNoteTreeId = document.location.hash.substr(1); // strip initial #
startNotePath = document.location.hash.substr(1); // strip initial #
}
return prepareNoteTree(resp.notes, resp.notes_parent);

View File

@@ -0,0 +1,34 @@
$("#setup-form").submit(() => {
const username = $("#username").val();
const password1 = $("#password1").val();
const password2 = $("#password2").val();
if (!username) {
showAlert("Username can't be empty");
return false;
}
if (!password1) {
showAlert("Password can't be empty");
return false;
}
if (password1 !== password2) {
showAlert("Both password fields need be identical.");
return false;
}
server.post('setup', {
username: username,
password: password1
}).then(() => {
window.location.replace("/");
});
return false;
});
function showAlert(message) {
$("#alert").html(message);
$("#alert").show();
}

View File

@@ -30,6 +30,12 @@ function showError(message) {
});
}
function throwError(message) {
messaging.logError(message);
throw new Error(message);
}
function getDateFromTS(timestamp) {
// Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling
// see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript