mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
simplification of "add link" dialog
This commit is contained in:
parent
d87c469fbb
commit
b685d7ffb5
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "trilium",
|
"name": "trilium",
|
||||||
"version": "0.36.2",
|
"version": "0.36.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import cloningService from '../services/cloning.js';
|
|
||||||
import linkService from '../services/link.js';
|
import linkService from '../services/link.js';
|
||||||
import noteDetailService from '../services/note_detail.js';
|
import noteDetailService from '../services/note_detail.js';
|
||||||
import treeUtils from '../services/tree_utils.js';
|
import treeUtils from '../services/tree_utils.js';
|
||||||
@ -9,49 +8,18 @@ const $dialog = $("#add-link-dialog");
|
|||||||
const $form = $("#add-link-form");
|
const $form = $("#add-link-form");
|
||||||
const $autoComplete = $("#note-autocomplete");
|
const $autoComplete = $("#note-autocomplete");
|
||||||
const $linkTitle = $("#link-title");
|
const $linkTitle = $("#link-title");
|
||||||
const $clonePrefix = $("#clone-prefix");
|
const $addLinkTitleFormGroup = $("#add-link-title-form-group");
|
||||||
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) {
|
export async function showDialog() {
|
||||||
$linkTypes.each(function () {
|
|
||||||
$(this).prop('checked', $(this).val() === linkType);
|
|
||||||
});
|
|
||||||
|
|
||||||
linkTypeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function showDialogForClone() {
|
|
||||||
showDialog('selected-to-active');
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function showDialog(linkType) {
|
|
||||||
utils.closeActiveDialog();
|
utils.closeActiveDialog();
|
||||||
|
|
||||||
|
$addLinkTitleFormGroup.toggle(!hasSelection());
|
||||||
|
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
if (noteDetailService.getActiveTabNoteType() === 'text') {
|
|
||||||
$linkTypeHtml.prop('disabled', false);
|
|
||||||
|
|
||||||
setLinkType('html');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$linkTypeHtml.prop('disabled', true);
|
|
||||||
|
|
||||||
setLinkType('selected-to-active');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (linkType === 'selected-to-active') {
|
|
||||||
setLinkType(linkType);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dialog.modal();
|
$dialog.modal();
|
||||||
|
|
||||||
$autoComplete.val('').focus();
|
$autoComplete.val('').focus();
|
||||||
$clonePrefix.val('');
|
|
||||||
$linkTitle.val('');
|
$linkTitle.val('');
|
||||||
|
|
||||||
async function setDefaultLinkTitle(noteId) {
|
async function setDefaultLinkTitle(noteId) {
|
||||||
@ -85,42 +53,23 @@ export async function showDialog(linkType) {
|
|||||||
|
|
||||||
$form.submit(() => {
|
$form.submit(() => {
|
||||||
const notePath = $autoComplete.getSelectedPath();
|
const notePath = $autoComplete.getSelectedPath();
|
||||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
|
||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
const linkType = $("input[name='add-link-type']:checked").val();
|
const linkTitle = $linkTitle.val();
|
||||||
|
|
||||||
if (linkType === 'html') {
|
$dialog.modal('hide');
|
||||||
const linkTitle = $linkTitle.val();
|
|
||||||
|
|
||||||
$dialog.modal('hide');
|
const linkHref = '#' + notePath;
|
||||||
|
const editor = noteDetailService.getActiveEditor();
|
||||||
|
|
||||||
const linkHref = '#' + notePath;
|
if (hasSelection()) {
|
||||||
const editor = noteDetailService.getActiveEditor();
|
editor.execute('link', linkHref);
|
||||||
|
|
||||||
if (hasSelection()) {
|
|
||||||
editor.execute('link', linkHref);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
linkService.addLinkToEditor(linkTitle, linkHref);
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.editing.view.focus();
|
|
||||||
}
|
}
|
||||||
else if (linkType === 'selected-to-active') {
|
else {
|
||||||
const prefix = $clonePrefix.val();
|
linkService.addLinkToEditor(linkTitle, linkHref);
|
||||||
|
|
||||||
cloningService.cloneNoteTo(noteId, noteDetailService.getActiveTabNoteId(), prefix);
|
|
||||||
|
|
||||||
$dialog.modal('hide');
|
|
||||||
}
|
}
|
||||||
else if (linkType === 'active-to-selected') {
|
|
||||||
const prefix = $clonePrefix.val();
|
|
||||||
|
|
||||||
cloningService.cloneNoteTo(noteDetailService.getActiveTabNoteId(), noteId, prefix);
|
editor.editing.view.focus();
|
||||||
|
|
||||||
$dialog.modal('hide');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error("No path to add link.");
|
console.error("No path to add link.");
|
||||||
@ -135,15 +84,4 @@ function hasSelection() {
|
|||||||
const selection = model.document.selection;
|
const selection = model.document.selection;
|
||||||
|
|
||||||
return !selection.isCollapsed;
|
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);
|
|
@ -12,20 +12,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<form id="add-link-form">
|
<form id="add-link-form">
|
||||||
<div class="modal-body">
|
<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">
|
<div class="form-group">
|
||||||
<label for="note-autocomplete">Note</label>
|
<label for="note-autocomplete">Note</label>
|
||||||
|
|
||||||
@ -38,11 +24,6 @@
|
|||||||
<label for="link-title">Link title</label>
|
<label for="link-title">Link title</label>
|
||||||
<input id="link-title" class="form-control" style="width: 100%;">
|
<input id="link-title" class="form-control" style="width: 100%;">
|
||||||
</div>
|
</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>
|
||||||
<div class="modal-footer" style="display: flex; justify-content: space-between;">
|
<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>
|
<button type="submit" class="btn btn-primary">Add note link <kbd>enter</kbd></button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user