| 
									
										
										
										
											2019-12-29 23:46:40 +01:00
										 |  |  | import treeUtils from '../services/tree_utils.js'; | 
					
						
							|  |  |  | import noteAutocompleteService from '../services/note_autocomplete.js'; | 
					
						
							|  |  |  | import utils from "../services/utils.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const $dialog = $("#include-note-dialog"); | 
					
						
							|  |  |  | const $form = $("#include-note-form"); | 
					
						
							|  |  |  | const $autoComplete = $("#include-note-autocomplete"); | 
					
						
							|  |  |  | let callback = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export async function showDialog(cb) { | 
					
						
							|  |  |  |     callback = cb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $autoComplete.val(''); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 10:00:13 +01:00
										 |  |  |     utils.openDialog($dialog); | 
					
						
							| 
									
										
										
										
											2019-12-29 23:46:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     noteAutocompleteService.initNoteAutocomplete($autoComplete, { hideGoToSelectedNoteButton: true }); | 
					
						
							|  |  |  |     noteAutocompleteService.showRecentNotes($autoComplete); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $form.on('submit', () => { | 
					
						
							|  |  |  |     const notePath = $autoComplete.getSelectedPath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (notePath) { | 
					
						
							|  |  |  |         $dialog.modal('hide'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (callback) { | 
					
						
							|  |  |  |             callback(treeUtils.getNoteIdFromNotePath(notePath)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         console.error("No noteId to include."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); |