Skip to content

Commit

Permalink
Improve tom-select CSS,
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Aug 8, 2023
1 parent f26fc2f commit 801d5e7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 120 deletions.
11 changes: 0 additions & 11 deletions BookingSystem/static/css/chosen.min.css

This file was deleted.

9 changes: 6 additions & 3 deletions BookingSystem/static/css/tom-select.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions BookingSystem/static/js/chosen.jquery.min.js

This file was deleted.

32 changes: 15 additions & 17 deletions BookingSystem/templates/booking.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,8 @@ <h3>Dersom du ikke finner eleven i listen, må eleven logge inn på nettstedet o

<script>
$(document).ready(function () {
let options = {
create: false,
sortField: {
field: 'text',
direction: 'asc'
},
hidePlaceholder: true,
closeAfterSelect: true,
}

new TomSelect('#user', {
...options,
let userSelect = new TomSelect('#user', {
...tomDefaults,
maxItems: 1,
searchField: ['text', 'classroom'],
selectOnTab: true,
Expand All @@ -71,13 +61,19 @@ <h3>Dersom du ikke finner eleven i listen, må eleven logge inn på nettstedet o
let icon = data.classroom === 'Lærer' ? 'fa-user-circle' : 'fa-user-circle-o';
return `<div class="booking-option">\<div class="option-inline-text">${data.text}</div>\
<div class="option-inline-details">${data.classroom}</div></div>`
}
},
no_results: function (data, escape) {
return '<div class="no-results">Finner ingen bruker med navnet <strong>' + escape(data.input) + '</strong></div>';
},
},
onDropdownClose: function (dropdown) {
// Focus days input when user is selected
let days = $('#days');
days.focus();
days.select();
},
onDropdownOpen: function (dropdown) {
userSelect.clear()
}
});

Expand All @@ -90,16 +86,18 @@ <h3>Dersom du ikke finner eleven i listen, må eleven logge inn på nettstedet o
});

new TomSelect('#equipment', {
...options,
...tomDefaults,
plugins: ['remove_button'],
searchField: ['text'],
openOnFocus: false,
render: {
option: function (data, escape) {
return `<div class="booking-option">\
<div class="option-inline-text">${data.text}</div>\
<div class="option-inline-itemdetails">${data.name} (${data.category})</div></div>`
},
no_results: function (data, escape) {
return '<div class="no-results">Finner ingen utstyr med løpenummer <strong>' + escape(data.input) + '</strong></div>';
},
}
});

Expand Down Expand Up @@ -171,12 +169,12 @@ <h3>Dersom du ikke finner eleven i listen, må eleven logge inn på nettstedet o
if (any_overdue) {
iziToast.warning({
title: 'Advarsel',
message: `Valgt bruker har utstyr som er over forfallsdato!`,
message: `Bruker har utstyr som er over forfallsdato!`,
});
} else {
iziToast.info({
title: 'Info',
message: `Valgt bruker har aktive lån.`,
message: `Bruker har aktive lån.`,
})
}
}
Expand Down
9 changes: 3 additions & 6 deletions BookingSystem/templates/inventar_add.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'layout.html' %}

{% block extra_head %}
{% include 'templates/chosen.html' %}
{% include 'templates/tom-select.html' %}
{% endblock %}

{% block content %}
Expand All @@ -20,7 +20,7 @@ <h3>Her kan du legge til nytt inventar. Legg gjerne til flere, så forlater du b
pattern="{{ regex_item }}">

<label for="category">Kategori</label>
<select name="category" id="category" required>
<select name="category" id="category" required data-placeholder="Velg kategori" autocomplete="off">
<option value=""></option>
{% for category in categories %}
<option value="{{ category }}">{{ category }}</option>
Expand Down Expand Up @@ -58,10 +58,7 @@ <h3>Her kan du legge til nytt inventar. Legg gjerne til flere, så forlater du b

<script>
$(document).ready(function () {
$('#category').chosen({
no_results_text: 'Fant ingen kategorier med det navnet',
placeholder_text_single: 'Velg kategori'
});
new TomSelect('#category', tomDefaults);

$('form').submit(function (event) {
event.preventDefault();
Expand Down
10 changes: 3 additions & 7 deletions BookingSystem/templates/inventar_edit.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'layout.html' %}

{% block extra_head %}
{% include 'templates/chosen.html' %}
{% include 'templates/tom-select.html' %}
{% endblock %}

{% block content %}
Expand All @@ -22,7 +22,7 @@ <h3>Redigerer {{ item.id }} ({{ item.name }})</h3>
value="{{ item.name }}">

<label for="category">Kategori</label>
<select name="category" id="category" required>
<select name="category" id="category" data-placeholder="Velg kategori" required autocomplete="off">
<option value=""></option>
{% for category in categories %}
<option value="{{ category }}">{{ category }}
Expand Down Expand Up @@ -63,11 +63,7 @@ <h3>Redigerer {{ item.id }} ({{ item.name }})</h3>

$(document).ready(function () {
$('#category').val('{{ item.category }}');

$('#category').chosen({
no_results_text: 'Fant ingen kategorier med det navnet',
placeholder_text_single: 'Velg kategori'
});
new TomSelect('#category', tomDefaults);

$('form').submit(function (event) {
event.preventDefault();
Expand Down
67 changes: 0 additions & 67 deletions BookingSystem/templates/templates/chosen.html

This file was deleted.

31 changes: 26 additions & 5 deletions BookingSystem/templates/templates/tom-select.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,33 @@
font-size: calc(var(--font-size) * 0.75);
}

/* Change the height for single select to match others */
.ts-wrapper input, .ts-wrapper.single .ts-control {
height: calc(1rem * var(--line-height) + var(--form-element-spacing-vertical) * 2 + var(--border-width) * 2) !important;
.ts-wrapper input {
height: auto;
}

.ts-dropdown.single {
margin-top: .6rem;
margin-top: .5rem;
}
</style>

.ts-control input {
width: auto;
}
</style>

<script>
let tomDefaults = {
create: false,
sortField: {
field: 'text',
direction: 'asc'
},
searchField: ['text'],
hidePlaceholder: true,
closeAfterSelect: true,
render: {
no_results: function (data, escape) {
return '<div class="no-results">Fant ingen verdier for <strong>' + escape(data.input) + '</strong></div>';
},
}
}
</script>
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Python Dependencies are listed in `requirements.txt`
JS/CSS libraries are used:

- [PicoCSS](https://picocss.com/) (for now)
- [Chosen](https://harvesthq.github.io/chosen/) (Deprecated, might be removed)
- [jQuery](https://jquery.com/)
- [DataTables](https://datatables.net/)
- [iziToast](https://izitoast.marcelodolza.com/)
Expand Down

0 comments on commit 801d5e7

Please sign in to comment.