| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  | const contextMenu = (function() { | 
					
						
							|  |  |  |     const treeEl = $("#tree"); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     function pasteAfter(node) { | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         const subjectNode = treeUtils.getNodeByNoteTreeId(noteTree.getClipboardNoteTreeId()); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 22:10:41 -04:00
										 |  |  |         treeChanges.moveAfterNode(subjectNode, node); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         noteTree.setClipboardNoteTreeId(null); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     function pasteInto(node) { | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         const subjectNode = treeUtils.getNodeByNoteTreeId(noteTree.getClipboardNoteTreeId()); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 22:10:41 -04:00
										 |  |  |         treeChanges.moveToNode(subjectNode, node); | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         noteTree.setClipboardNoteTreeId(null); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     function cut(node) { | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         noteTree.setClipboardNoteTreeId(node.note_tree_id); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-10-15 20:55:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     const contextMenuSettings = { | 
					
						
							|  |  |  |         delegate: "span.fancytree-title", | 
					
						
							|  |  |  |         autoFocus: true, | 
					
						
							|  |  |  |         menu: [ | 
					
						
							|  |  |  |             {title: "Insert note here", cmd: "insertNoteHere", uiIcon: "ui-icon-pencil"}, | 
					
						
							|  |  |  |             {title: "Insert child note", cmd: "insertChildNote", uiIcon: "ui-icon-pencil"}, | 
					
						
							|  |  |  |             {title: "Delete", cmd: "delete", uiIcon: "ui-icon-trash"}, | 
					
						
							|  |  |  |             {title: "----"}, | 
					
						
							| 
									
										
										
										
											2017-11-15 00:04:26 -05:00
										 |  |  |             {title: "Protect sub-tree", cmd: "protectSubTree", uiIcon: "ui-icon-locked"}, | 
					
						
							|  |  |  |             {title: "Unprotect sub-tree", cmd: "unprotectSubTree", uiIcon: "ui-icon-unlocked"}, | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             {title: "----"}, | 
					
						
							|  |  |  |             {title: "Cut", cmd: "cut", uiIcon: "ui-icon-scissors"}, | 
					
						
							|  |  |  |             {title: "Copy / clone", cmd: "copy", uiIcon: "ui-icon-copy"}, | 
					
						
							|  |  |  |             {title: "Paste after", cmd: "pasteAfter", uiIcon: "ui-icon-clipboard"}, | 
					
						
							|  |  |  |             {title: "Paste into", cmd: "pasteInto", uiIcon: "ui-icon-clipboard"} | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         beforeOpen: (event, ui) => { | 
					
						
							|  |  |  |             const node = $.ui.fancytree.getNode(ui.target); | 
					
						
							|  |  |  |             // Modify menu entries depending on node status
 | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |             treeEl.contextmenu("enableEntry", "pasteAfter", noteTree.getClipboardNoteTreeId() !== null); | 
					
						
							|  |  |  |             treeEl.contextmenu("enableEntry", "pasteInto", noteTree.getClipboardNoteTreeId() !== null); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             // Activate node on right-click
 | 
					
						
							|  |  |  |             node.setActive(); | 
					
						
							|  |  |  |             // Disable tree keyboard handling
 | 
					
						
							|  |  |  |             ui.menu.prevKeyboard = node.tree.options.keyboard; | 
					
						
							|  |  |  |             node.tree.options.keyboard = false; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         close: (event, ui) => {}, | 
					
						
							|  |  |  |         select: (event, ui) => { | 
					
						
							|  |  |  |             const node = $.ui.fancytree.getNode(ui.target); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             if (ui.cmd === "insertNoteHere") { | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |                 const parentNoteTreeId = treeUtils.getParentNoteTreeId(node); | 
					
						
							| 
									
										
										
										
											2017-11-14 23:01:23 -05:00
										 |  |  |                 const isProtected = treeUtils.getParentProtectedStatus(node); | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |                 noteEditor.createNote(node, parentNoteTreeId, 'after', isProtected); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |             else if (ui.cmd === "insertChildNote") { | 
					
						
							| 
									
										
										
										
											2017-11-22 20:46:42 -05:00
										 |  |  |                 noteEditor.createNote(node, node.data.note_id, 'into'); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-15 00:04:26 -05:00
										 |  |  |             else if (ui.cmd === "protectSubTree") { | 
					
						
							| 
									
										
										
										
											2017-11-22 20:46:42 -05:00
										 |  |  |                 protected_session.protectSubTree(node.data.note_id, true); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-15 00:04:26 -05:00
										 |  |  |             else if (ui.cmd === "unprotectSubTree") { | 
					
						
							| 
									
										
										
										
											2017-11-22 20:46:42 -05:00
										 |  |  |                 protected_session.protectSubTree(node.data.note_id, false); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |             else if (ui.cmd === "cut") { | 
					
						
							|  |  |  |                 cut(node); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (ui.cmd === "pasteAfter") { | 
					
						
							|  |  |  |                 pasteAfter(node); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (ui.cmd === "pasteInto") { | 
					
						
							|  |  |  |                 pasteInto(node); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (ui.cmd === "delete") { | 
					
						
							| 
									
										
										
										
											2017-11-04 22:10:41 -04:00
										 |  |  |                 treeChanges.deleteNode(node); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 console.log("Unknown command: " + ui.cmd); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         pasteAfter, | 
					
						
							|  |  |  |         pasteInto, | 
					
						
							|  |  |  |         cut, | 
					
						
							|  |  |  |         contextMenuSettings | 
					
						
							| 
									
										
										
										
											2017-09-09 12:06:15 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-04 19:33:39 -04:00
										 |  |  | })(); |