const params = { 'dluo': 'DLUO', 'lot': 'Nº de lot', 'q': 'Poids net (g)', 'teneur': 'Teneur en fruits (%)', 'f': 'Quantité de fruits pour 100g (g)', } var tikats; function getCookie(name) { const cookies = document.cookie.split(';'); for (let cookie of cookies) { cookie = cookie.trim(); if (cookie.startsWith(name + '=')) { return cookie.substring(name.length + 1); } } return null; } function post(url, data) { const csrf_token = getCookie('csrftoken'); return $.ajax({ url, data: JSON.stringify(data), method: 'POST', xhrFields: { withCredentials: true }, headers: { 'X-CSRFToken': csrf_token }, }); } function disableButtons() { $('.btn').addClass("disabled"); } function enableButtons() { $('.btn').removeClass('disabled'); } function resetEditModal(force = false) { if ($("#new-add").text() === "Ajouter" && !force) { return; } $("#new-name").val(""); $("#new-type").val("").formSelect(); $("#new-designation").val(""); $("#new-ingredients").val(""); $("#new-description").val(""); $("#new-color")[0].jscolor.fromString("#97a1cc"); $("#new-organic").prop("checked", false); M.updateTextFields(); M.textareaAutoResize($('#new-ingredients')); M.textareaAutoResize($('#new-description')); $("#new-add").text("Ajouter").off('click').click(() => { const req = getTiketteData(); post(backend_api + 'newtikette', req).then(() => { resetEditModal(true); reload(); }); }); } function openEditModal(zett) { M.Modal.getInstance($("#newproduct")).open(); $("#new-name").val(zett.title); $("#new-type").val(zett.category_id).formSelect(); $("#new-designation").val(zett.designation); $("#new-ingredients").val(zett.ingredients); $("#new-description").val(zett.description); $("#new-color")[0].jscolor.fromString(zett.color); $("#new-organic").prop("checked", zett.ab === "inline"); M.updateTextFields(); M.textareaAutoResize($('#new-ingredients')); M.textareaAutoResize($('#new-description')); $("#new-add").text("Modifier").off('click').click(() => { const req = getTiketteData(); req.id = zett.id; resetEditModal(); post(backend_api + 'updatetikette', req).then(reload); }); } function addProduct(tikette) { const zett = tikette; const appbody = $("#appbody"); const block = $('