2018-03-25 11:09:17 -04:00
|
|
|
import server from './server.js';
|
2019-08-26 20:21:43 +02:00
|
|
|
import ws from "./ws.js";
|
2018-03-25 23:25:17 -04:00
|
|
|
import treeCache from "./tree_cache.js";
|
2020-02-01 11:15:58 +01:00
|
|
|
import NoteComplement from "../entities/note_full.js";
|
2020-01-12 11:15:23 +01:00
|
|
|
import appContext from "./app_context.js";
|
2019-05-05 10:59:34 +02:00
|
|
|
|
2019-05-19 09:13:13 +02:00
|
|
|
function getActiveEditor() {
|
2020-01-12 12:37:44 +01:00
|
|
|
const activeTabContext = appContext.getActiveTabContext();
|
2019-05-19 09:13:13 +02:00
|
|
|
|
|
|
|
|
if (activeTabContext && activeTabContext.note && activeTabContext.note.type === 'text') {
|
|
|
|
|
return activeTabContext.getComponent().getEditor();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-01 11:15:58 +01:00
|
|
|
async function loadNoteComplement(noteId) {
|
2018-08-29 22:28:58 +02:00
|
|
|
const row = await server.get('notes/' + noteId);
|
|
|
|
|
|
2020-02-01 11:15:58 +01:00
|
|
|
return new NoteComplement(row);
|
2018-08-29 22:28:58 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-07 10:50:05 +02:00
|
|
|
function focusOnTitle() {
|
2020-01-24 17:54:47 +01:00
|
|
|
appContext.trigger('focusOnTitle');
|
2018-08-29 22:28:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 22:46:08 +01:00
|
|
|
function focusAndSelectTitle() {
|
2020-01-24 17:54:47 +01:00
|
|
|
appContext.trigger('focusAndSelectTitle');
|
2019-01-01 19:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-12 19:59:52 +02:00
|
|
|
function noteChanged() {
|
2020-01-12 12:37:44 +01:00
|
|
|
const activeTabContext = appContext.getActiveTabContext();
|
2019-06-12 19:59:52 +02:00
|
|
|
|
|
|
|
|
if (activeTabContext) {
|
|
|
|
|
activeTabContext.noteChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-26 22:29:14 -04:00
|
|
|
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
|
|
|
|
|
// this sends the request asynchronously and doesn't wait for result
|
2020-01-19 21:40:23 +01:00
|
|
|
// FIXME
|
2020-01-19 22:05:45 +01:00
|
|
|
$(window).on('beforeunload', () => {
|
|
|
|
|
//saveNotesIfChanged();
|
|
|
|
|
});
|
2018-03-26 22:29:14 -04:00
|
|
|
|
2018-03-25 11:09:17 -04:00
|
|
|
export default {
|
2020-02-01 11:15:58 +01:00
|
|
|
loadNoteComplement,
|
2018-09-07 10:50:05 +02:00
|
|
|
focusOnTitle,
|
2019-01-10 22:46:08 +01:00
|
|
|
focusAndSelectTitle,
|
2019-05-19 09:13:13 +02:00
|
|
|
getActiveEditor,
|
2020-01-24 17:54:47 +01:00
|
|
|
noteChanged
|
2018-03-25 11:09:17 -04:00
|
|
|
};
|