| 
									
										
										
										
											2018-03-25 13:41:29 -04:00
										 |  |  | import treeService from '../services/tree.js'; | 
					
						
							| 
									
										
										
										
											2018-04-18 00:26:42 -04:00
										 |  |  | import server from '../services/server.js'; | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  | import searchNotesService from '../services/search_notes.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
										 |  |  | 
 | 
					
						
							|  |  |  | 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-03-25 11:09:17 -04:00
										 |  |  |     $dialog.dialog({ | 
					
						
							|  |  |  |         modal: true, | 
					
						
							| 
									
										
										
										
											2018-07-26 17:35:32 +02:00
										 |  |  |         width: 800, | 
					
						
							|  |  |  |         position: { my: "center top+100", at: "top", of: window } | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await $autoComplete.autocomplete({ | 
					
						
							| 
									
										
										
										
											2018-04-18 00:26:42 -04:00
										 |  |  |         source: async function(request, response) { | 
					
						
							|  |  |  |             const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 20:18:46 -04:00
										 |  |  |             if (result.length > 0) { | 
					
						
							|  |  |  |                 response(result); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 response([{ | 
					
						
							|  |  |  |                     label: "No results", | 
					
						
							|  |  |  |                     value: "No results" | 
					
						
							|  |  |  |                 }]); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         focus: function(event, ui) { | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |             event.preventDefault(); | 
					
						
							| 
									
										
										
										
											2018-04-18 00:26:42 -04:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |         minLength: 0, | 
					
						
							|  |  |  |         autoFocus: true, | 
					
						
							|  |  |  |         select: function (event, ui) { | 
					
						
							|  |  |  |             if (ui.item.value === 'No results') { | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |             treeService.activateNode(ui.item.value); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 16:05:09 +02:00
										 |  |  |             $dialog.dialog('close'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 09:22:25 +02: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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $dialog.dialog('close'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-27 09:22:25 +02:00
										 |  |  | function showRecentNotes() { | 
					
						
							|  |  |  |     $autoComplete.autocomplete("search", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | }; |