From af5c64045b436357006500afb448b266d927e65a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 6 Apr 2023 15:51:09 +0300 Subject: [PATCH] add simple autocompleter for tags --- classes/article.php | 13 +++++++------ js/Article.js | 28 ++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/classes/article.php b/classes/article.php index 609ddeebe..5bddf3bdb 100755 --- a/classes/article.php +++ b/classes/article.php @@ -239,8 +239,7 @@ class Article extends Handler_Protected { print json_encode(["id" => (int)$id, "tags" => $this->_get_tags($id)]); } - - /*function completeTags() { + function completeTags() { $search = clean($_REQUEST["search"]); $sth = $this->pdo->prepare("SELECT DISTINCT tag_name FROM ttrss_tags @@ -250,12 +249,14 @@ class Article extends Handler_Protected { $sth->execute([$_SESSION['uid'], "$search%"]); - print ""; - }*/ + + print json_encode($results); + } function assigntolabel(): void { $this->_label_ops(true); diff --git a/js/Article.js b/js/Article.js index 703b634d5..5f3a8c2e9 100644 --- a/js/Article.js +++ b/js/Article.js @@ -333,6 +333,20 @@ const Article = { return false; }, + autocompleteInject: function(elem, targetId) { + const target = App.byId(targetId); + + if (!target) + return; + + target.value = target.value.split(',') + .slice(0, -1) + .map((w) => w.trim()) + .concat([elem.innerText]) + .join(', ') + ', '; + + target.focus(); + }, editTags: function (id) { const dialog = new fox.SingleUseDialog({ title: __("Article tags"), @@ -348,7 +362,7 @@ const Article = {
- +