| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  | function moveBeforeNode(node, beforeNode) { | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							|  |  |  |         url: baseUrl + 'notes/' + node.key + '/moveBefore/' + beforeNode.key, | 
					
						
							|  |  |  |         type: 'PUT', | 
					
						
							|  |  |  |         contentType: "application/json", | 
					
						
							|  |  |  |         success: function () { | 
					
						
							|  |  |  |             node.moveTo(beforeNode, 'before'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function moveAfterNode(node, afterNode) { | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							|  |  |  |         url: baseUrl + 'notes/' + node.key + '/moveAfter/' + afterNode.key, | 
					
						
							|  |  |  |         type: 'PUT', | 
					
						
							|  |  |  |         contentType: "application/json", | 
					
						
							|  |  |  |         success: function () { | 
					
						
							|  |  |  |             node.moveTo(afterNode, 'after'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function moveToNode(node, toNode) { | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							|  |  |  |         url: baseUrl + 'notes/' + node.key + '/moveTo/' + toNode.key, | 
					
						
							|  |  |  |         type: 'PUT', | 
					
						
							|  |  |  |         contentType: "application/json", | 
					
						
							|  |  |  |         success: function (result) { | 
					
						
							|  |  |  |             node.moveTo(toNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             toNode.setExpanded(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             toNode.folder = true; | 
					
						
							|  |  |  |             toNode.renderTitle(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  | function deleteNode(node) { | 
					
						
							|  |  |  |     if (confirm('Are you sure you want to delete note "' + node.title + '"?')) { | 
					
						
							|  |  |  |         $.ajax({ | 
					
						
							|  |  |  |             url: baseUrl + 'notes/' + node.key, | 
					
						
							|  |  |  |             type: 'DELETE', | 
					
						
							|  |  |  |             success: function () { | 
					
						
							|  |  |  |                 if (node.getParent() !== null && node.getParent().getChildren().length <= 1) { | 
					
						
							|  |  |  |                     node.getParent().folder = false; | 
					
						
							|  |  |  |                     node.getParent().renderTitle(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 globalAllNoteIds = globalAllNoteIds.filter(e => e !== node.key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // remove from recent notes
 | 
					
						
							| 
									
										
										
										
											2017-09-06 21:11:19 -04:00
										 |  |  |                 globalRecentNotes = globalRecentNotes.filter(note => note !== node.key); | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let next = node.getNextSibling(); | 
					
						
							|  |  |  |                 if (!next) { | 
					
						
							|  |  |  |                     next = node.getParent(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 node.remove(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // activate next element after this one is deleted so we don't lose focus
 | 
					
						
							|  |  |  |                 next.setActive(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 13:27:54 -04:00
										 |  |  | function getParentKey(node) { | 
					
						
							|  |  |  |     return (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 22:43:02 -04:00
										 |  |  | function getParentEncryption(node) { | 
					
						
							|  |  |  |     return node.getParent() === null ? 0 : node.getParent().data.encryption; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  | const keybindings = { | 
					
						
							|  |  |  |     "insert": function(node) { | 
					
						
							| 
									
										
										
										
											2017-09-04 13:27:54 -04:00
										 |  |  |         const parentKey = getParentKey(node); | 
					
						
							| 
									
										
										
										
											2017-09-08 22:43:02 -04:00
										 |  |  |         const encryption = getParentEncryption(node); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 22:43:02 -04:00
										 |  |  |         createNote(node, parentKey, 'after', encryption); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     "ctrl+insert": function(node) { | 
					
						
							| 
									
										
										
										
											2017-09-08 22:43:02 -04:00
										 |  |  |         createNote(node, node.key, 'into', node.data.encryption); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     "del": function(node) { | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  |         deleteNode(node); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     "shift+up": function(node) { | 
					
						
							| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  |         const beforeNode = node.getPrevSibling(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (beforeNode !== null) { | 
					
						
							|  |  |  |             moveBeforeNode(node, beforeNode); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "shift+down": function(node) { | 
					
						
							| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  |         let afterNode = node.getNextSibling(); | 
					
						
							|  |  |  |         if (afterNode !== null) { | 
					
						
							|  |  |  |             moveAfterNode(node, afterNode); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "shift+left": function(node) { | 
					
						
							|  |  |  |         if (node.getParent() !== null) { | 
					
						
							|  |  |  |             $.ajax({ | 
					
						
							|  |  |  |                 url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key, | 
					
						
							|  |  |  |                 type: 'PUT', | 
					
						
							|  |  |  |                 contentType: "application/json", | 
					
						
							|  |  |  |                 success: function() { | 
					
						
							|  |  |  |                     if (node.getParent() !== null && node.getParent().getChildren().length <= 1) { | 
					
						
							|  |  |  |                         node.getParent().folder = false; | 
					
						
							|  |  |  |                         node.getParent().renderTitle(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     node.moveTo(node.getParent(), 'after'); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "shift+right": function(node) { | 
					
						
							| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  |         let toNode = node.getPrevSibling(); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  |         if (toNode !== null) { | 
					
						
							|  |  |  |             moveToNode(node, toNode); | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     "return": function(node) { | 
					
						
							|  |  |  |         // doesn't work :-/
 | 
					
						
							|  |  |  |         $('#noteDetail').summernote('focus'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 18:50:56 -04:00
										 |  |  | let globalAllNoteIds = []; | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  | let globalTree; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getNodeByKey(noteId) { | 
					
						
							|  |  |  |     return globalTree.fancytree('getNodeByKey', noteId); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getFullName(noteId) { | 
					
						
							|  |  |  |     let note = getNodeByKey(noteId); | 
					
						
							|  |  |  |     const path = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (note) { | 
					
						
							|  |  |  |         path.push(note.title); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         note = note.getParent(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // remove "root" element
 | 
					
						
							|  |  |  |     path.pop(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return path.reverse().join(" > "); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  | let globalClipboardNoteId = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | $(function(){ | 
					
						
							| 
									
										
										
										
											2017-08-22 21:23:10 -04:00
										 |  |  |     $.get(baseUrl + 'tree').then(resp => { | 
					
						
							|  |  |  |         const notes = resp.notes; | 
					
						
							| 
									
										
										
										
											2017-08-22 21:32:03 -04:00
										 |  |  |         let startNoteId = resp.start_note_id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (document.location.hash) { | 
					
						
							|  |  |  |             startNoteId = document.location.hash.substr(1); // strip initial #
 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-22 21:23:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |         function copyTitle(notes) { | 
					
						
							| 
									
										
										
										
											2017-08-29 22:25:58 -04:00
										 |  |  |             for (const note of notes) { | 
					
						
							| 
									
										
										
										
											2017-09-03 18:50:56 -04:00
										 |  |  |                 globalAllNoteIds.push(note.note_id); | 
					
						
							| 
									
										
										
										
											2017-08-27 10:30:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 23:13:39 -04:00
										 |  |  |                 if (note.encryption > 0) { | 
					
						
							|  |  |  |                     note.title = "[encrypted]"; | 
					
						
							| 
									
										
										
										
											2017-09-08 23:14:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     note.extraClasses = "encrypted"; | 
					
						
							| 
									
										
										
										
											2017-09-06 23:13:39 -04:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else { | 
					
						
							|  |  |  |                     note.title = note.note_title; | 
					
						
							| 
									
										
										
										
											2017-08-15 21:29:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 23:13:39 -04:00
										 |  |  |                     if (note.is_clone) { | 
					
						
							|  |  |  |                         note.title += " (clone)"; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2017-08-15 21:29:12 -04:00
										 |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |                 note.key = note.note_id; | 
					
						
							|  |  |  |                 note.expanded = note.is_expanded; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (note.children && note.children.length > 0) { | 
					
						
							|  |  |  |                     copyTitle(note.children); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         copyTitle(notes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         function setExpanded(note_id, is_expanded) { | 
					
						
							|  |  |  |             expanded_num = is_expanded ? 1 : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $.ajax({ | 
					
						
							|  |  |  |                 url: baseUrl + 'notes/' + note_id + '/expanded/' + expanded_num, | 
					
						
							|  |  |  |                 type: 'PUT', | 
					
						
							|  |  |  |                 contentType: "application/json", | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |                 success: function(result) {} | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-03 15:08:17 -04:00
										 |  |  |         globalTree = $("#tree"); | 
					
						
							|  |  |  |         globalTree.fancytree({ | 
					
						
							| 
									
										
										
										
											2017-08-22 21:23:10 -04:00
										 |  |  |             autoScroll: true, | 
					
						
							| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  |             extensions: ["hotkeys", "filter", "dnd"], | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |             source: notes, | 
					
						
							|  |  |  |             activate: function(event, data){ | 
					
						
							| 
									
										
										
										
											2017-08-15 21:29:12 -04:00
										 |  |  |                 const node = data.node.data; | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-23 21:43:02 -04:00
										 |  |  |                 saveNoteIfChanged(() => loadNote(node.note_id)); | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             expand: function(event, data) { | 
					
						
							|  |  |  |                 setExpanded(data.node.key, true); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             collapse: function(event, data) { | 
					
						
							|  |  |  |                 setExpanded(data.node.key, false); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-08-22 21:23:10 -04:00
										 |  |  |             init: function(event, data) { | 
					
						
							|  |  |  |                 if (startNoteId) { | 
					
						
							|  |  |  |                     data.tree.activateKey(startNoteId); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-09-05 23:48:41 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 $(window).resize(); | 
					
						
							| 
									
										
										
										
											2017-08-22 21:23:10 -04:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |             hotkeys: { | 
					
						
							| 
									
										
										
										
											2017-08-23 20:09:28 -04:00
										 |  |  |                 keydown: keybindings | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             filter: { | 
					
						
							|  |  |  |                 autoApply: true,   // Re-apply last filter if lazy data is loaded
 | 
					
						
							|  |  |  |                 autoExpand: true, // Expand all branches that contain matches while filtered
 | 
					
						
							|  |  |  |                 counter: false,     // Show a badge with number of matching child nodes near parent icons
 | 
					
						
							|  |  |  |                 fuzzy: false,      // Match single characters in order, e.g. 'fb' will match 'FooBar'
 | 
					
						
							|  |  |  |                 hideExpandedCounter: true,  // Hide counter badge if parent is expanded
 | 
					
						
							|  |  |  |                 hideExpanders: false,       // Hide expanders if all child nodes are hidden by filter
 | 
					
						
							|  |  |  |                 highlight: true,   // Highlight matches by wrapping inside <mark> tags
 | 
					
						
							|  |  |  |                 leavesOnly: false, // Match end nodes only
 | 
					
						
							|  |  |  |                 nodata: true,      // Display a 'no data' status node if result is empty
 | 
					
						
							|  |  |  |                 mode: "hide"       // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
 | 
					
						
							| 
									
										
										
										
											2017-09-04 12:02:34 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             dnd: { | 
					
						
							|  |  |  |                 autoExpandMS: 600, | 
					
						
							|  |  |  |                 draggable: { // modify default jQuery draggable options
 | 
					
						
							|  |  |  |                     zIndex: 1000, | 
					
						
							|  |  |  |                     scroll: false, | 
					
						
							|  |  |  |                     containment: "parent", | 
					
						
							|  |  |  |                     revert: "invalid" | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
 | 
					
						
							|  |  |  |                 preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 dragStart: function(node, data) { | 
					
						
							|  |  |  |                     // This function MUST be defined to enable dragging for the tree.
 | 
					
						
							|  |  |  |                     // Return false to cancel dragging of node.
 | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 dragEnter: function(node, data) { | 
					
						
							|  |  |  |                     /* data.otherNode may be null for non-fancytree droppables. | 
					
						
							|  |  |  |                     * Return false to disallow dropping on node. In this case | 
					
						
							|  |  |  |                     * dragOver and dragLeave are not called. | 
					
						
							|  |  |  |                     * Return 'over', 'before, or 'after' to force a hitMode. | 
					
						
							|  |  |  |                     * Return ['before', 'after'] to restrict available hitModes. | 
					
						
							|  |  |  |                     * Any other return value will calc the hitMode from the cursor position. | 
					
						
							|  |  |  |                     */ | 
					
						
							|  |  |  |                     // Prevent dropping a parent below another parent (only sort
 | 
					
						
							|  |  |  |                     // nodes under the same parent):
 | 
					
						
							|  |  |  |                     //    if(node.parent !== data.otherNode.parent){
 | 
					
						
							|  |  |  |                     //      return false;
 | 
					
						
							|  |  |  |                     //    }
 | 
					
						
							|  |  |  |                     // Don't allow dropping *over* a node (would create a child). Just
 | 
					
						
							|  |  |  |                     // allow changing the order:
 | 
					
						
							|  |  |  |                     //    return ["before", "after"];
 | 
					
						
							|  |  |  |                     // Accept everything:
 | 
					
						
							|  |  |  |                     return true; | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 dragExpand: function(node, data) { | 
					
						
							|  |  |  |                   // return false to prevent auto-expanding data.node on hover
 | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 dragOver: function(node, data) { | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 dragLeave: function(node, data) { | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 dragStop: function(node, data) { | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 dragDrop: function(node, data) { | 
					
						
							|  |  |  |                     // This function MUST be defined to enable dropping of items on the tree.
 | 
					
						
							|  |  |  |                     // data.hitMode is 'before', 'after', or 'over'.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (data.hitMode === "before") { | 
					
						
							|  |  |  |                         moveBeforeNode(data.otherNode, node); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     else if (data.hitMode === "after") { | 
					
						
							|  |  |  |                         moveAfterNode(data.otherNode, node); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     else if (data.hitMode === "over") { | 
					
						
							|  |  |  |                         moveToNode(data.otherNode, node); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     else { | 
					
						
							|  |  |  |                         throw new Exception("Unknown hitMode=" + data.hitMode); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         globalTree.contextmenu({ | 
					
						
							|  |  |  |             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: "----"}, | 
					
						
							|  |  |  |                 {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: function (event, ui) { | 
					
						
							|  |  |  |                 const node = $.ui.fancytree.getNode(ui.target); | 
					
						
							|  |  |  |                 // Modify menu entries depending on node status
 | 
					
						
							|  |  |  |                 globalTree.contextmenu("enableEntry", "pasteAfter", globalClipboardNoteId !== null); | 
					
						
							|  |  |  |                 globalTree.contextmenu("enableEntry", "pasteInto", globalClipboardNoteId !== null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // Activate node on right-click
 | 
					
						
							|  |  |  |                 node.setActive(); | 
					
						
							|  |  |  |                 // Disable tree keyboard handling
 | 
					
						
							|  |  |  |                 ui.menu.prevKeyboard = node.tree.options.keyboard; | 
					
						
							|  |  |  |                 node.tree.options.keyboard = false; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-09-04 13:27:54 -04:00
										 |  |  |             close: function (event, ui) {}, | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  |             select: function (event, ui) { | 
					
						
							|  |  |  |                 const node = $.ui.fancytree.getNode(ui.target); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 13:27:54 -04:00
										 |  |  |                 if (ui.cmd === "insertNoteHere") { | 
					
						
							| 
									
										
										
										
											2017-09-08 22:43:02 -04:00
										 |  |  |                     const parentKey = getParentKey(node); | 
					
						
							|  |  |  |                     const encryption = getParentEncryption(node); | 
					
						
							| 
									
										
										
										
											2017-09-04 13:27:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 22:43:02 -04:00
										 |  |  |                     createNote(node, parentKey, 'after', encryption); | 
					
						
							| 
									
										
										
										
											2017-09-04 13:27:54 -04:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else if (ui.cmd === "insertChildNote") { | 
					
						
							|  |  |  |                     createNote(node, node.key, 'into'); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else if (ui.cmd === "cut") { | 
					
						
							| 
									
										
										
										
											2017-09-04 13:22:24 -04:00
										 |  |  |                     globalClipboardNoteId = node.key; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else if (ui.cmd === "pasteAfter") { | 
					
						
							|  |  |  |                     const subjectNode = getNodeByKey(globalClipboardNoteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     moveAfterNode(subjectNode, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     globalClipboardNoteId = null; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else if (ui.cmd === "pasteInto") { | 
					
						
							|  |  |  |                     const subjectNode = getNodeByKey(globalClipboardNoteId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     moveToNode(subjectNode, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     globalClipboardNoteId = null; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else if (ui.cmd === "delete") { | 
					
						
							|  |  |  |                     deleteNode(node); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else { | 
					
						
							|  |  |  |                     console.log("Unknown command: " + ui.cmd); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-06-11 16:04:07 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $("input[name=search]").keyup(function (e) { | 
					
						
							| 
									
										
										
										
											2017-08-29 22:58:44 -04:00
										 |  |  |     const searchString = $(this).val(); | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 22:58:44 -04:00
										 |  |  |     if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchString) === "") { | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  |         $("button#btnResetSearch").click(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-29 22:58:44 -04:00
										 |  |  |     if (e && e.which === $.ui.keyCode.ENTER) { | 
					
						
							|  |  |  |         $.get(baseUrl + 'notes?search=' + searchString).then(resp => { | 
					
						
							|  |  |  |             console.log("search: ", resp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Pass a string to perform case insensitive matching
 | 
					
						
							| 
									
										
										
										
											2017-09-06 21:34:54 -04:00
										 |  |  |             const tree = globalTree.fancytree("getTree"); | 
					
						
							| 
									
										
										
										
											2017-08-29 22:58:44 -04:00
										 |  |  |             tree.filterBranches(function(node) { | 
					
						
							|  |  |  |                 return resp.includes(node.data.note_id); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  | }).focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $("button#btnResetSearch").click(function () { | 
					
						
							|  |  |  |     $("input[name=search]").val(""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 21:34:54 -04:00
										 |  |  |     const tree = globalTree.fancytree("getTree"); | 
					
						
							| 
									
										
										
										
											2017-08-28 23:10:04 -04:00
										 |  |  |     tree.clearFilter(); | 
					
						
							| 
									
										
										
										
											2017-08-29 20:58:53 -04:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function collapseTree() { | 
					
						
							| 
									
										
										
										
											2017-09-06 21:34:54 -04:00
										 |  |  |     globalTree.fancytree("getRootNode").visit(function(node){ | 
					
						
							| 
									
										
										
										
											2017-08-29 20:58:53 -04:00
										 |  |  |         node.setExpanded(false); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(document).bind('keydown', 'alt+c', collapseTree); |