Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.1] - select collections from the url if present #1400

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'; ?>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is safe current based on its use however the contents of this can be unsafe so just fyi I guess

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