| 
									
										
										
										
											2019-05-01 23:06:18 +02:00
										 |  |  | import treeService from "./tree.js"; | 
					
						
							|  |  |  | import protectedSessionHolder from "./protected_session_holder.js"; | 
					
						
							|  |  |  | import server from "./server.js"; | 
					
						
							|  |  |  | import bundleService from "./bundle.js"; | 
					
						
							| 
									
										
										
										
											2019-05-04 22:44:25 +02:00
										 |  |  | import Attributes from "./attributes.js"; | 
					
						
							| 
									
										
										
										
											2019-05-01 23:06:18 +02:00
										 |  |  | import treeUtils from "./tree_utils.js"; | 
					
						
							|  |  |  | import utils from "./utils.js"; | 
					
						
							| 
									
										
										
										
											2019-05-04 22:44:25 +02:00
										 |  |  | import {NoteTypeContext} from "./note_type.js"; | 
					
						
							|  |  |  | import noteDetailService from "./note_detail.js"; | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  | import noteDetailEmpty from "./note_detail_empty.js"; | 
					
						
							| 
									
										
										
										
											2019-05-01 23:06:18 +02:00
										 |  |  | import noteDetailText from "./note_detail_text.js"; | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  | import noteDetailCode from "./note_detail_code.js"; | 
					
						
							| 
									
										
										
										
											2019-05-01 23:06:18 +02:00
										 |  |  | import noteDetailFile from "./note_detail_file.js"; | 
					
						
							|  |  |  | import noteDetailImage from "./note_detail_image.js"; | 
					
						
							|  |  |  | import noteDetailSearch from "./note_detail_search.js"; | 
					
						
							|  |  |  | import noteDetailRender from "./note_detail_render.js"; | 
					
						
							|  |  |  | import noteDetailRelationMap from "./note_detail_relation_map.js"; | 
					
						
							| 
									
										
										
										
											2019-05-05 19:48:30 +02:00
										 |  |  | import noteDetailProtectedSession from "./note_detail_protected_session.js"; | 
					
						
							| 
									
										
										
										
											2019-05-05 20:45:07 +02:00
										 |  |  | import protectedSessionService from "./protected_session.js"; | 
					
						
							| 
									
										
										
										
											2019-05-19 21:22:35 +02:00
										 |  |  | import linkService from "./link.js"; | 
					
						
							| 
									
										
										
										
											2019-07-21 10:17:08 +02:00
										 |  |  | import Sidebar from "./sidebar.js"; | 
					
						
							| 
									
										
										
										
											2019-05-01 23:06:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  | const $tabContentsContainer = $("#note-tab-container"); | 
					
						
							| 
									
										
										
										
											2019-05-02 22:24:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | const componentClasses = { | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |     'empty': noteDetailEmpty, | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |     'text': noteDetailText, | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |     'code': noteDetailCode, | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |     'file': noteDetailFile, | 
					
						
							|  |  |  |     'image': noteDetailImage, | 
					
						
							|  |  |  |     'search': noteDetailSearch, | 
					
						
							|  |  |  |     'render': noteDetailRender, | 
					
						
							| 
									
										
										
										
											2019-05-05 19:48:30 +02:00
										 |  |  |     'relation-map': noteDetailRelationMap, | 
					
						
							|  |  |  |     'protected-session': noteDetailProtectedSession | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  | class TabContext { | 
					
						
							| 
									
										
										
										
											2019-05-11 19:44:58 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param {TabRow} tabRow | 
					
						
							| 
									
										
										
										
											2019-08-16 21:29:44 +02:00
										 |  |  |      * @param {object} state | 
					
						
							| 
									
										
										
										
											2019-05-11 19:44:58 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-08-16 21:29:44 +02:00
										 |  |  |     constructor(tabRow, state = {}) { | 
					
						
							| 
									
										
										
										
											2019-05-11 19:44:58 +02:00
										 |  |  |         this.tabRow = tabRow; | 
					
						
							| 
									
										
										
										
											2019-08-16 21:29:44 +02:00
										 |  |  |         this.tabId = state.tabId || utils.randomString(4); | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  |         this.$tab = $(this.tabRow.addTab(this.tabId)); | 
					
						
							| 
									
										
										
										
											2019-05-05 10:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         this.$tabContent = $(".note-tab-content-template").clone(); | 
					
						
							|  |  |  |         this.$tabContent.removeClass('note-tab-content-template'); | 
					
						
							|  |  |  |         this.$tabContent.attr('data-tab-id', this.tabId); | 
					
						
							| 
									
										
										
										
											2019-05-05 10:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         $tabContentsContainer.append(this.$tabContent); | 
					
						
							| 
									
										
										
										
											2019-05-05 10:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         this.$noteTitle = this.$tabContent.find(".note-title"); | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |         this.$noteTitleRow = this.$tabContent.find(".note-title-row"); | 
					
						
							| 
									
										
										
										
											2019-05-19 21:22:35 +02:00
										 |  |  |         this.$notePathList = this.$tabContent.find(".note-path-list"); | 
					
						
							|  |  |  |         this.$notePathCount = this.$tabContent.find(".note-path-count"); | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         this.$noteDetailComponents = this.$tabContent.find(".note-detail-component"); | 
					
						
							|  |  |  |         this.$childrenOverview = this.$tabContent.find(".children-overview"); | 
					
						
							|  |  |  |         this.$scriptArea = this.$tabContent.find(".note-detail-script-area"); | 
					
						
							|  |  |  |         this.$savedIndicator = this.$tabContent.find(".saved-indicator"); | 
					
						
							| 
									
										
										
										
											2019-05-04 14:34:03 +02:00
										 |  |  |         this.noteChangeDisabled = false; | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |         this.isNoteChanged = false; | 
					
						
							| 
									
										
										
										
											2019-05-04 22:44:25 +02:00
										 |  |  |         this.attributes = new Attributes(this); | 
					
						
							| 
									
										
										
										
											2019-05-13 23:08:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (utils.isDesktop()) { | 
					
						
							| 
									
										
										
										
											2019-08-16 21:29:44 +02:00
										 |  |  |             this.sidebar = new Sidebar(this, state.sidebar); | 
					
						
							| 
									
										
										
										
											2019-05-13 23:08:59 +02:00
										 |  |  |             this.noteType = new NoteTypeContext(this); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |         this.components = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$noteTitle.on('input', () => { | 
					
						
							| 
									
										
										
										
											2019-06-24 20:12:04 +02:00
										 |  |  |             if (!this.note) { | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |             this.noteChanged(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 20:12:04 +02:00
										 |  |  |             this.note.title = this.$noteTitle.val(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.tabRow.updateTab(this.$tab[0], {title: this.note.title}); | 
					
						
							|  |  |  |             treeService.setNoteTitle(this.noteId, this.note.title); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 20:12:04 +02:00
										 |  |  |             this.setTitleBar(); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-05-02 22:24:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-22 20:53:59 +02:00
										 |  |  |         if (utils.isDesktop()) { | 
					
						
							|  |  |  |             // keyboard plugin is not loaded in mobile
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |             utils.bindElShortcut(this.$noteTitle, 'return', () => { | 
					
						
							| 
									
										
										
										
											2019-07-03 20:29:55 +02:00
										 |  |  |                 this.getComponent().focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return false; // to not propagate the enter into the editor (causes issues with codemirror)
 | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2019-05-22 20:53:59 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-19 21:22:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         this.$protectButton = this.$tabContent.find(".protect-button"); | 
					
						
							| 
									
										
										
										
											2019-05-05 20:45:07 +02:00
										 |  |  |         this.$protectButton.click(protectedSessionService.protectNoteAndSendToServer); | 
					
						
							| 
									
										
										
										
											2019-05-03 21:50:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         this.$unprotectButton = this.$tabContent.find(".unprotect-button"); | 
					
						
							| 
									
										
										
										
											2019-05-05 20:45:07 +02:00
										 |  |  |         this.$unprotectButton.click(protectedSessionService.unprotectNoteAndSendToServer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 12:03:51 +02:00
										 |  |  |         console.debug(`Created note tab ${this.tabId}`); | 
					
						
							| 
									
										
										
										
											2019-05-02 22:24:43 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 20:14:41 +02:00
										 |  |  |     setNote(note, notePath) { | 
					
						
							| 
									
										
										
										
											2019-05-02 22:24:43 +02:00
										 |  |  |         this.noteId = note.noteId; | 
					
						
							| 
									
										
										
										
											2019-05-08 20:14:41 +02:00
										 |  |  |         this.notePath = notePath; | 
					
						
							| 
									
										
										
										
											2019-05-02 22:24:43 +02:00
										 |  |  |         this.note = note; | 
					
						
							| 
									
										
										
										
											2019-05-13 22:08:06 +02:00
										 |  |  |         this.tabRow.updateTab(this.$tab[0], {title: note.title}); | 
					
						
							| 
									
										
										
										
											2019-05-04 22:44:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.attributes.invalidateAttributes(); | 
					
						
							| 
									
										
										
										
											2019-05-05 10:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 22:08:06 +02:00
										 |  |  |         this.setupClasses(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  |         this.setCurrentNotePathToHash(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-29 19:55:05 +02:00
										 |  |  |         this.setTitleBar(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-26 21:08:54 +02:00
										 |  |  |         this.closeAutocomplete(); // esp. on windows autocomplete is not getting closed automatically
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  |         setTimeout(async () => { | 
					
						
							|  |  |  |             // we include the note into recent list only if the user stayed on the note at least 5 seconds
 | 
					
						
							| 
									
										
										
										
											2019-05-21 21:47:28 +02:00
										 |  |  |             if (notePath && notePath === this.notePath) { | 
					
						
							|  |  |  |                 await server.post('recent-notes', { | 
					
						
							|  |  |  |                     noteId: this.noteId, | 
					
						
							|  |  |  |                     notePath: this.notePath | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         }, 5000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 16:56:16 +02:00
										 |  |  |         if (utils.isDesktop()) { | 
					
						
							|  |  |  |             this.noteType.updateExecuteScriptButtonVisibility(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 21:22:35 +02:00
										 |  |  |         this.showPaths(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-21 11:32:38 +02:00
										 |  |  |         if (this.sidebar) { | 
					
						
							|  |  |  |             this.sidebar.noteLoaded(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-06 12:03:51 +02:00
										 |  |  |         console.debug(`Switched tab ${this.tabId} to ${this.noteId}`); | 
					
						
							| 
									
										
										
										
											2019-05-13 22:08:06 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  |     show() { | 
					
						
							|  |  |  |         this.$tabContent.show(); | 
					
						
							|  |  |  |         this.setCurrentNotePathToHash(); | 
					
						
							| 
									
										
										
										
											2019-05-29 19:55:05 +02:00
										 |  |  |         this.setTitleBar(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setTitleBar() { | 
					
						
							|  |  |  |         if (!this.$tabContent.is(":visible")) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         document.title = "Trilium Notes"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this.note) { | 
					
						
							|  |  |  |             // it helps navigating in history if note title is included in the title
 | 
					
						
							|  |  |  |             document.title += " - " + this.note.title; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     hide() { | 
					
						
							|  |  |  |         this.$tabContent.hide(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setCurrentNotePathToHash() { | 
					
						
							|  |  |  |         if (this.$tab[0] === this.tabRow.activeTabEl) { | 
					
						
							|  |  |  |             document.location.hash = (this.notePath || "") + "-" + this.tabId; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 22:08:06 +02:00
										 |  |  |     setupClasses() { | 
					
						
							|  |  |  |         for (const clazz of Array.from(this.$tab[0].classList)) { // create copy to safely iterate over while removing classes
 | 
					
						
							|  |  |  |             if (clazz !== 'note-tab') { | 
					
						
							|  |  |  |                 this.$tab.removeClass(clazz); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         for (const clazz of Array.from(this.$tabContent[0].classList)) { // create copy to safely iterate over while removing classes
 | 
					
						
							| 
									
										
										
										
											2019-05-13 22:08:06 +02:00
										 |  |  |             if (clazz !== 'note-tab-content') { | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |                 this.$tabContent.removeClass(clazz); | 
					
						
							| 
									
										
										
										
											2019-05-05 20:45:07 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-13 22:08:06 +02:00
										 |  |  |         this.$tab.addClass(this.note.cssClass); | 
					
						
							|  |  |  |         this.$tab.addClass(utils.getNoteTypeClass(this.note.type)); | 
					
						
							|  |  |  |         this.$tab.addClass(utils.getMimeTypeClass(this.note.mime)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$tabContent.addClass(this.note.cssClass); | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  |         this.$tabContent.addClass(utils.getNoteTypeClass(this.note.type)); | 
					
						
							|  |  |  |         this.$tabContent.addClass(utils.getMimeTypeClass(this.note.mime)); | 
					
						
							| 
									
										
										
										
											2019-05-22 22:26:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$noteTitleRow.show(); // might be hidden from empty detail
 | 
					
						
							|  |  |  |         this.$tabContent.toggleClass("protected", this.note.isProtected); | 
					
						
							|  |  |  |         this.$protectButton.toggleClass("active", this.note.isProtected); | 
					
						
							|  |  |  |         this.$protectButton.prop("disabled", this.note.isProtected); | 
					
						
							|  |  |  |         this.$unprotectButton.toggleClass("active", !this.note.isProtected); | 
					
						
							|  |  |  |         this.$unprotectButton.prop("disabled", !this.note.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-05 19:48:30 +02:00
										 |  |  |     getComponent() { | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |         let type; | 
					
						
							| 
									
										
										
										
											2019-05-05 19:48:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |         if (this.note) { | 
					
						
							|  |  |  |             type = this.note.type; | 
					
						
							| 
									
										
										
										
											2019-05-05 19:48:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |             if (this.note.isProtected) { | 
					
						
							|  |  |  |                 if (protectedSessionHolder.isProtectedSessionAvailable()) { | 
					
						
							|  |  |  |                     protectedSessionHolder.touchProtectedSession(); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     type = 'protected-session'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     // user shouldn't be able to edit note title
 | 
					
						
							|  |  |  |                     this.$noteTitle.prop("readonly", true); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-05-05 19:48:30 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-12 12:58:55 +02:00
										 |  |  |         else { | 
					
						
							|  |  |  |             type = 'empty'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!(type in this.components)) { | 
					
						
							|  |  |  |             this.components[type] = new componentClasses[type](this); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return this.components[type]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-21 20:24:40 +02:00
										 |  |  |     async activate() { | 
					
						
							|  |  |  |         await this.tabRow.activateTab(this.$tab[0]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |     async saveNote() { | 
					
						
							|  |  |  |         if (this.note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.note.title = this.$noteTitle.val(); | 
					
						
							| 
									
										
										
										
											2019-05-21 20:24:40 +02:00
										 |  |  |         this.note.content = this.getComponent().getContent(); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // it's important to set the flag back to false immediatelly after retrieving title and content
 | 
					
						
							|  |  |  |         // otherwise we might overwrite another change (especially async code)
 | 
					
						
							|  |  |  |         this.isNoteChanged = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         treeService.setNoteTitle(this.note.noteId, this.note.title); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 22:39:27 +02:00
										 |  |  |         const resp = await server.put('notes/' + this.note.noteId, this.note.dto); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.note.dateModified = resp.dateModified; | 
					
						
							|  |  |  |         this.note.utcDateModified = resp.utcDateModified; | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (this.note.isProtected) { | 
					
						
							|  |  |  |             protectedSessionHolder.touchProtectedSession(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 21:50:14 +02:00
										 |  |  |         this.$savedIndicator.fadeIn(); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // run async
 | 
					
						
							| 
									
										
										
										
											2019-05-29 21:48:48 +02:00
										 |  |  |         bundleService.executeRelationBundles(this.note, 'runOnNoteChange', this); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async saveNoteIfChanged() { | 
					
						
							|  |  |  |         if (this.isNoteChanged) { | 
					
						
							|  |  |  |             await this.saveNote(); | 
					
						
							| 
									
										
										
										
											2019-05-20 22:25:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             noteDetailService.refreshTabs(this.tabId, this.noteId); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     noteChanged() { | 
					
						
							| 
									
										
										
										
											2019-05-04 14:34:03 +02:00
										 |  |  |         if (this.noteChangeDisabled) { | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.isNoteChanged = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-03 21:50:14 +02:00
										 |  |  |         this.$savedIndicator.fadeOut(); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async showChildrenOverview() { | 
					
						
							| 
									
										
										
										
											2019-05-04 22:44:25 +02:00
										 |  |  |         const attributes = await this.attributes.getAttributes(); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  |         const hideChildrenOverview = attributes.some(attr => attr.type === 'label' && attr.name === 'hideChildrenOverview') | 
					
						
							|  |  |  |             || this.note.type === 'relation-map' | 
					
						
							|  |  |  |             || this.note.type === 'image' | 
					
						
							|  |  |  |             || this.note.type === 'file'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (hideChildrenOverview) { | 
					
						
							|  |  |  |             this.$childrenOverview.hide(); | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$childrenOverview.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const childBranch of await this.note.getChildBranches()) { | 
					
						
							|  |  |  |             const link = $('<a>', { | 
					
						
							|  |  |  |                 href: 'javascript:', | 
					
						
							|  |  |  |                 text: await treeUtils.getNoteTitle(childBranch.noteId, childBranch.parentNoteId) | 
					
						
							| 
									
										
										
										
											2019-05-14 22:29:47 +02:00
										 |  |  |             }).attr('data-action', 'note').attr('data-note-path', this.notePath + '/' + childBranch.noteId); | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             const childEl = $('<div class="child-overview-item">').html(link); | 
					
						
							|  |  |  |             this.$childrenOverview.append(childEl); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$childrenOverview.show(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-19 21:22:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async addPath(notePath, isCurrent) { | 
					
						
							|  |  |  |         const title = await treeUtils.getNotePathTitle(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const noteLink = await linkService.createNoteLink(notePath, title); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         noteLink | 
					
						
							|  |  |  |             .addClass("no-tooltip-preview") | 
					
						
							|  |  |  |             .addClass("dropdown-item"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isCurrent) { | 
					
						
							|  |  |  |             noteLink.addClass("current"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$notePathList.append(noteLink); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async showPaths() { | 
					
						
							|  |  |  |         if (this.note.noteId === 'root') { | 
					
						
							|  |  |  |             // root doesn't have any parent, but it's still technically 1 path
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.$notePathCount.html("1 path"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.$notePathList.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             await this.addPath('root', true); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             const parents = await this.note.getParentNotes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.$notePathCount.html(parents.length + " path" + (parents.length > 1 ? "s" : "")); | 
					
						
							|  |  |  |             this.$notePathList.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const pathSegments = this.notePath.split("/"); | 
					
						
							|  |  |  |             const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const parentNote of parents) { | 
					
						
							|  |  |  |                 const parentNotePath = await treeService.getSomeNotePath(parentNote); | 
					
						
							|  |  |  |                 // this is to avoid having root notes leading '/'
 | 
					
						
							|  |  |  |                 const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId; | 
					
						
							|  |  |  |                 const isCurrent = activeNoteParentNoteId === parentNote.noteId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 await this.addPath(notePath, isCurrent); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-06-26 21:08:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     closeAutocomplete() { | 
					
						
							| 
									
										
										
										
											2019-06-30 20:14:57 +02:00
										 |  |  |         if (utils.isDesktop()) { | 
					
						
							|  |  |  |             this.$tabContent.find('.aa-input').autocomplete('close'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-06-26 21:08:54 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-06 22:39:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     syncDataReceived(syncData) { | 
					
						
							| 
									
										
										
										
											2019-08-06 23:20:27 +02:00
										 |  |  |         this.attributes.syncDataReceived(syncData); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 22:39:27 +02:00
										 |  |  |         if (this.sidebar) { | 
					
						
							|  |  |  |             this.sidebar.syncDataReceived(syncData); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-15 10:04:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     getTabState() { | 
					
						
							|  |  |  |         if (!this.notePath) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             tabId: this.tabId, | 
					
						
							|  |  |  |             notePath: this.notePath, | 
					
						
							|  |  |  |             active: this.tabRow.activeTabEl === this.$tab[0], | 
					
						
							|  |  |  |             sidebar: this.sidebar && this.sidebar.getSidebarState() | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stateChanged() { | 
					
						
							|  |  |  |         noteDetailService.openTabsChanged(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-01 22:19:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 19:55:24 +02:00
										 |  |  | export default TabContext; |