From 68d82ef82e54bba973be1acad26081b0e3881b6b Mon Sep 17 00:00:00 2001 From: Matias De lellis Date: Mon, 11 Nov 2019 20:58:35 -0300 Subject: [PATCH] Fill current tags and selection --- js/qn-dialogs.js | 16 ++++++++++------ js/script.js | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/qn-dialogs.js b/js/qn-dialogs.js index 07e5f7a..9f702e5 100644 --- a/js/qn-dialogs.js +++ b/js/qn-dialogs.js @@ -24,7 +24,7 @@ */ const QnDialogs = { - tags: function (callback) { + tags: function (currentTags, selectedTags, callback) { return $.when(this._getMessageTemplate()).then(function ($tmpl) { var dialogName = 'qn-dialog-content'; var dialogId = '#' + dialogName; @@ -45,11 +45,15 @@ const QnDialogs = { input.select2({ placeholder: t('quicknotes', 'Enter tag name'), - tokenSeparators: [',', ' '], - tags: true, - allowClear: true + tokenSeparators: ',', + tags: currentTags.map(function (value) { return value.name; }), + allowClear: true, + toggleSelect: true }); + input.val(selectedTags.map(function (value) { return value.name; })); + input.trigger("change"); + // wrap callback in _.once(): // only call callback once and not twice (button handler and close // event) but call it for the close event, if ESC or the x is hit @@ -62,7 +66,7 @@ const QnDialogs = { click: function () { input.select2('close'); if (callback !== undefined) { - callback(false, input.val()); + callback(false, input.select2("val")); } $(dialogId).ocdialog('close'); } @@ -71,7 +75,7 @@ const QnDialogs = { click: function () { input.select2('close'); if (callback !== undefined) { - callback(true, input.val()); + callback(true, input.select2("val")); } $(dialogId).ocdialog('close'); }, diff --git a/js/script.js b/js/script.js index 64e0c9f..aac2628 100644 --- a/js/script.js +++ b/js/script.js @@ -615,9 +615,13 @@ View.prototype = { // handle tags button. $('#modal-note-div #tag-button').click(function (event) { event.stopPropagation(); + var id = $("#modal-note-div .quicknote").data('id'); + self._notes.load(id); QnDialogs.tags( + self._tags.getAll(), + self._notes.getActive().tags, function(result, value) { - if (result === true && value) { + if (result === true) { OC.Notification.showTemporary("TEST TAGS DIALOG OK"); } else {