Skip to content

Commit

Permalink
[3.1] - select collections from the url if present (#1400)
Browse files Browse the repository at this point in the history
* select collections from the url if present

* DRY up sanitizedCollectionSource section, which has the same pattern as occurs elsewhere

* fix typo

* change default to empty array

* add better type checking to collIdsFromUrl
  • Loading branch information
Atticus29 authored Jun 5, 2024
1 parent 15e2000 commit be64c2c
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions collections/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
if($LANG_TAG != 'en' && file_exists($SERVER_ROOT.'/content/lang/collections/search/index.' . $LANG_TAG . '.php')) include_once($SERVER_ROOT.'/content/lang/collections/search/index.' . $LANG_TAG . '.php');
else include_once($SERVER_ROOT . '/content/lang/collections/search/index.en.php');

$collIdsFromUrl = array_key_exists("db",$_GET) ? explode(",", str_replace(array('[',']'), '', $_GET["db"])) : '';

$collManager = new OccurrenceManager();
$collectionSource = $collManager->getQueryTermStr();

Expand Down Expand Up @@ -567,31 +569,15 @@
ul.outerWidth(this.element.outerWidth());
}
const collectionSource = <?php echo isset($collectionSource) ? json_encode($collectionSource) : 'null'; ?>;
const collIdsFromUrl = <?php echo isset($collIdsFromUrl) ? json_encode($collIdsFromUrl) : 'null'; ?>;
if (collIdsFromUrl && Array.isArray(collIdsFromUrl) && collIdsFromUrl.length > 0) {
uncheckEverything();
checkTheCollectionsThatShouldBeChecked(collIdsFromUrl);
}
const sanitizedCollectionSource = collectionSource.replace('db=','');

if(collectionSource){
// go through all collections and set them all to unchecked
const collectionCheckboxes = document.querySelectorAll('input[id^="coll"]');
collectionCheckboxes.forEach(collection => {
collection.checked = false;
});

//go through all collections and set the parent collections to unchecked
const parentCollectionCheckboxes = document.querySelectorAll('input[id^="cat-"]');
parentCollectionCheckboxes.forEach(collection => {
collection.checked = false;
});

// set the one with collectionSource as checked
const targetCheckbox = document.querySelectorAll('input[id^="coll-' + sanitizedCollectionSource + '"]');
targetCheckbox.forEach(collection => {
collection.checked = true;
});
//do the same for collections with slightly different format
const targetCheckboxAlt = document.querySelectorAll('input[id^="collection-' + sanitizedCollectionSource + '"]');
targetCheckboxAlt.forEach(collection => {
collection.checked = true;
});
if (collectionSource) {
uncheckEverything();
checkTheCollectionsThatShouldBeChecked(sanitizedCollectionSource);
updateChip();
}

Expand Down

0 comments on commit be64c2c

Please sign in to comment.