From f345d8a99a6fc2ec9ae235792eb2db5e5e0a0797 Mon Sep 17 00:00:00 2001 From: Neal Date: Wed, 23 Sep 2026 14:56:33 -0400 Subject: [PATCH 1/2] readd request collection button --- app/Assets/css/extra.css | 2 +- app/Assets/js/requests.js | 40 +++++++++++++++----------- app/Controllers/Findingaid.php | 7 ++--- app/Views/Findingaid/requests.mustache | 4 +++ app/Views/Findingaid/toc.mustache | 2 -- app/Views/Layouts/application.mustache | 4 ++- 6 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Assets/css/extra.css b/app/Assets/css/extra.css index 85618e1..5623d4b 100644 --- a/app/Assets/css/extra.css +++ b/app/Assets/css/extra.css @@ -118,7 +118,7 @@ visibility: hidden; } -.fa-request.fa-requestable-toc { +.fa-request.fa-requestable-collection { display: block; margin: 0 auto; } diff --git a/app/Assets/js/requests.js b/app/Assets/js/requests.js index 8b5e4b7..6edc6e9 100644 --- a/app/Assets/js/requests.js +++ b/app/Assets/js/requests.js @@ -122,8 +122,8 @@ var requests = (function() { container = $('#' + target).attr('data-container'); label = $('#' + target).val(); title_pieces = []; - title_pieces.push(volume); - title_pieces.push(container); + if (volume) title_pieces.push(volume); + if (container) title_pieces.push(container); title = title_pieces.join(', '); item = { @@ -639,7 +639,7 @@ var requests = (function() { }); add_input({ name: "ItemTitle_" + id, - value: collection_title + ': ' + folder["title"], + value: collection_title + (folder["title"] ? ': ' + folder["title"] : ''), root: id }); add_input({ @@ -668,6 +668,8 @@ var requests = (function() { collection_title = options["title"]; button_active = options["button_active"]; button_inactive = options["button_inactive"]; + var button_collection_active = options["button_collection_active"]; + var button_collection_inactive = options["button_collection_inactive"]; model.init(); update(); @@ -717,20 +719,24 @@ var requests = (function() { $('.fa-requestable').each(function () { var id = $(this).attr('id'); - $(this).after([ - '' - ].join('')); - //} + var isCollection = $(this).hasClass('fa-collection'); + var active = isCollection ? button_collection_active : button_active; + var inactive = isCollection ? button_collection_inactive : button_inactive; + $(this).after([ + '' + ].join('')); }); $('form.fa-request-fieldset').submit(function () { diff --git a/app/Controllers/Findingaid.php b/app/Controllers/Findingaid.php index 7e6a2a5..4368d4c 100644 --- a/app/Controllers/Findingaid.php +++ b/app/Controllers/Findingaid.php @@ -245,10 +245,9 @@ public function show() $repository = $model->repository(); $requestable = ($repository === 'University of Kentucky'); - $toc_component = false; + $collection_request = false; if ($requestable and ($component_count == 0)) { - $toc_component = [ - 'summary' => '', + $collection_request = [ 'id' => 'fa-no-components-request', 'container_list' => fa_brevity($model->title()), 'volume' => '', @@ -262,7 +261,6 @@ public function show() 'entries' => $toc_entries, 'links' => $links, 'requestable' => $requestable, - 'toc_component' => $toc_component, ]; $toc = $m->render( @@ -283,6 +281,7 @@ public function show() 'id' => $requests_config['summary']['id'], 'label' => fa_brevity($requests_config['summary']['label']), 'list_id' => $requests_config['summary']['list_id'], + 'collection_request' => $collection_request, 'title' => $this->cleanup($model->unittitle()), 'collection_id' => $model->id(), 'call_number' => $model->unitid(), diff --git a/app/Views/Findingaid/requests.mustache b/app/Views/Findingaid/requests.mustache index 692779a..1b69fbb 100644 --- a/app/Views/Findingaid/requests.mustache +++ b/app/Views/Findingaid/requests.mustache @@ -102,5 +102,9 @@ + {{#collection_request}}{{> checkered_divider}}{{/collection_request}} + {{#collection_request}} + + {{/collection_request}} diff --git a/app/Views/Findingaid/toc.mustache b/app/Views/Findingaid/toc.mustache index 3b0c1a5..c4f4e43 100644 --- a/app/Views/Findingaid/toc.mustache +++ b/app/Views/Findingaid/toc.mustache @@ -21,7 +21,5 @@ {{/links}} - {{#toc_component}} - {{/toc_component}} diff --git a/app/Views/Layouts/application.mustache b/app/Views/Layouts/application.mustache index 44c6983..55fcde5 100644 --- a/app/Views/Layouts/application.mustache +++ b/app/Views/Layouts/application.mustache @@ -54,7 +54,9 @@ requests.init({ title: "{{title}}", button_active: "Remove", - button_inactive: "Request" + button_inactive: "Request", + button_collection_active: "Remove Collection", + button_collection_inactive: "Add Collection to Request" }); {{/requestable}} From 2ddd742bf3defa529e22008296ec70554a7284e6 Mon Sep 17 00:00:00 2001 From: Neal Date: Wed, 23 Sep 2026 14:56:43 -0400 Subject: [PATCH 2/2] add regression tests --- tests/CollectionRequestTest.php | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/CollectionRequestTest.php diff --git a/tests/CollectionRequestTest.php b/tests/CollectionRequestTest.php new file mode 100644 index 0000000..d663a88 --- /dev/null +++ b/tests/CollectionRequestTest.php @@ -0,0 +1,44 @@ +render(load_template('Findingaid/requests'), [ + 'collection_request' => [ + 'id' => 'fa-no-components-request', + 'container_list' => 'Example collection', + 'volume' => '', + 'container' => '', + ], + ]); + $document = new \DOMDocument(); + $document->loadHTML($html, LIBXML_NOERROR | LIBXML_NOWARNING); + $xpath = new \DOMXPath($document); + // These classes are the hooks requests.js uses to create the collection button. + $targets = $xpath->query( + '//input[contains(concat(" ", normalize-space(@class), " "), " fa-requestable ")]' + . '[contains(concat(" ", normalize-space(@class), " "), " fa-collection ")]' + ); + + $this->assertCount(1, $targets, 'The collection must have one selectable request target.'); + $this->assertCount(0, $xpath->query( + 'ancestor::div[contains(concat(" ", normalize-space(@class), " "), " js-accordion__panel ")]', + $targets->item(0) + ), 'Collapsing the request options must not hide the collection button.'); + } + + public function testNoCollectionRequestTargetWithoutTheFallback(): void + { + $html = (new Mustache_Engine())->render(load_template('Findingaid/requests'), [ + 'collection_request' => false, + ]); + + $this->assertStringNotContainsString('fa-requestable', $html); + } +}