| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  | import TabAwareWidget from "./tab_aware_widget.js"; | 
					
						
							|  |  |  | import treeService from "../services/tree.js"; | 
					
						
							|  |  |  | import utils from "../services/utils.js"; | 
					
						
							|  |  |  | import protectedSessionService from "../services/protected_session.js"; | 
					
						
							|  |  |  | import treeUtils from "../services/tree_utils.js"; | 
					
						
							|  |  |  | import linkService from "../services/link.js"; | 
					
						
							|  |  |  | import protectedSessionHolder from "../services/protected_session_holder.js"; | 
					
						
							|  |  |  | import NoteTypeWidget from "./note_type.js"; | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | import NotePathsWidget from "./note_paths.js"; | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  | import NoteActionsWidget from "./note_actions.js"; | 
					
						
							|  |  |  | import ProtectedNoteSwitchWidget from "./protected_note_switch.js"; | 
					
						
							|  |  |  | import RunScriptButtonsWidget from "./run_script_buttons.js"; | 
					
						
							| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const TPL = `
 | 
					
						
							| 
									
										
										
										
											2020-01-19 15:44:18 +01:00
										 |  |  | <div class="note-title-container"> | 
					
						
							| 
									
										
										
										
											2020-01-14 20:27:40 +01:00
										 |  |  |     <style> | 
					
						
							| 
									
										
										
										
											2020-01-19 15:44:18 +01:00
										 |  |  |     .note-title-container { | 
					
						
							|  |  |  |         flex-grow: 100; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     .note-title-container input.note-title { | 
					
						
							| 
									
										
										
										
											2020-01-14 20:27:40 +01:00
										 |  |  |         margin-left: 15px; | 
					
						
							|  |  |  |         margin-right: 10px; | 
					
						
							|  |  |  |         font-size: 150%; | 
					
						
							|  |  |  |         border: 0; | 
					
						
							|  |  |  |         width: 5em; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     </style> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |     <input autocomplete="off" value="" class="note-title" tabindex="1"> | 
					
						
							| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  | </div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default class NoteTitleWidget extends TabAwareWidget { | 
					
						
							| 
									
										
										
										
											2020-01-12 20:15:05 +01:00
										 |  |  |     doRender() { | 
					
						
							| 
									
										
										
										
											2020-01-14 20:27:40 +01:00
										 |  |  |         this.$widget = $(TPL); | 
					
						
							|  |  |  |         this.$noteTitle = this.$widget.find(".note-title"); | 
					
						
							| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$noteTitle.on('input', () => { | 
					
						
							|  |  |  |             if (!this.note) { | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // FIXME event not used
 | 
					
						
							|  |  |  |             this.trigger(`activeNoteChanged`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.note.title = this.$noteTitle.val(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.tabRow.updateTab(this.$tab[0], {title: this.note.title}); | 
					
						
							|  |  |  |             treeService.setNoteTitle(this.note.noteId, this.note.title); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.setTitleBar(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (utils.isDesktop()) { | 
					
						
							|  |  |  |             // keyboard plugin is not loaded in mobile
 | 
					
						
							|  |  |  |             utils.bindElShortcut(this.$noteTitle, 'return', () => { | 
					
						
							|  |  |  |                 this.getComponent().focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return false; // to not propagate the enter into the editor (causes issues with codemirror)
 | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-12 20:15:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 20:27:40 +01:00
										 |  |  |         return this.$widget; | 
					
						
							| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 15:36:42 +01:00
										 |  |  |     async refreshWithNote(note) { | 
					
						
							| 
									
										
										
										
											2020-01-12 23:03:55 +01:00
										 |  |  |         this.$noteTitle.val(note.title); | 
					
						
							| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 11:03:34 +01:00
										 |  |  |         if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { | 
					
						
							|  |  |  |             this.$noteTitle.prop("readonly", true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-12 19:05:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |