| 
									
										
										
										
											2018-03-25 13:41:29 -04:00
										 |  |  | import treeService from '../services/tree.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 14:49:20 -04:00
										 |  |  | import server from '../services/server.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 22:37:02 -04:00
										 |  |  | import treeCache from "../services/tree_cache.js"; | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | const $dialog = $("#edit-tree-prefix-dialog"); | 
					
						
							|  |  |  | const $form = $("#edit-tree-prefix-form"); | 
					
						
							|  |  |  | const $treePrefixInput = $("#tree-prefix-input"); | 
					
						
							|  |  |  | const $noteTitle = $('#tree-prefix-note-title'); | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | let branchId; | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | async function showDialog() { | 
					
						
							|  |  |  |     glob.activeDialog = $dialog; | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     await $dialog.dialog({ | 
					
						
							|  |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 500 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     const currentNode = treeService.getCurrentNode(); | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     branchId = currentNode.data.branchId; | 
					
						
							| 
									
										
										
										
											2018-03-25 22:37:02 -04:00
										 |  |  |     const branch = await treeCache.getBranch(branchId); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 14:49:20 -04:00
										 |  |  |     $treePrefixInput.val(branch.prefix).focus(); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     const noteTitle = treeService.getNoteTitle(currentNode.data.noteId); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     $noteTitle.html(noteTitle); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | $form.submit(() => { | 
					
						
							|  |  |  |     const prefix = $treePrefixInput.val(); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     server.put('tree/' + branchId + '/set-prefix', { | 
					
						
							|  |  |  |         prefix: prefix | 
					
						
							|  |  |  |     }).then(() => treeService.setPrefix(branchId, prefix)); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  |     $dialog.dialog("close"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-11-26 22:34:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |     showDialog | 
					
						
							|  |  |  | }; |