Skip to content

Build your personal knowledge base with Trilium Notes

more refactoring

azivner42c21afa6257
diff --git a/src/templates/app.html b/src/templates/app.html
index 0ec6660a2c..6a9a82c745 100644
--- a/src/templates/app.html
+++ b/src/templates/app.html
@@ -38,7 +38,7 @@
</div>
</div>
- <div id="noteDetailWrapper" style="width: 750px; float: left; margin-left: 30px;">
+ <div id="noteDetailWrapper">
<div style="float: left; margin: 0 5px 5px 5px;" class="hide-toggle">
<button class="btn btn-sm"
onclick="encryptNoteAndSendToServer();"
@@ -153,19 +153,23 @@
<script src="stat/js/init.js"></script>
+ <!-- Tree scripts -->
<script src="stat/js/tree.js"></script>
- <script src="stat/js/treeutils.js"></script>
- <script src="stat/js/draganddrop.js"></script>
- <script src="stat/js/contextmenu.js"></script>
+ <script src="stat/js/tree_mutations.js"></script>
+ <script src="stat/js/tree_utils.js"></script>
+ <script src="stat/js/drag_and_drop.js"></script>
+ <script src="stat/js/context_menu.js"></script>
+ <!-- Note detail -->
<script src="stat/js/note.js"></script>
<script src="stat/js/notecase2html.js"></script>
<script src="stat/js/html2notecase.js"></script>
<script src="stat/js/encryption.js"></script>
- <script src="stat/js/recentnotes.js"></script>
- <script src="stat/js/addlink.js"></script>
- <script src="stat/js/jumptonote.js"></script>
+ <!-- dialogs -->
+ <script src="stat/js/recent_notes.js"></script>
+ <script src="stat/js/add_link.js"></script>
+ <script src="stat/js/jump_to_note.js"></script>
<script src="stat/js/utils.js"></script>
</body>
diff --git a/static/js/addlink.js b/static/js/add_link.js
similarity index 100%
rename from static/js/addlink.js
rename to static/js/add_link.js
diff --git a/static/js/contextmenu.js b/static/js/context_menu.js
similarity index 100%
rename from static/js/contextmenu.js
rename to static/js/context_menu.js
diff --git a/static/js/draganddrop.js b/static/js/drag_and_drop.js
similarity index 100%
rename from static/js/draganddrop.js
rename to static/js/drag_and_drop.js
diff --git a/static/js/jumptonote.js b/static/js/jump_to_note.js
similarity index 100%
rename from static/js/jumptonote.js
rename to static/js/jump_to_note.js
diff --git a/static/js/recentnotes.js b/static/js/recent_notes.js
similarity index 100%
rename from static/js/recentnotes.js
rename to static/js/recent_notes.js
diff --git a/static/js/tree.js b/static/js/tree.js
index 5c3f9bdc70..096b7450e0 100644
--- a/static/js/tree.js
+++ b/static/js/tree.js
@@ -1,89 +1,3 @@
-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 () {
- node.moveTo(toNode);
-
- toNode.setExpanded(true);
-
- toNode.folder = true;
- toNode.renderTitle();
- }
- });
-}
-
-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
- globalRecentNotes = globalRecentNotes.filter(note => note !== node.key);
-
- 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();
- }
- });
- }
-}
-
-function moveNodeUp(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');
- }
- });
- }
-}
-
const keybindings = {
"insert": function(node) {
const parentKey = getParentKey(node);
diff --git a/static/js/tree_mutations.js b/static/js/tree_mutations.js
new file mode 100644
index 0000000000..0a5f1d410f
--- /dev/null
+++ b/static/js/tree_mutations.js
@@ -0,0 +1,85 @@
+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 () {
+ node.moveTo(toNode);
+
+ toNode.setExpanded(true);
+
+ toNode.folder = true;
+ toNode.renderTitle();
+ }
+ });
+}
+
+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
+ globalRecentNotes = globalRecentNotes.filter(note => note !== node.key);
+
+ 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();
+ }
+ });
+ }
+}
+
+function moveNodeUp(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');
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/static/js/treeutils.js b/static/js/tree_utils.js
similarity index 100%
rename from static/js/treeutils.js
rename to static/js/tree_utils.js
diff --git a/static/style.css b/static/style.css
index 6398abb0e2..e133a523ed 100644
--- a/static/style.css
+++ b/static/style.css
@@ -8,6 +8,12 @@
background-color: #eee;
}
+#noteDetailWrapper {
+ width: 750px;
+ float: left;
+ margin-left: 30px;
+}
+
#top-message {
display: none; /* initial state is hidden */
background-color: #e0e0e0;