| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | import searchNotesService from '../services/search_notes.js'; | 
					
						
							| 
									
										
										
										
											2018-11-07 09:51:14 +01:00
										 |  |  | import noteAutocompleteService from '../services/note_autocomplete.js'; | 
					
						
							| 
									
										
										
										
											2019-06-10 22:45:03 +02:00
										 |  |  | import utils from "../services/utils.js"; | 
					
						
							| 
									
										
										
										
											2020-02-02 22:04:28 +01:00
										 |  |  | import appContext from "../services/app_context.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-11-07 00:23:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  | export async function showDialog() { | 
					
						
							| 
									
										
										
										
											2019-06-10 22:45:03 +02:00
										 |  |  |     utils.closeActiveDialog(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     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-14 11:28:52 +01:00
										 |  |  |     noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true }) | 
					
						
							| 
									
										
										
										
											2018-11-07 09:51:14 +01:00
										 |  |  |         .on('autocomplete:selected', function(event, suggestion, dataset) { | 
					
						
							|  |  |  |             if (!suggestion.path) { | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-08-16 21:02:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 21:08:55 +01:00
										 |  |  |             appContext.tabManager.getActiveTabContext().setNote(suggestion.path); | 
					
						
							| 
									
										
										
										
											2018-11-07 09:51:14 +01:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 09:51:14 +01:00
										 |  |  |     noteAutocompleteService.showRecentNotes($autoComplete); | 
					
						
							| 
									
										
										
										
											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-11-07 09:51:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-09 17:39:48 +01:00
										 |  |  | $showInFullTextButton.on('click', showInFullText); | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  | utils.bindElShortcut($dialog, 'ctrl+return', showInFullText); |