Skip to content
Snippets Groups Projects
Commit dfb8d7dc authored by Tomáš's avatar Tomáš
Browse files

finish vote selecting, improve styles

parent 4bb42030
No related branches found
No related tags found
1 merge request!1Test release
Pipeline #11231 failed
...@@ -14,25 +14,30 @@ ...@@ -14,25 +14,30 @@
<main> <main>
<h1 class="text-6xl font-bebas mb-5">Kalkulačka hlasování RV</h1> <h1 class="text-6xl font-bebas mb-5">Kalkulačka hlasování RV</h1>
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-7 mb-5 items-center">
<div> <div class="flex items-center gap-3 justify-between">
<h2 class="text-2xl font-bebas mb-5">Hlasy členů</h2> <h2 class="text-2xl font-bebas">Hlasy členů</h2>
<ul class="flex flex-col gap-2"> <button
{% for member in rv_members %} class="bg-black text-white px-5 py-3 duration-100 hover:bg-gray-800"
<li class="flex gap-4 items-center"> id="count-votes"
<div class="basis-56 flex items-center"> >Vypočítat</button>
<i class="ico--user text-xl mr-2"></i>
{{ member.displayName }}
</div>
<select class="grow __vote-selection" multiple="multiple"></select>
</li>
{% endfor %}
</ul>
</div> </div>
<div> <h2 class="text-2xl font-bebas">Výsledky</h2>
<h2 class="text-2xl font-bebas mb-5">Výsledky</h2> </div>
</div>
<div class="grid grid-cols-2 gap-7">
<ul class="flex flex-col gap-2">
{% for member in rv_members %}
<li class="flex gap-4 items-center">
<div class="basis-56 flex items-center">
<i class="ico--user text-xl mr-2"></i>
{{ member.displayName }}
</div>
<select class="grow w-full __vote-selection" multiple="multiple"></select>
</li>
{% endfor %}
</ul>
</div> </div>
</main> </main>
......
...@@ -21,6 +21,16 @@ $(window).ready( ...@@ -21,6 +21,16 @@ $(window).ready(
} }
}); });
$(".__vote-selection").on(
"select2:selecting",
event => {
// Prevent empty tags.
if (event.params.args.data.id == "") {
event.preventDefault();
}
}
);
$(".__vote-selection").on( $(".__vote-selection").on(
"select2:select", "select2:select",
event => { event => {
...@@ -31,7 +41,7 @@ $(window).ready( ...@@ -31,7 +41,7 @@ $(window).ready(
return; return;
} }
const tagName = event.params.data.text; const tagName = event.params.data.id;
const addedTag = new Option( const addedTag = new Option(
tagName, tagName,
...@@ -46,7 +56,11 @@ $(window).ready( ...@@ -46,7 +56,11 @@ $(window).ready(
// Check if they contain the tag. If they do, ignore them. // Check if they contain the tag. If they do, ignore them.
for (const selection of unfilteredSelections) { for (const selection of unfilteredSelections) {
if ($(selection).children(`option[value=${tagName}]`).length === 0) { if (
$(selection).
children(`option[value=${$.escapeSelector(tagName)}]`).
length === 0
) {
filteredSelections.push(selection); filteredSelections.push(selection);
} }
} }
...@@ -61,7 +75,7 @@ $(window).ready( ...@@ -61,7 +75,7 @@ $(window).ready(
event => { event => {
//// Remove the tag option if it's not selected anywhere. //// Remove the tag option if it's not selected anywhere.
const tagName = event.params.data.text; const tagName = event.params.data.id;
// Get all other selections. // Get all other selections.
const selections = $(".__vote-selection"); const selections = $(".__vote-selection");
...@@ -69,16 +83,9 @@ $(window).ready( ...@@ -69,16 +83,9 @@ $(window).ready(
// Check if any of them have the tag selected. If they do, end the function. // Check if any of them have the tag selected. If they do, end the function.
for (const selection of selections) { for (const selection of selections) {
for (const data of $(selection).select2("data")) { for (const data of $(selection).select2("data")) {
if (data.selected && data.id == tagName) { if (data.id == tagName) {
// Workaround - add the option back to this select (TODO - improve) // TODO - Don't remove the tag from this select.
$(event.target).append( // I'm not sure select2 has a good way of doing this.
new Option(
tagName,
tagName,
false,
false
)
).trigger("change");
return; return;
} }
...@@ -87,7 +94,12 @@ $(window).ready( ...@@ -87,7 +94,12 @@ $(window).ready(
// If the function has not ended by now, we can remove the tag. // If the function has not ended by now, we can remove the tag.
for (const selection of selections) { for (const selection of selections) {
$(selection).children(`option[value=${tagName}]`).remove(); (
$(selection).
children(`option[value=${$.escapeSelector(tagName)}]`).
remove()
);
$(selection).trigger("change"); $(selection).trigger("change");
} }
} }
......
const escapeHTML = (source) => {
return new Option(source).innerHTML;
}
export { escapeHTML };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment