Commit 980db79e authored by Geoffroy ARNOUD's avatar Geoffroy ARNOUD
Browse files

Added select2 dropdown into header and default-settings page #K7

parent 2836fbca
......@@ -13,9 +13,8 @@
<?php
if ($useSelect2) {
echo '<link rel="stylesheet" href="'. $_SERVER['SCRIPT_NAME'] .'/select2.css" type="text/css" >'.PHP_EOL;
echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />'.PHP_EOL;
echo '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>'.PHP_EOL;
// echo '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.js"></script>'.PHP_EOL;
echo '<script type="text/javascript" src="'.$javascriptURL .'/select2Functions.js"></script>'.PHP_EOL;
} elseif ($useImprovedDropDownList) {
echo '<link rel="stylesheet" href="'. $_SERVER['SCRIPT_NAME'] .'/ImprovedDropDown.css" type="text/css">'.PHP_EOL;
......@@ -95,8 +94,8 @@
if (<?php echo ($useSelect2) ? 'true' : 'false' ?>){
$('.userIdPSelection').select2({
ajax: {
url: <?php echo "'".$apiURL."/idps'" ?>,
delay: 250,
url: <?php echo "'".$_SERVER['REQUEST_URI']."api/idps'" ?>,
delay: 1000,
dataType: 'json',
data: function (params) {
var query = {
......@@ -118,7 +117,7 @@
placeholder: "<?php echo getLocalString('select_idp') ?>",
allowClear: true,
templateResult: formatList,
templateSelection: formatSelection,
templateSelection: formatRepoSelection,
escapeMarkup: function (text) { return text; }
});
......
......@@ -13,7 +13,6 @@
<p class="promptMessage"><?php echo getLocalString('permanent_cookie'); ?></p>
<p><?php echo getLocalString('select_idp'); ?></p>
<div style="text-align: center">
<select name="user_idp" id="userIdPSelection" class="userIdPSelection" tabindex="0">
<?php
// If we use select2, we don't want IDP to be in DOM, but to use AJAX instead
......
......@@ -4,48 +4,49 @@
* Inspired from https://select2.org/data-sources/ajax
*/
/*
* Format for list items
*/
function formatList(idp) {
if (idp.loading) {
return idp.text;
}
if (idp.children == null) {
// IDP
var img = "";
if (idp.logo !== null) {
// Logo present
if (idp.logo.toLowerCase().indexOf('data:image') !== 0) {
// TODO : gérer le cas où on ne veut pas fetcher les logos distants
// remote logo
img = "<img src='" + idp.logo + "' />";
} else {
// local logo
img = "<img src='" + idp.logo + "' />";
}
if (idp.loading) {
return idp.text;
}
if (idp.children == null) {
// IDP
var img = "";
if (idp.logo !== null) {
// Logo present
if (idp.logo.toLowerCase().indexOf('data:image') !== 0) {
// TODO : gérer le cas où on ne veut pas fetcher les logos distants
// remote logo
img = "<img src='" + idp.logo + "' />";
} else {
// local logo
img = "<img src='" + idp.logo + "' />";
}
} else {
img = "&nbsp;";
}
var markup = "<div class='select2-result-repository clearfix'>" +
"<div class='select2-result-repository__logo'>" + img + "</div>" +
"<div class='select2-result-repository__title'>" + idp.text + "</div></div>";
return markup;
} else {
img = "&nbsp;";
// Group
var markup = "<div class='select2-result-repository clearfix'>" +
idp.text + "</div>";
return markup;
}
var markup = "<div class='select2-result-repository clearfix'>" +
"<div class='select2-result-repository__logo'>" + img + "</div>" +
"<div class='select2-result-repository__title'>" + idp.text + "</div></div>";
return markup;
} else {
// Group
var markup = "<div class='select2-result-repository clearfix'>" +
idp.text + "</div>";
return markup;
}
}
/*
* Format for selected element
*/
function formatSelection(idp) {
return idp.text;
return idp.text;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment