const params = { 'dluo': 'DLUO', 'lot': 'NÂș de lot', 'qty': 'Poids net (g)', 'vol': 'Volume net (cL)', 'teneur': 'Teneur en fruits (%)', 'fruit': 'QuantitĂ© de fruits pour 100g (g)', } function loadAll(zetikettes) { const appbody = $("#appbody"); for (let zett of zetikettes) { const block = $('
'); for (let sub in zett.subs) { block.append($(`
`)); } const loader = $('
') .hide(); const action = $('
') .append($('generate') .click(() => { const subs = block.find(':text') .toArray() .reduce((obj, el) => ({...obj, [el.name]: el.value}), {}); const req = { sticker: zett.sticker, subs, landscape: zett.landscape, }; loader.show(); $('.btn').addClass("disabled"); $.post(backend_api, JSON.stringify(req)) .then(data => { console.log(data); const pdfbtn = $(`open pdf`); action.append(pdfbtn); }) .catch(err => { console.log(err); }) .always(() => { loader.hide(); $('.btn').removeClass('disabled'); }); }) .append(loader)); appbody .append($('
  • ') .append($(`
    ${zett.title}
    `)) .append($('
    ') .append(block) .append(action))); } $('.collapsible').collapsible(); konami(); } function konami() { var k = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65], n = 0; $(document).keydown(function (e) { if (e.keyCode === k[n++]) { if (n === k.length) { document.location.href = backend_api + 'admin'; } } else { n = 0; } }); } $(document).ready(async () => { try { const resp = await $.ajax({ url: backend_api + 'list', timeout: 1000, }); loadAll(resp.tikettes.sort((a, b) => (a.title < b.title) ? -1 : 1)); } catch(e) { const appbody = $("#appbody"); appbody.append(`
  • Could not reach backend server`); throw e; } });