From 6a50afd9529b3649d503a14d16bdd33dc2eb3738 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 28 Jul 2018 17:02:48 +0200 Subject: [PATCH] #126, "show recent notes" now work in relations dialog --- src/public/javascripts/dialogs/labels.js | 6 ++--- src/public/javascripts/dialogs/relations.js | 26 +++++++++++---------- src/views/index.ejs | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/public/javascripts/dialogs/labels.js b/src/public/javascripts/dialogs/labels.js index 7855334a5..2b39eb924 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 afc9c7811..0d0d74830 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'); - $(this).parent().find('.relation-target-note-id').autocomplete("search", ""); + await initAutocomplete($autocomplete); + + $autocomplete.autocomplete("search", ""); }); export default { diff --git a/src/views/index.ejs b/src/views/index.ejs index 0c4fa2208..8fcfbb422 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;"> - +