mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Merge pull request #858 from ae-utbm/jsstandard
Add biome to format js files
This commit is contained in:
@ -1,77 +1,86 @@
|
||||
document.addEventListener('alpine:init', () => {
|
||||
Alpine.data('counter', () => ({
|
||||
basket: basket,
|
||||
errors: [],
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("counter", () => ({
|
||||
// biome-ignore lint/correctness/noUndeclaredVariables: defined in counter_click.jinja
|
||||
basket: sessionBasket,
|
||||
errors: [],
|
||||
|
||||
sum_basket() {
|
||||
if (!this.basket || Object.keys(this.basket).length === 0) {
|
||||
return 0;
|
||||
}
|
||||
const total = Object.values(this.basket)
|
||||
.reduce((acc, cur) => acc + cur["qty"] * cur["price"], 0);
|
||||
return total / 100;
|
||||
sumBasket() {
|
||||
if (!this.basket || Object.keys(this.basket).length === 0) {
|
||||
return 0;
|
||||
}
|
||||
const total = Object.values(this.basket).reduce(
|
||||
(acc, cur) => acc + cur.qty * cur.price,
|
||||
0,
|
||||
);
|
||||
return total / 100;
|
||||
},
|
||||
|
||||
async handleCode(event) {
|
||||
const code = $(event.target).find("#code_field").val().toUpperCase();
|
||||
if (["FIN", "ANN"].includes(code)) {
|
||||
$(event.target).submit();
|
||||
} else {
|
||||
await this.handleAction(event);
|
||||
}
|
||||
},
|
||||
|
||||
async handleAction(event) {
|
||||
const payload = $(event.target).serialize();
|
||||
// biome-ignore lint/correctness/noUndeclaredVariables: defined in counter_click.jinja
|
||||
const request = new Request(clickApiUrl, {
|
||||
method: "POST",
|
||||
body: payload,
|
||||
headers: {
|
||||
// biome-ignore lint/style/useNamingConvention: this goes into http headers
|
||||
Accept: "application/json",
|
||||
// biome-ignore lint/correctness/noUndeclaredVariables: defined in counter_click.jinja
|
||||
"X-CSRFToken": csrfToken,
|
||||
},
|
||||
});
|
||||
const response = await fetch(request);
|
||||
const json = await response.json();
|
||||
this.basket = json.basket;
|
||||
this.errors = json.errors;
|
||||
$("form.code_form #code_field").val("").focus();
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
async handle_code(event) {
|
||||
const code = $(event.target).find("#code_field").val().toUpperCase();
|
||||
if(["FIN", "ANN"].includes(code)) {
|
||||
$(event.target).submit();
|
||||
} else {
|
||||
await this.handle_action(event);
|
||||
}
|
||||
},
|
||||
$(() => {
|
||||
/* Autocompletion in the code field */
|
||||
const codeField = $("#code_field");
|
||||
|
||||
async handle_action(event) {
|
||||
const payload = $(event.target).serialize();
|
||||
let request = new Request(click_api_url, {
|
||||
method: "POST",
|
||||
body: payload,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-CSRFToken': csrf_token,
|
||||
}
|
||||
})
|
||||
const response = await fetch(request);
|
||||
const json = await response.json();
|
||||
this.basket = json["basket"]
|
||||
this.errors = json["errors"]
|
||||
$('form.code_form #code_field').val("").focus();
|
||||
}
|
||||
}))
|
||||
})
|
||||
let quantity = "";
|
||||
codeField.autocomplete({
|
||||
select: (event, ui) => {
|
||||
event.preventDefault();
|
||||
codeField.val(quantity + ui.item.value);
|
||||
},
|
||||
focus: (event, ui) => {
|
||||
event.preventDefault();
|
||||
codeField.val(quantity + ui.item.value);
|
||||
},
|
||||
source: (request, response) => {
|
||||
// biome-ignore lint/performance/useTopLevelRegex: performance impact is minimal
|
||||
const res = /^(\d+x)?(.*)/i.exec(request.term);
|
||||
quantity = res[1] || "";
|
||||
const search = res[2];
|
||||
const matcher = new RegExp($.ui.autocomplete.escapeRegex(search), "i");
|
||||
response(
|
||||
// biome-ignore lint/correctness/noUndeclaredVariables: defined in counter_click.jinja
|
||||
$.grep(productsAutocomplete, (value) => {
|
||||
return matcher.test(value.tags);
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
$(function () {
|
||||
/* Autocompletion in the code field */
|
||||
const code_field = $("#code_field");
|
||||
/* Accordion UI between basket and refills */
|
||||
$("#click_form").accordion({
|
||||
heightStyle: "content",
|
||||
activate: () => $(".focus").focus(),
|
||||
});
|
||||
$("#products").tabs();
|
||||
|
||||
let quantity = "";
|
||||
code_field.autocomplete({
|
||||
select: function (event, ui) {
|
||||
event.preventDefault();
|
||||
code_field.val(quantity + ui.item.value);
|
||||
},
|
||||
focus: function (event, ui) {
|
||||
event.preventDefault();
|
||||
code_field.val(quantity + ui.item.value);
|
||||
},
|
||||
source: function (request, response) {
|
||||
const res = /^(\d+x)?(.*)/i.exec(request.term);
|
||||
quantity = res[1] || "";
|
||||
const search = res[2];
|
||||
const matcher = new RegExp($.ui.autocomplete.escapeRegex(search), "i" );
|
||||
response($.grep(products_autocomplete, function(value) {
|
||||
value = value.tags;
|
||||
return matcher.test( value );
|
||||
}));
|
||||
},
|
||||
});
|
||||
|
||||
/* Accordion UI between basket and refills */
|
||||
$("#click_form").accordion({
|
||||
heightStyle: "content",
|
||||
activate: () => $(".focus").focus(),
|
||||
});
|
||||
$("#products").tabs();
|
||||
|
||||
code_field.focus();
|
||||
});
|
||||
codeField.focus();
|
||||
});
|
||||
|
@ -59,7 +59,7 @@
|
||||
|
||||
{# Formulaire pour rechercher un produit en tapant son code dans une barre de recherche #}
|
||||
<form method="post" action=""
|
||||
class="code_form" @submit.prevent="handle_code">
|
||||
class="code_form" @submit.prevent="handleCode">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="code">
|
||||
<label for="code_field"></label>
|
||||
@ -77,7 +77,7 @@
|
||||
<template x-for="[id, item] in Object.entries(basket)" :key="id">
|
||||
<div>
|
||||
<form method="post" action="" class="inline del_product_form"
|
||||
@submit.prevent="handle_action">
|
||||
@submit.prevent="handleAction">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="del_product">
|
||||
<input type="hidden" name="product_id" :value="id">
|
||||
@ -87,7 +87,7 @@
|
||||
<span x-text="item['qty'] + item['bonus_qty']"></span>
|
||||
|
||||
<form method="post" action="" class="inline add_product_form"
|
||||
@submit.prevent="handle_action">
|
||||
@submit.prevent="handleAction">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="add_product">
|
||||
<input type="hidden" name="product_id" :value="id">
|
||||
@ -104,7 +104,7 @@
|
||||
</ul>
|
||||
<p>
|
||||
<strong>Total: </strong>
|
||||
<strong x-text="sum_basket().toLocaleString(undefined, { minimumFractionDigits: 2 })"></strong>
|
||||
<strong x-text="sumBasket().toLocaleString(undefined, { minimumFractionDigits: 2 })"></strong>
|
||||
<strong> €</strong>
|
||||
</p>
|
||||
|
||||
@ -147,7 +147,7 @@
|
||||
{% for p in categories[category] -%}
|
||||
<form method="post"
|
||||
action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}"
|
||||
class="form_button add_product_form" @submit.prevent="handle_action">
|
||||
class="form_button add_product_form" @submit.prevent="handleAction">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="add_product">
|
||||
<input type="hidden" name="product_id" value="{{ p.id }}">
|
||||
@ -171,9 +171,9 @@
|
||||
{% block script %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
const csrf_token = "{{ csrf_token }}";
|
||||
const click_api_url = "{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}";
|
||||
const basket = {{ request.session["basket"]|tojson }};
|
||||
const csrfToken = "{{ csrf_token }}";
|
||||
const clickApiUrl = "{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}";
|
||||
const sessionBasket = {{ request.session["basket"]|tojson }};
|
||||
const products = {
|
||||
{%- for p in products -%}
|
||||
{{ p.id }}: {
|
||||
@ -183,7 +183,7 @@
|
||||
},
|
||||
{%- endfor -%}
|
||||
};
|
||||
const products_autocomplete = [
|
||||
const productsAutocomplete = [
|
||||
{% for p in products -%}
|
||||
{
|
||||
value: "{{ p.code }}",
|
||||
|
Reference in New Issue
Block a user