Skip to content

Build your personal knowledge base with Trilium Notes

#126, "show recent notes" now work in relations dialog

azivner6a50afd9529b
diff --git a/src/public/javascripts/dialogs/labels.js b/src/public/javascripts/dialogs/labels.js
index 7855334a54..2b39eb9247 100644
--- a/src/public/javascripts/dialogs/labels.js
+++ b/src/public/javascripts/dialogs/labels.js
@@ -167,9 +167,9 @@ async function showDialog() {
});
}
-ko.applyBindings(labelsModel, document.getElementById('labels-dialog'));
+ko.applyBindings(labelsModel, $dialog[0]);
-$(document).on('focus', '.label-name', function (e) {
+$dialog.on('focus', '.label-name', function (e) {
if (!$(this).hasClass("ui-autocomplete-input")) {
$(this).autocomplete({
// shouldn't be required and autocomplete should just accept array of strings, but that fails
@@ -187,7 +187,7 @@ $(document).on('focus', '.label-name', function (e) {
$(this).autocomplete("search", $(this).val());
});
-$(document).on('focus', '.label-value', async function (e) {
+$dialog.on('focus', '.label-value', async function (e) {
if (!$(this).hasClass("ui-autocomplete-input")) {
const labelName = $(this).parent().parent().find('.label-name').val();
diff --git a/src/public/javascripts/dialogs/relations.js b/src/public/javascripts/dialogs/relations.js
index afc9c7811b..0d0d74830e 100644
--- a/src/public/javascripts/dialogs/relations.js
+++ b/src/public/javascripts/dialogs/relations.js
@@ -1,9 +1,6 @@
import noteDetailService from '../services/note_detail.js';
import server from '../services/server.js';
import infoService from "../services/info.js";
-import treeService from "../services/tree.js";
-import linkService from "../services/link.js";
-import treeUtils from "../services/tree_utils.js";
const $dialog = $("#relations-dialog");
const $saveRelationsButton = $("#save-relations-button");
@@ -177,7 +174,7 @@ async function showDialog() {
ko.applyBindings(relationsModel, document.getElementById('relations-dialog'));
-$(document).on('focus', '.relation-name', function (e) {
+$dialog.on('focus', '.relation-name', function (e) {
if (!$(this).hasClass("ui-autocomplete-input")) {
$(this).autocomplete({
// shouldn't be required and autocomplete should just accept array of strings, but that fails
@@ -195,10 +192,10 @@ $(document).on('focus', '.relation-name', function (e) {
$(this).autocomplete("search", $(this).val());
});
-$(document).on('focus', '.relation-target-note-id', async function (e) {
- if (!$(this).hasClass("ui-autocomplete-input")) {
- await $(this).autocomplete({
- source: async function(request, response) {
+async function initAutocomplete($el) {
+ if (!$el.hasClass("ui-autocomplete-input")) {
+ await $el.autocomplete({
+ source: async function (request, response) {
const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
if (result.length > 0) {
@@ -224,15 +221,20 @@ $(document).on('focus', '.relation-target-note-id', async function (e) {
},
});
}
+}
+
+$dialog.on('focus', '.relation-target-note-id', async function (e) {
+ await initAutocomplete($(this));
$(this).autocomplete("search", $(this).val());
});
-$(document).on('click', '.relations-show-recent-notes', function () {
- alert("HI!");
- alert($(this).parent().find('.relation-target-note-id').length);
+$dialog.on('click', '.relations-show-recent-notes', async function () {
+ const $autocomplete = $(this).parent().find('.relation-target-note-id');
+
+ await initAutocomplete($autocomplete);
- $(this).parent().find('.relation-target-note-id').autocomplete("search", "");
+ $autocomplete.autocomplete("search", "");
});
export default {
diff --git a/src/views/index.ejs b/src/views/index.ejs
index 0c4fa22082..8fcfbb4227 100644
--- a/src/views/index.ejs
+++ b/src/views/index.ejs
@@ -626,7 +626,7 @@
data-bind="value: targetNoteId, valueUpdate: 'blur', event: { blur: $parent.relationChanged }"
style="width: 300px;">
- <span class="input-group-addon" class="relations-show-recent-notes" title="Show recent notes" style="background: url('/images/icons/clock-16.png') no-repeat center; cursor: pointer;"></span>
+ <span class="input-group-addon relations-show-recent-notes" title="Show recent notes" style="background: url('/images/icons/clock-16.png') no-repeat center; cursor: pointer;"></span>
</div>
</td>
<td title="Delete" style="padding: 13px;">