1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/CliClient/app/gui/NoteWidget.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

const Note = require('lib/models/Note.js');
2017-10-07 23:01:03 +02:00
const TextWidget = require('tkwidgets/TextWidget.js');
2017-12-15 09:31:57 +02:00
const { _ } = require('lib/locale.js');
2017-10-07 23:01:03 +02:00
class NoteWidget extends TextWidget {
constructor() {
super();
this.noteId_ = 0;
this.note_ = null;
2017-10-28 19:44:28 +02: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 23:01:03 +02:00
}
get noteId() {
return this.noteId_;
}
set noteId(v) {
this.noteId_ = v;
this.note_ = null;
2017-10-28 19:44:28 +02:00
this.reloadNote();
}
2017-10-07 23:01:03 +02:00
2017-12-15 09:31:57 +02:00
welcomeText() {
return _('Welcome to Joplin!\n\nType `:help shortcuts` for the list of keyboard shortcuts, or just `:help` for usage information.\n\nFor example, to create a notebook press `mb`; to create a note press `mn`.');
}
2017-10-28 19:44:28 +02:00
reloadNote() {
2017-12-15 09:31:57 +02:00
if (!this.noteId_ && !this.notes.length) {
this.text = this.welcomeText();
this.scrollTop = 0;
} else if (this.noteId_) {
2017-10-28 19:07:10 +02:00
this.doAsync('loadNote', async () => {
this.note_ = await Note.load(this.noteId_);
2017-12-28 21:51:24 +02:00
if (this.note_ && this.note_.encryption_applied) {
2017-12-26 12:38:53 +02:00
this.text = _('One or more items are currently encrypted and you may need to supply a master password. To do so please type `e2ee decrypt`. If you have already supplied the password, the encrypted items are being decrypted in the background and will be available soon.');
} else {
2019-09-19 23:51:18 +02:00
this.text = this.note_ ? `${this.note_.title}\n\n${this.note_.body}` : '';
2017-12-26 12:38:53 +02:00
}
2017-10-28 19:44:28 +02:00
if (this.lastLoadedNoteId_ !== this.noteId_) this.scrollTop = 0;
this.lastLoadedNoteId_ = this.noteId_;
2017-10-28 19:07:10 +02:00
});
} else {
this.text = '';
2017-10-28 19:44:28 +02:00
this.scrollTop = 0;
2017-10-07 23:01:03 +02:00
}
}
}
module.exports = NoteWidget;