joplin/CliClient/app/gui/NoteWidget.js

51 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-10-07 21:01:03 +00:00
const Note = require('lib/models/note.js').Note;
const TextWidget = require('tkwidgets/TextWidget.js');
class NoteWidget extends TextWidget {
constructor() {
super();
this.noteId_ = 0;
this.note_ = null;
2017-10-28 17:44:28 +00:00
this.notes_ = [];
this.lastLoadedNoteId_ = null;
}
get notes() {
return this.notes_;
}
set notes(v) {
// If the note collection has changed it means the current note might
// have changed or has been deleted, so refresh the note.
this.notes_ = v;
this.reloadNote();
2017-10-07 21:01:03 +00:00
}
get noteId() {
return this.noteId_;
}
set noteId(v) {
this.noteId_ = v;
this.note_ = null;
2017-10-28 17:44:28 +00:00
this.reloadNote();
}
2017-10-07 21:01:03 +00:00
2017-10-28 17:44:28 +00:00
reloadNote() {
2017-10-28 17:07:10 +00:00
if (this.noteId_) {
this.doAsync('loadNote', async () => {
this.note_ = await Note.load(this.noteId_);
this.text = this.note_ ? this.note_.title + "\n\n" + this.note_.body : '';
2017-10-28 17:44:28 +00:00
if (this.lastLoadedNoteId_ !== this.noteId_) this.scrollTop = 0;
this.lastLoadedNoteId_ = this.noteId_;
2017-10-28 17:07:10 +00:00
});
} else {
this.text = '';
2017-10-28 17:44:28 +00:00
this.scrollTop = 0;
2017-10-07 21:01:03 +00:00
}
}
}
module.exports = NoteWidget;