From f3c2a2f72526c528c2bd2a94a3215cc522dafc0e Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Wed, 28 Jun 2023 23:17:03 +0200 Subject: [PATCH] Now handles uploading new tempaltes!!1 Just point your browser to /zetikettes/newtikette.html Password is in web.py --- README.md | 9 +- static/index.html | 2 +- static/newtikette.html | 45 +++++++ static/newtikette.js | 130 +++++++++++++++++++ static/zetikettes.js | 287 +++-------------------------------------- tikettes.json | 1 + web.py | 164 +++++++++++++++++++++-- 7 files changed, 352 insertions(+), 286 deletions(-) create mode 100644 static/newtikette.html create mode 100644 static/newtikette.js create mode 100644 tikettes.json diff --git a/README.md b/README.md index ca36e28..69f9d86 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,7 @@ docker run -d --rm -p 8000:8000 -v /var/lib/zetikettes/templates:/data zetikette Change available templates -------------------------- -1. make or update templates -1. add them to tempaltes/ -1. update static/zetikettes.js -1. git commit && git push -1. update /var/lib/zetikettes -1. no need to restart the container (magic!) +1. go to /zetikettes/newtikette.html +1. add the newtikette +1. still no need to restart the container (magic!) 2. profit. diff --git a/static/index.html b/static/index.html index 98ce5ec..1530b38 100644 --- a/static/index.html +++ b/static/index.html @@ -3,7 +3,7 @@ - zetikettes 0.1 + zetikettes 0.2 diff --git a/static/newtikette.html b/static/newtikette.html new file mode 100644 index 0000000..f9be025 --- /dev/null +++ b/static/newtikette.html @@ -0,0 +1,45 @@ + + + + + + zetikettes 0.2 + + + + + + + + + + + + + + +
+

Zétikwett's

+
+
+
+
+
+
+ + + diff --git a/static/newtikette.js b/static/newtikette.js new file mode 100644 index 0000000..c23f8ca --- /dev/null +++ b/static/newtikette.js @@ -0,0 +1,130 @@ +const backend_api = { + 'prod': '/zetikettes/srv/', + 'dev': '/zetikettes.dev/srv/', +}[config]; + +const params = [ + ['dluo', 'DLUO', true], + ['lot', 'Nº de lot', true], + ['qty', 'Poids net (g)', true], + ['teneur', 'Teneur en fruits (%)', false], + ['fruit', 'Quantité de fruits pour 100g (g)', false], +] + +function post() { + const lemot = $('input[type=password]').val(); + const formdata = new FormData($('form')[0]); + formdata.append('lemotdepasse', lemot); + $.ajax({ + url: backend_api + `newtikette`, + type: 'POST', + data: formdata, + + contentType: false, + processData: false, + + xhr: function () { + var myXhr = $.ajaxSettings.xhr(); + if (myXhr.upload) { + // For handling the progress of the upload + myXhr.upload.addEventListener('progress', function (e) { + if (e.lengthComputable) { + $('progress').attr({ + value: e.loaded, + max: e.total, + }); + } + }, false); + } + return myXhr; + } + }) + .then(data => { + console.log(data); + }) + .catch(err => { + console.log(err); + if (err.status == 403) { + M.toast({html: 'access denied'}); + } else if (err.status == 500) { + M.toast({html: 'server error'}); + } + }) + .always(() => { + $('.progress').hide(); + $('.btn').removeClass('disabled'); + }); +} + +$(document).ready(async () => { + const appbody = $("#appbody"); + const block = $('
'); + block.append($(`
+ `)); + block.append($(`
`)); + const subst = $('

'); + for (let param of params) { + subst.append($(`
`)); + } + block.append(subst); + + block.append(`
+
+ File + +
+
+ +
+ `) + + const loader = $('
') + .hide(); + + let setup = false; + + const action = $('
') + .append($('add newtikette') + .click(() => { + if (!setup) { + setup = true; + $('input[type=password]').on('keydown', e => { + if (e.keyCode == 13 && !e.repeat) { + $('.modal').modal('close'); + post(); + } + }); + $("#pushgo").click(() => { post(); }); + } + + $('.modal').modal('open'); + $('input[type=password]').focus(); + + loader.show(); + $('.btn').addClass("disabled"); + $('.modal-close').removeClass("disabled"); + + }) + .append(loader)); + + const lemotdepasse = $(` +