| 
									
										
										
										
											2018-03-25 13:41:29 -04:00
										 |  |  | import treeService from '../services/tree.js'; | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | import searchNotesService from '../services/search_notes.js'; | 
					
						
							| 
									
										
										
										
											2018-08-16 21:02:42 +02:00
										 |  |  | import noteautocompleteService from '../services/note_autocomplete.js'; | 
					
						
							|  |  |  | import linkService from "../services/link.js"; | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | const $dialog = $("#jump-to-note-dialog"); | 
					
						
							|  |  |  | const $autoComplete = $("#jump-to-note-autocomplete"); | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | const $showInFullTextButton = $("#show-in-full-text-button"); | 
					
						
							| 
									
										
										
										
											2018-08-14 17:36:39 +02:00
										 |  |  | const $showRecentNotesButton = $dialog.find(".show-recent-notes-button"); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  | $dialog.on("shown.bs.modal", e => $autoComplete.focus()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | async function showDialog() { | 
					
						
							|  |  |  |     glob.activeDialog = $dialog; | 
					
						
							| 
									
										
										
										
											2017-11-19 22:31:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     $autoComplete.val(''); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 15:25:07 +01:00
										 |  |  |     $dialog.modal(); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  |     $autoComplete.autocomplete({ | 
					
						
							|  |  |  |         appendTo: document.querySelector('body'), | 
					
						
							|  |  |  |         hint: false, | 
					
						
							|  |  |  |         autoselect: true, | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |         openOnFocus: true, | 
					
						
							|  |  |  |         minLength: 0 | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  |     }, [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             source: noteautocompleteService.autocompleteSource, | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |             displayKey: 'title', | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  |             templates: { | 
					
						
							|  |  |  |                 suggestion: function(suggestion) { | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |                     return suggestion.title; | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     ]).on('autocomplete:selected', function(event, suggestion, dataset) { | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |         if (!suggestion.path) { | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-16 21:02:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |         treeService.activateNote(suggestion.path); | 
					
						
							| 
									
										
										
										
											2018-11-07 00:23:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $dialog.modal('hide'); | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |     showRecentNotes(); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | function showInFullText(e) { | 
					
						
							|  |  |  |     // stop from propagating upwards (dangerous especially with ctrl+enter executable javascript notes)
 | 
					
						
							|  |  |  |     e.preventDefault(); | 
					
						
							|  |  |  |     e.stopPropagation(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const searchText = $autoComplete.val(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     searchNotesService.resetSearch(); | 
					
						
							|  |  |  |     searchNotesService.showSearch(); | 
					
						
							|  |  |  |     searchNotesService.doSearch(searchText); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 17:47:40 +01:00
										 |  |  |     $dialog.modal('hide'); | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 09:22:25 +02:00
										 |  |  | function showRecentNotes() { | 
					
						
							| 
									
										
										
										
											2018-11-07 09:35:29 +01:00
										 |  |  |     $autoComplete.autocomplete("val", ""); | 
					
						
							|  |  |  |     $autoComplete.autocomplete("open"); | 
					
						
							| 
									
										
										
										
											2018-07-27 09:22:25 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | $showInFullTextButton.click(showInFullText); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 09:22:25 +02:00
										 |  |  | $showRecentNotesButton.click(showRecentNotes); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | $dialog.bind('keydown', 'ctrl+return', showInFullText); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |     showDialog | 
					
						
							|  |  |  | }; |