| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  | const jumpToNote = (function() { | 
					
						
							|  |  |  |     const dialogEl = $("#jump-to-note-dialog"); | 
					
						
							|  |  |  |     const autoCompleteEl = $("#jump-to-note-autocomplete"); | 
					
						
							|  |  |  |     const formEl = $("#jump-to-note-form"); | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |     const noteDetailEl = $('#note-detail'); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  |     async function showDialog() { | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |         noteDetailEl.summernote('editor.saveRange'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |         glob.activeDialog = dialogEl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  |         autoCompleteEl.val(''); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  |         dialogEl.dialog({ | 
					
						
							|  |  |  |             modal: true, | 
					
						
							|  |  |  |             width: 800 | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-10-10 20:37:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  |         await autoCompleteEl.autocomplete({ | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |             source: noteTree.getAutocompleteItems(), | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  |             minLength: 0 | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |     function getSelectedNotePath() { | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  |         const val = autoCompleteEl.val(); | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |         return link.getNodePathFromLabel(val); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |     function getSelectedNoteId() { | 
					
						
							|  |  |  |         const notePath = getSelectedNotePath(); | 
					
						
							|  |  |  |         return treeUtils.getNoteIdFromNotePath(notePath); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |     function goToNote() { | 
					
						
							|  |  |  |         const notePath = getSelectedNotePath(); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  |         if (notePath) { | 
					
						
							|  |  |  |             noteTree.activateNode(notePath); | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             dialogEl.dialog('close'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $(document).bind('keydown', 'alt+j', showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     formEl.submit(() => { | 
					
						
							|  |  |  |         const action = dialogEl.find("button:focus").val(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |         if (!action || action === 'jump') { | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  |             goToNote(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |         else if (action === 'add-link') { | 
					
						
							|  |  |  |             const notePath = getSelectedNotePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (notePath) { | 
					
						
							|  |  |  |                 dialogEl.dialog("close"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 noteDetailEl.summernote('editor.restoreRange'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |                 const noteId = treeUtils.getNoteIdFromNotePath(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |                 noteDetailEl.summernote('createLink', { | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |                     text: noteTree.getNoteTitle(noteId), | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  |                     url: 'app#' + notePath, | 
					
						
							|  |  |  |                     isNewWindow: true | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (action === 'add-current-as-child') { | 
					
						
							| 
									
										
										
										
											2017-11-26 19:56:08 -05:00
										 |  |  |             treeChanges.cloneNoteTo(noteEditor.getCurrentNoteId(), getSelectedNoteId()); | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             dialogEl.dialog("close"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (action === 'add-selected-as-child') { | 
					
						
							| 
									
										
										
										
											2017-11-26 19:56:08 -05:00
										 |  |  |             treeChanges.cloneNoteTo(getSelectedNoteId(), noteEditor.getCurrentNoteId()); | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             dialogEl.dialog("close"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             console.error("Unknown action=" + action); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:59:43 -04:00
										 |  |  |     return { | 
					
						
							|  |  |  |         showDialog | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })(); |