diff --git a/templates/includes/searchbox.twig b/templates/includes/searchbox.twig index 8860f24bcf0af56432b4dbf15faf0d90dff7f4dd..1169030dc6f09cd7dbc5a50ca259246ba5a6690f 100644 --- a/templates/includes/searchbox.twig +++ b/templates/includes/searchbox.twig @@ -33,17 +33,25 @@ <div class="box-vcards-list__content u-pb-0 u-pt-0 u-pr-0 u-pl-10"> {% if attribute(idp.name, currentLanguage) is defined %}{{ attribute(idp.name, currentLanguage) }}{% elseif idp.name is iterable and idp.name is not empty %}idp.name|first{% else %}{{ '{campusmultiauth:undefined}'|trans }}{% endif %} </div> + <div class="remove-option"> + <span class="icon icon-times"></span> + </div> </div> </button> </div> {% else %} - <button class="list-group-item list-group-item-action d-flex align-items-center" type="submit"> - <span class="mb-0"> - <img src="{{ idp.img }}" class="img-searchbox" alt=""/> - </span> - <span class="margin-left-24"> - {% if attribute(idp.name, currentLanguage) is defined %}{{ attribute(idp.name, currentLanguage) }}{% elseif idp.name is iterable and idp.name is not empty %}idp.name|first{% else %}{{ '{campusmultiauth:undefined}'|trans }}{% endif %} - </span> + <button class="list-group-item list-group-item-action d-flex align-items-center" type="submit" name="searchbox" value="{{ idp.entityid }}"> + <div class="full-width"> + <span class="mb-0"> + <img src="{{ idp.img }}" class="img-searchbox" alt=""/> + </span> + <span class="margin-left-24"> + {% if attribute(idp.name, currentLanguage) is defined %}{{ attribute(idp.name, currentLanguage) }}{% elseif idp.name is iterable and idp.name is not empty %}idp.name|first{% else %}{{ '{campusmultiauth:undefined}'|trans }}{% endif %} + </span> + <div class="remove-option"> + <i class="fas fa-times"></i> + </div> + </div> </button> {% endif %} {% set counter = counter + 1 %} diff --git a/www/removeCookie.php b/www/removeCookie.php new file mode 100644 index 0000000000000000000000000000000000000000..766b0a3ce8dfae98b24e6dffd2a889351d21e056 --- /dev/null +++ b/www/removeCookie.php @@ -0,0 +1,18 @@ +<?php + +use SimpleSAML\Module\campusmultiauth\Auth\Source\Campusidp; +use SimpleSAML\Logger; + +$prevIdps = Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS) === null ? + [] : + json_decode(gzinflate(base64_decode(Campusidp::getCookie(Campusidp::COOKIE_PREVIOUS_IDPS))), true); + +$entityid = $_POST['entityid']; + +foreach ($prevIdps as $index => $idp) { + if ($idp['entityid'] === $entityid) { + unset($prevIdps[$index]); + } +} + +Campusidp::setCookie(Campusidp::COOKIE_PREVIOUS_IDPS, base64_encode(gzdeflate(json_encode($prevIdps)))); diff --git a/www/resources/campus-idp.css b/www/resources/campus-idp.css index a18b3fcb2a67a02ed79e81976559bbdb15907e2b..61c47369bb008ac5627edf5e8b5cbefdf1263704 100644 --- a/www/resources/campus-idp.css +++ b/www/resources/campus-idp.css @@ -89,6 +89,11 @@ html, body { margin: 24px; } +.remove-option { + float: right; + margin-right: 10px; +} + .header-img { width: 170px; margin: 0 auto 0 36px; diff --git a/www/resources/campus-idp.js b/www/resources/campus-idp.js index 850d839c6db837ca3d98ac109d2c79027f0461d7..4b026dcc3b8d66b97302f036d8e3b1367bca71d1 100644 --- a/www/resources/campus-idp.js +++ b/www/resources/campus-idp.js @@ -117,6 +117,24 @@ document.addEventListener("DOMContentLoaded", function () { }); } + document.querySelectorAll('.remove-option').forEach(function (element) { + element.addEventListener('click', function (e) { + e.stopPropagation(); + + let button = this.parentElement.parentElement; + + $.ajax({ + url: "./removeCookie.php", + type: "POST", + data: { + entityid: button.value + }, + }); + + button.remove(); + }) + }) + document.querySelectorAll('.idps-form-nojs-div').forEach(hideElement); document.querySelectorAll('.idps-form-div').forEach(showElement);