From 524b6abe238d0240b517cb59e5dbb10153e29791 Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Thu, 30 Nov 2023 09:27:01 +0100 Subject: [PATCH] Admin report: autocomplete pages --- action.php | 21 ++++++++++++++++----- script.js | 10 ++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/action.php b/action.php index ff1efac..7c01250 100644 --- a/action.php +++ b/action.php @@ -90,12 +90,23 @@ public function handleAjaxAutocomplete(Event $event) /** @var helper_plugin_acknowledge $hlp */ $hlp = $this->loadHelper('acknowledge'); - $knownUsers = $hlp->getUsers(); + $found = []; + + if ($INPUT->has('user')) { + $search = $INPUT->str('user'); + $knownUsers = $hlp->getUsers(); + $found = array_filter($knownUsers, function ($user) use ($search) { + return (strstr(strtolower($user['label']), strtolower($search))) !== false ? $user : null; + }); + } - $search = $INPUT->str('user'); - $found = array_filter($knownUsers, function ($user) use ($search) { - return (strstr(strtolower($user['label']), strtolower($search))) !== false ? $user : null; - }); + if ($INPUT->has('pg')) { + $search = $INPUT->str('pg'); + $pages = ft_pageLookup($search); + $found = array_map(function ($id, $title) { + return ['value' => $id, 'label' => $title ?? $id]; + }, array_keys($pages), array_values($pages)); + } header('Content-Type: application/json'); diff --git a/script.js b/script.js index a3d956a..fac802c 100644 --- a/script.js +++ b/script.js @@ -15,6 +15,16 @@ jQuery(function () { }, minLength: 1 }); + $form.find('input[name="pg"]') + .autocomplete({ + source: function (request, response) { + jQuery.getJSON(DOKU_BASE + 'lib/exe/ajax.php?call=plugin_acknowledge_autocomplete', { + pg: request.term, + sectok: $form.find('input[name="sectok"]').val() + }, response); + }, + minLength: 3 + }); } const $form = jQuery('.dokuwiki.mode_admin div.plugin_acknowledgement_admin form#acknowledge__user-autocomplete');