From ec576464a8ef0943ea5a77f25659f89fbe377462 Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 12 Aug 2021 15:40:38 +0200 Subject: Use arrow functions in main.js --- assets/main.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'assets') diff --git a/assets/main.js b/assets/main.js index ba82a9f..c22499e 100644 --- a/assets/main.js +++ b/assets/main.js @@ -46,8 +46,8 @@ if (path == '/login') { // Functions function trim_inputs_on_blur() { - document.querySelectorAll('input').forEach(function (input) { - input.addEventListener('blur', function () { + document.querySelectorAll('input').forEach(input => { + input.addEventListener('blur', () => { input.value = input.value.trim() }) }) @@ -58,7 +58,7 @@ function control_remove_button() { const removeButton = document.getElementById('remove-button') if (removeInput && removeButton) { - removeInput.addEventListener('input', function() { + removeInput.addEventListener('input', () => { if (removeInput.value.trim() == removeInput.getAttribute('data-name')) { removeButton.removeAttribute('disabled') } else { @@ -76,9 +76,9 @@ function auto_fill_category() { const query = name.value.trim() if (query) { const xhttp = new XMLHttpRequest() - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - category.value = this.responseText + xhttp.onreadystatechange = () => { + if (xhttp.readyState == 4 && xhttp.status == 200) { + category.value = xhttp.responseText } } xhttp.open('GET', `/payment/category?payment_name=${query}`, true) @@ -94,21 +94,21 @@ function show_statistics() { const incomes = JSON.parse(document.getElementById('incomes').textContent) const payments = JSON.parse(document.getElementById('payments').textContent) - const dates = incomes.map(function (i) { return i.date }) + const dates = incomes.map(i => i.date) const datasets = [ { label: 'Revenus', - data: incomes.map(function (i) { return i.amount }), + data: incomes.map(i => i.amount), fill: false, backgroundColor: '#222222', borderColor: '#222222' } ] - const total_payments = {}; + const total_payments = {} const categories_payments = {} - payments.forEach(function (p) { + payments.forEach(p => { if (categories_payments[p.category_id] === undefined) { categories_payments[p.category_id] = {} } @@ -122,18 +122,18 @@ function show_statistics() { datasets.push({ label: 'Total des paiements', - data: dates.map(function (d) { return total_payments[d] || 0 }), + data: dates.map(d => total_payments[d] || 0), fill: false, backgroundColor: '#555555', borderColor: '#555555' }) - Object.keys(categories_payments).forEach(function (category_id) { + Object.keys(categories_payments).forEach(category_id => { const category_payments = categories_payments[category_id] - const category = categories.find(function (c) { return c.id == category_id }) + const category = categories.find(c => c.id == category_id) datasets.push({ label: category.name, - data: dates.map(function (d) { return category_payments[d] || 0 }), + data: dates.map(d => category_payments[d] || 0), fill: false, backgroundColor: category.color, borderColor: category.color, @@ -154,10 +154,10 @@ function show_statistics() { mode: 'nearest', intersect: false, callbacks: { - title: function(tooltipItem, data) { + title: (tooltipItem, data) => { return capitalize(prettyPrintMonth(tooltipItem[0].xLabel)) }, - label: function(tooltipItem, data) { + label: (tooltipItem, data) => { let label = data.datasets[tooltipItem.datasetIndex].label || '' if (label) { label += ': ' @@ -183,9 +183,7 @@ function show_statistics() { { ticks: { beginAtZero: true, - callback: function(value) { - return `${value} €` - } + callback: value => `${value} €` } } ] -- cgit v1.2.3