mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Format with biome instead of standard
This commit is contained in:
@ -1,79 +1,80 @@
|
||||
/* eslint-disable camelcase */
|
||||
/* global basket, click_api_url, csrf_token, products_autocomplete */
|
||||
document.addEventListener('alpine:init', () => {
|
||||
Alpine.data('counter', () => ({
|
||||
basket,
|
||||
errors: [],
|
||||
document.addEventListener("alpine:init", () => {
|
||||
Alpine.data("counter", () => ({
|
||||
basket,
|
||||
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
|
||||
},
|
||||
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;
|
||||
},
|
||||
|
||||
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)
|
||||
}
|
||||
},
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
async handle_action (event) {
|
||||
const payload = $(event.target).serialize()
|
||||
const 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()
|
||||
}
|
||||
}))
|
||||
})
|
||||
async handle_action(event) {
|
||||
const payload = $(event.target).serialize();
|
||||
const 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();
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
$(function () {
|
||||
/* Autocompletion in the code field */
|
||||
const code_field = $('#code_field')
|
||||
$(() => {
|
||||
/* Autocompletion in the code field */
|
||||
const code_field = $("#code_field");
|
||||
|
||||
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)
|
||||
}))
|
||||
}
|
||||
})
|
||||
let quantity = "";
|
||||
code_field.autocomplete({
|
||||
select: (event, ui) => {
|
||||
event.preventDefault();
|
||||
code_field.val(quantity + ui.item.value);
|
||||
},
|
||||
focus: (event, ui) => {
|
||||
event.preventDefault();
|
||||
code_field.val(quantity + ui.item.value);
|
||||
},
|
||||
source: (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, (value) => {
|
||||
return matcher.test(value.tags);
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
/* Accordion UI between basket and refills */
|
||||
$('#click_form').accordion({
|
||||
heightStyle: 'content',
|
||||
activate: () => $('.focus').focus()
|
||||
})
|
||||
$('#products').tabs()
|
||||
/* Accordion UI between basket and refills */
|
||||
$("#click_form").accordion({
|
||||
heightStyle: "content",
|
||||
activate: () => $(".focus").focus(),
|
||||
});
|
||||
$("#products").tabs();
|
||||
|
||||
code_field.focus()
|
||||
})
|
||||
code_field.focus();
|
||||
});
|
||||
|
Reference in New Issue
Block a user