2017-12-14 20:53:08 +02:00
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 _ ) ;
2019-07-30 09:35:42 +02:00
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
}
}
}
2019-07-30 09:35:42 +02:00
module . exports = NoteWidget ;