Skip to content

Commit

Permalink
More plumbing.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jul 5, 2024
1 parent 88dc39f commit 3d2b359
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
11 changes: 11 additions & 0 deletions module/GeebyDeeby/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,17 @@
],
],
],
'search-creator-ajax' => [
'type' => 'Literal',
'options' => [
'route' => '/Search/CreatorAjax',
'defaults' => [
'__NAMESPACE__' => 'GeebyDeeby\Controller',
'controller' => 'Search',
'action' => 'creatorAjax',
],
],
],
'series' => [
'type' => 'Segment',
'options' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function getDbTable($table)
}

/**
* Die with a JSON-encoded error message.
* Die with a JSON-encoded message.
*
* @param string $msg The message to send back.
* @param bool $success Success status
Expand Down
15 changes: 15 additions & 0 deletions module/GeebyDeeby/src/GeebyDeeby/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ protected function tokenize($q)
return explode(' ', $q);
}

/**
* Retrieve creator details by AJAX.
*
* @return mixed
*/
public function creatorAjaxAction()
{
$post = $this->params()->fromPost();
$ids = explode(',', $post['ids']);
foreach ($ids as $id) {
$response[$id] = "foo $id";
}
return $this->jsonDie($response, true);
}

/**
* Keyword results
*
Expand Down
14 changes: 10 additions & 4 deletions public/js/search.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
/*global basePath */
function setupSearch() {
let creatorsVisible = false;
let creatorsLoading = false;
const loadCreators = function () {
const loadCreators = async function () {
if (!creatorsLoading) {
creatorsLoading = true;
const ids = [];
document.querySelectorAll('.creators').forEach((element) => {
ids.push(element.dataset.itemId);
});
const uniqueIds = [...new Set(ids)];
uniqueIds.forEach((id) => {
let formData = new FormData();
formData.append('ids', uniqueIds);
const response = await fetch(basePath + "/Search/CreatorAjax", { body: formData, method: "post" });
const json = await response.json();
for (const id in json.msg) {
const text = json.msg[id];
document.querySelectorAll('.creators[data-item-id="' + id + '"]').forEach((element) => {
element.dataset.loaded = "1";
element.classList.remove("hidden");
element.querySelector('.values').innerHTML = id;
element.querySelector('.values').innerHTML = text;
});
});
};
}
};
document.querySelectorAll('.search-controls').forEach((element) => {
Expand Down

0 comments on commit 3d2b359

Please sign in to comment.