Skip to content

Build your personal knowledge base with Trilium Notes

simplification of "add link" dialog

zadamb685d7ffb578
diff --git a/package-lock.json b/package-lock.json
index 87fd68a1de..a02db234f3 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "trilium",
- "version": "0.36.2",
+ "version": "0.36.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js
index 8a5ba65cd4..b99608ce9e 100644
--- a/src/public/javascripts/dialogs/add_link.js
+++ b/src/public/javascripts/dialogs/add_link.js
@@ -1,4 +1,3 @@
-import cloningService from '../services/cloning.js';
import linkService from '../services/link.js';
import noteDetailService from '../services/note_detail.js';
import treeUtils from '../services/tree_utils.js';
@@ -9,49 +8,18 @@ const $dialog = $("#add-link-dialog");
const $form = $("#add-link-form");
const $autoComplete = $("#note-autocomplete");
const $linkTitle = $("#link-title");
-const $clonePrefix = $("#clone-prefix");
-const $linkTitleFormGroup = $("#add-link-title-form-group");
-const $prefixFormGroup = $("#add-link-prefix-form-group");
-const $linkTypeDiv = $("#add-link-type-div");
-const $linkTypes = $("input[name='add-link-type']");
-const $linkTypeHtml = $linkTypes.filter('input[value="html"]');
-
-function setLinkType(linkType) {
- $linkTypes.each(function () {
- $(this).prop('checked', $(this).val() === linkType);
- });
-
- linkTypeChanged();
-}
+const $addLinkTitleFormGroup = $("#add-link-title-form-group");
-export async function showDialogForClone() {
- showDialog('selected-to-active');
-}
-
-export async function showDialog(linkType) {
+export async function showDialog() {
utils.closeActiveDialog();
- glob.activeDialog = $dialog;
-
- if (noteDetailService.getActiveTabNoteType() === 'text') {
- $linkTypeHtml.prop('disabled', false);
+ $addLinkTitleFormGroup.toggle(!hasSelection());
- setLinkType('html');
- }
- else {
- $linkTypeHtml.prop('disabled', true);
-
- setLinkType('selected-to-active');
- }
-
- if (linkType === 'selected-to-active') {
- setLinkType(linkType);
- }
+ glob.activeDialog = $dialog;
$dialog.modal();
$autoComplete.val('').focus();
- $clonePrefix.val('');
$linkTitle.val('');
async function setDefaultLinkTitle(noteId) {
@@ -85,42 +53,23 @@ export async function showDialog(linkType) {
$form.submit(() => {
const notePath = $autoComplete.getSelectedPath();
- const noteId = treeUtils.getNoteIdFromNotePath(notePath);
if (notePath) {
- const linkType = $("input[name='add-link-type']:checked").val();
-
- if (linkType === 'html') {
- const linkTitle = $linkTitle.val();
+ const linkTitle = $linkTitle.val();
- $dialog.modal('hide');
+ $dialog.modal('hide');
- const linkHref = '#' + notePath;
- const editor = noteDetailService.getActiveEditor();
+ const linkHref = '#' + notePath;
+ const editor = noteDetailService.getActiveEditor();
- if (hasSelection()) {
- editor.execute('link', linkHref);
- }
- else {
- linkService.addLinkToEditor(linkTitle, linkHref);
- }
-
- editor.editing.view.focus();
+ if (hasSelection()) {
+ editor.execute('link', linkHref);
}
- else if (linkType === 'selected-to-active') {
- const prefix = $clonePrefix.val();
-
- cloningService.cloneNoteTo(noteId, noteDetailService.getActiveTabNoteId(), prefix);
-
- $dialog.modal('hide');
+ else {
+ linkService.addLinkToEditor(linkTitle, linkHref);
}
- else if (linkType === 'active-to-selected') {
- const prefix = $clonePrefix.val();
-
- cloningService.cloneNoteTo(noteDetailService.getActiveTabNoteId(), noteId, prefix);
- $dialog.modal('hide');
- }
+ editor.editing.view.focus();
}
else {
console.error("No path to add link.");
@@ -135,15 +84,4 @@ function hasSelection() {
const selection = model.document.selection;
return !selection.isCollapsed;
-}
-
-function linkTypeChanged() {
- const value = $linkTypes.filter(":checked").val();
-
- $linkTitleFormGroup.toggle(!hasSelection() && value === 'html');
- $prefixFormGroup.toggle(!hasSelection() && value !== 'html');
-
- $linkTypeDiv.toggle(!hasSelection());
-}
-
-$linkTypes.change(linkTypeChanged);
+}
\ No newline at end of file
diff --git a/src/views/dialogs/add_link.ejs b/src/views/dialogs/add_link.ejs
index 6cdc1493a3..95dafb0b14 100644
--- a/src/views/dialogs/add_link.ejs
+++ b/src/views/dialogs/add_link.ejs
@@ -12,20 +12,6 @@
</div>
<form id="add-link-form">
<div class="modal-body">
- <div id="add-link-type-div" class="radio">
- <label title="Add HTML link to the selected note at cursor in active note">
- <input type="radio" name="add-link-type" value="html"/>
- add normal HTML link</label>
-
- <label title="Add selected note as a child of active note">
- <input type="radio" name="add-link-type" value="selected-to-active"/>
- add selected note to active note</label>
-
- <label title="Add active note as a child of the selected note">
- <input type="radio" name="add-link-type" value="active-to-selected"/>
- add active note to selected note</label>
- </div>
-
<div class="form-group">
<label for="note-autocomplete">Note</label>
@@ -38,11 +24,6 @@
<label for="link-title">Link title</label>
<input id="link-title" class="form-control" style="width: 100%;">
</div>
-
- <div class="form-group" id="add-link-prefix-form-group" title="Cloned note will be shown in note tree with given prefix">
- <label for="clone-prefix">Prefix (optional)</label>
- <input id="clone-prefix" class="form-control" style="width: 100%;">
- </div>
</div>
<div class="modal-footer" style="display: flex; justify-content: space-between;">
<button type="submit" class="btn btn-primary">Add note link <kbd>enter</kbd></button>