mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	allow deleting notes from note actions button, closes #3131
This commit is contained in:
		| @@ -68,7 +68,7 @@ async function moveToParentNote(branchIdsToMove, newParentBranchId) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| async function deleteNotes(branchIdsToDelete) { | ||||
| async function deleteNotes(branchIdsToDelete, forceDeleteAllClones = false) { | ||||
|     branchIdsToDelete = filterRootNote(branchIdsToDelete); | ||||
|  | ||||
|     if (branchIdsToDelete.length === 0) { | ||||
| @@ -83,7 +83,7 @@ async function deleteNotes(branchIdsToDelete) { | ||||
|     } | ||||
|     else { | ||||
|         ({proceed, deleteAllClones, eraseNotes} = await new Promise(res => | ||||
|             appContext.triggerCommand('showDeleteNotesDialog', {branchIdsToDelete, callback: res}))); | ||||
|             appContext.triggerCommand('showDeleteNotesDialog', {branchIdsToDelete, callback: res, forceDeleteAllClones}))); | ||||
|     } | ||||
|  | ||||
|     if (!proceed) { | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| import NoteContextAwareWidget from "../note_context_aware_widget.js"; | ||||
| import utils from "../../services/utils.js"; | ||||
| import branchService from "../../services/branches.js"; | ||||
|  | ||||
| const TPL = ` | ||||
| <div class="dropdown note-actions"> | ||||
| @@ -30,6 +31,7 @@ const TPL = ` | ||||
|         <a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"><kbd data-command="openNoteExternally"></kbd> Open note externally</a> | ||||
|         <a class="dropdown-item import-files-button">Import files</a> | ||||
|         <a class="dropdown-item export-note-button">Export note</a> | ||||
|         <a class="dropdown-item delete-note-button">Delete note</a> | ||||
|         <a data-trigger-command="printActiveNote" class="dropdown-item print-active-note-button"><kbd data-command="printActiveNote"></kbd> Print note</a> | ||||
|     </div> | ||||
| </div>`; | ||||
| @@ -65,6 +67,15 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { | ||||
|         this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle')); | ||||
|  | ||||
|         this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button"); | ||||
|  | ||||
|         this.$deleteNoteButton = this.$widget.find(".delete-note-button"); | ||||
|         this.$deleteNoteButton.on("click", () => { | ||||
|             if (this.note.noteId === 'root') { | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             branchService.deleteNotes([this.note.getParentBranches()[0].branchId], true); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     refreshWithNote(note) { | ||||
|   | ||||
| @@ -97,7 +97,7 @@ export default class DeleteNotesDialog extends BasicWidget { | ||||
|  | ||||
|             this.resolve({ | ||||
|                 proceed: true, | ||||
|                 deleteAllClones: this.isDeleteAllClonesChecked(), | ||||
|                 deleteAllClones: this.forceDeleteAllClones || this.isDeleteAllClonesChecked(), | ||||
|                 eraseNotes: this.isEraseNotesChecked() | ||||
|             }); | ||||
|         }); | ||||
| @@ -108,7 +108,7 @@ export default class DeleteNotesDialog extends BasicWidget { | ||||
|     async renderDeletePreview() { | ||||
|         const response = await server.post('delete-notes-preview', { | ||||
|             branchIdsToDelete: this.branchIds, | ||||
|             deleteAllClones: this.isDeleteAllClonesChecked() | ||||
|             deleteAllClones: this.forceDeleteAllClones || this.isDeleteAllClonesChecked() | ||||
|         }); | ||||
|  | ||||
|         this.$deleteNotesList.empty(); | ||||
| @@ -143,14 +143,18 @@ export default class DeleteNotesDialog extends BasicWidget { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     async showDeleteNotesDialogEvent({branchIdsToDelete, callback}) { | ||||
|     async showDeleteNotesDialogEvent({branchIdsToDelete, callback, forceDeleteAllClones}) { | ||||
|         this.branchIds = branchIdsToDelete; | ||||
|         this.forceDeleteAllClones = forceDeleteAllClones; | ||||
|  | ||||
|         await this.renderDeletePreview(); | ||||
|  | ||||
|         utils.openDialog(this.$widget); | ||||
|  | ||||
|         this.$deleteAllClones.prop("checked", false); | ||||
|         this.$deleteAllClones | ||||
|             .prop("checked", !!forceDeleteAllClones) | ||||
|             .prop("disabled", !!forceDeleteAllClones); | ||||
|  | ||||
|         this.$eraseNotes.prop("checked", false); | ||||
|  | ||||
|         this.resolve = callback; | ||||
|   | ||||
| @@ -946,7 +946,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|  | ||||
|         if (this.noteContext | ||||
|             && this.noteContext.notePath | ||||
|             && !this.noteContext.note.isDeleted | ||||
|             && !this.noteContext.note?.isDeleted | ||||
|             && !this.noteContext.notePath.includes("root/hidden") | ||||
|         ) { | ||||
|             const newActiveNode = await this.getNodeFromPath(this.noteContext.notePath); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user