Fix something I think

This commit is contained in:
Jovan Jovanovic 2021-08-04 23:09:58 +02:00
parent e58b8c2aad
commit b120322732

View file

@ -124,71 +124,63 @@
]
})
$('#users').select2({
ajax: {
url: '/admin/users.json',
dataType: 'json',
delay: 250,
function initUserSelect(data) {
$('#users').select2({
ajax: {
url: '/admin/users.json',
dataType: 'json',
delay: 250,
data: function (params) {
return {
filter: { email: params.term },
page: params.page,
};
data: function (params) {
return {
filter: { email: params.term },
page: params.page,
};
},
processResults: function (data, params) {
return { results: data };
},
cache: true,
},
data: data,
minimumInputLength: 2,
templateResult: function (data) {
if (data.loading) return data.text;
const $container = $(
"<div class='select2-result-users clearfix' style='display:flex;'>" +
"<div class='select2-result-users__avatar' style='display:flex;align-items:center;'><img class='img-circle img-bordered-s' src='" + data.avatarUrl + "?s=40' /></div>" +
"<div class='select2-result-users__meta' style='margin-left:10px'>" +
"<div class='select2-result-users__username' style='font-size:16px;'></div>" +
"<div class='select2-result-users__email' style='font-size=13px;'></div>" +
"</div>" +
"</div>"
);
processResults: function (data, params) {
return { results: data };
$container.find(".select2-result-users__username").text(data.name);
$container.find(".select2-result-users__email").text(data.email);
return $container;
},
cache: true,
},
minimumInputLength: 2,
templateResult: function (data) {
if (data.loading) return escapeHtml(data.text);
const $container = $(
"<div class='select2-result-repository clearfix' style='display:flex;'>" +
"<div class='select2-result-repository__avatar' style='display:flex;align-items:center;'><img class='img-circle img-bordered-s' src='" + data.avatarUrl + "?s=40' /></div>" +
"<div class='select2-result-repository__meta' style='margin-left:10px'>" +
"<div class='select2-result-repository__username' style='font-size:16px;'></div>" +
"<div class='select2-result-repository__email' style='font-size=13px;'></div>" +
"</div>" +
"</div>"
);
$container.find(".select2-result-repository__username").text(data.name);
$container.find(".select2-result-repository__email").text(data.email);
return $container;
{{-- return $('<div class="user-block"> \
<img class="img-circle img-bordered-xs" src="' + escapeHtml(data.avatarUrl) + '?s=120" alt="User Image"> \
<span class="username"> \
<a href="#">' + escapeHtml(data.name) +'</a> \
</span> \
<span class="description"><strong>' + escapeHtml(data.email) + '</strong></span> \
</div>'); --}}
},
templateSelection: function (data) {
return $('<div> \
<span> \
<img class="img-rounded img-bordered-xs" src="' + escapeHtml(data.avatarUrl) + '?s=120" style="height:24px;margin-top:-4px;" alt="User Image"> \
</span> \
<span style="padding-left:10px;padding-right:10px;"> \
' + escapeHtml(data.name) +' \
</span> \
</div>');
}
})
templateSelection: function (data) {
$container = $('<div> \
<span> \
<img class="img-rounded img-bordered-xs" src="' + data.avatarUrl + '?s=120" style="height:24px;margin-top:-4px;" alt="User Image"> \
</span> \
<span class="select2-selection-users__username" style="padding-left:10px;padding-right:10px;"></span> \
</div>');
$container.find(".select2-selection-users__username").text(data.name);
return $container;
}
})
}
initUserSelect()
})
function toggleClass(id, className) {
document.getElementById(id).classList.toggle(className)
}
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
}
</script>