new frontend API - getCurrentNoteContent and onNoteChange

This commit is contained in:
azivner
2018-09-03 16:05:28 +02:00
parent a3feaa13b3
commit c7a609e349
42 changed files with 817 additions and 106 deletions

View File

@@ -49,6 +49,10 @@ const components = {
};
function getComponent(type) {
if (!type) {
type = getCurrentNote().type;
}
if (components[type]) {
return components[type];
}
@@ -93,11 +97,19 @@ async function switchToNote(noteId) {
}
}
function getCurrentNoteContent() {
return getComponent().getContent();
}
function onNoteChange(func) {
return getComponent().onNoteChange(func);
}
async function saveNote() {
const note = getCurrentNote();
note.title = $noteTitle.val();
note.content = getComponent(note.type).getContent();
note.content = getCurrentNoteContent(note);
// it's important to set the flag back to false immediatelly after retrieving title and content
// otherwise we might overwrite another change (especially async code)
@@ -107,7 +119,6 @@ async function saveNote() {
await server.put('notes/' + note.noteId, note.dto);
if (note.isProtected) {
protectedSessionHolder.touchProtectedSession();
}
@@ -549,5 +560,7 @@ export default {
refreshAttributes,
saveNote,
saveNoteIfChanged,
noteChanged
noteChanged,
getCurrentNoteContent,
onNoteChange
};