Now handles uploading new tempaltes!!1

Just point your browser to /zetikettes/newtikette.html
Password is in web.py
This commit is contained in:
2023-06-28 23:17:03 +02:00
parent c4e03c9550
commit f3c2a2f725
7 changed files with 352 additions and 286 deletions

View File

@@ -3,7 +3,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>zetikettes 0.1</title>
<title>zetikettes 0.2</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Compiled and minified CSS -->

45
static/newtikette.html Normal file
View File

@@ -0,0 +1,45 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>zetikettes 0.2</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="config.js"></script>
<script src="newtikette.js"></script>
<style>
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
</style>
</head>
<body>
<header class="container center orange-text">
<h1>Zétikwett's</h1>
</header>
<main class="container row">
<div class="col m6 offset-m3 s12">
<div id="appbody" class="container"></div>
</div>
</main>
<footer class="page-footer">
<div class="container row">
<span class="col right">displayed with recycled electrons.</span>
</div>
</footer>
</body>
</html>

130
static/newtikette.js Normal file
View File

@@ -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 = $('<form class="section">');
block.append($(`<div class="input-field"><label class="active">Title</label>
<input type="text" name="title" value="Gelée de brandade aux cêpes biou">`));
block.append($(`<div class="input-field"><label class="active">
<input type="checkbox" name="landscape"><span>landscape</span></label>`));
const subst = $('<div class="section"><label class="active">Substitutions</label><p></p>');
for (let param of params) {
subst.append($(`<div><label class="active"><input type="checkbox" name="${param}" ${param[2] ? 'checked': ''}>
<span>\${${param[0]}}: ${param[1]}</span></label>`));
}
block.append(subst);
block.append(`<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input type="file" name="sticker" accept=".svg">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Template .svg file">
</div>
`)
const loader = $('<div class="progress"><div class="determinate"></div></div>')
.hide();
let setup = false;
const action = $('<div class="section">')
.append($('<a class="btn">add newtikette<a>')
.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 = $(`
<div id="modal1" class="modal">
<div class="modal-content">
<h4>A lemotdepasse is needed</h4>
<div class="input-field"><label class="active">lemotdepasse</label>
<input type="password">
</div>
<div class="modal-footer">
<a class="btn modal-close" id="pushgo">go</a>
</div>
`);
appbody
.append(lemotdepasse)
.append(block)
.append(action);
$(".modal").modal();
});

View File

@@ -3,275 +3,6 @@ const backend_api = {
'dev': '/zetikettes.dev/srv/',
}[config];
const zetikettes = [
{
'title': 'Aromate herbes de Provence',
'sticker': 'Aromate - Herbes de Provence.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': false,
},
{
'title': 'Aromate herbes de Provence avec romarin',
'sticker': 'Aromate - Herbes de Provence avec romarin.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': false,
},
{
'title': 'Aromate thym',
'sticker': 'Aromate - Thym.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': false,
},
{
'title': 'Chocolat lavande',
'sticker': 'Chocolat - Lavande.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '100',
},
'landscape': false,
},
{
'title': 'Confiture de Mirabelle - non bio',
'sticker': 'Confiture - Mirabelle.svg',
'subs': {
'dluo': 'germinal 9999',
'fruit': '80',
'teneur': '50',
'lot': '0000-0',
'qty': '370',
},
'landscape': true,
},
{
'title': 'Gelée Extra de groseille',
'sticker': 'Gelée Extra - Groseille.svg',
'subs': {
'dluo': 'germinal 9999',
'fruit': '80',
'teneur': '50',
'lot': '0000-0',
'qty': '370',
},
'landscape': true,
},
{
'title': 'Gelée Extra de groseille au basilic',
'sticker': 'Gelée Extra - Groseille Basilic.svg',
'subs': {
'dluo': 'germinal 9999',
'fruit': '80',
'teneur': '50',
'lot': '0000-0',
'qty': '370',
},
'landscape': true,
},
{
'title': 'Gelée Extra de cassis',
'sticker': 'Gelée Extra - Cassis.svg',
'subs': {
'dluo': 'germinal 9999',
'fruit': '80',
'teneur': '50',
'lot': '0000-0',
'qty': '370',
},
'landscape': true,
},
{
'title': 'Pesto ail des ours',
'sticker': 'Pesto - Ail des Ours - 100% Olive.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '150',
},
'landscape': true,
},
{
'title': 'Sel grillade et légumes',
'sticker': 'Sel - Grillade.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': true,
},
{
'title': 'Sel herbes de Provence',
'sticker': 'Sel - Herbes de Provence.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': true,
},
{
'title': 'Sel viande blanche et poisson',
'sticker': 'Sel - Poisson et Viande Blanche.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': true,
},
{
'title': 'Sel salade',
'sticker': 'Sel - Salade.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': true,
},
{
'title': 'Sel salade sans basilic',
'sticker': 'Sel - Salade - Sans Basilic.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '40',
},
'landscape': true,
},
{
'title': 'Sirop de sureau',
'sticker': 'Sirop - Sureau.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '75',
},
},
{
'title': 'Sirop de lavande',
'sticker': 'Sirop - Lavande.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '75',
},
},
{
'title': 'Sirop de cassis',
'sticker': 'Sirop - Cassis.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '75',
},
'landscape': false,
},
{
'title': 'Sirop de thym',
'sticker': 'Sirop - Thym.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '75',
},
'landscape': false,
},
{
'title': 'Sirop de mélisse',
'sticker': 'Sirop - Melisse.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '75',
},
'landscape': false,
},
{
'title': 'Sirop de menthe verte',
'sticker': 'Sirop - Menthe Verte.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '75',
},
'landscape': false,
},
{
'title': 'Tisane Hiver',
'sticker': 'Tisane - Hiver.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '25',
},
'landscape': false,
},
{
'title': 'Tisane Joie de Vivre',
'sticker': 'Tisane - Joie de Vivre.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '25',
},
'landscape': false,
},
{
'title': 'Tisane Réconfort de la Gorge (Origan, Thym, Agastache, Mauve)',
'sticker': 'Tisane - Reconfort de la Gorge - Origan Thym Agastache Mauve.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '25',
},
'landscape': false,
},
{
'title': 'Tisane Nuit Étoilée (Mélisse, Lavande, Aubépine)',
'sticker': 'Tisane - Nuit Etoilee - Melisse Lavande Aubepine.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '25',
},
'landscape': false,
},
{
'title': 'Tisane Détox (Menthe, Sarriette, Basilic, Souci)',
'sticker': 'Tisane - Detox - Menthe Sarriette Basilic Souci.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '25',
},
'landscape': false,
},
{
'title': 'Tisane digestion',
'sticker': 'Tisane - Digestion.svg',
'subs': {
'dluo': 'germinal 9999',
'lot': '0000-0',
'qty': '25',
},
'landscape': false,
},
];
const params = {
'dluo': 'DLUO',
'lot': 'Nº de lot',
@@ -281,7 +12,7 @@ const params = {
'fruit': 'Quantité de fruits pour 100g (g)',
}
$(document).ready(() => {
function loadAll(zetikettes) {
const appbody = $("#appbody");
for (let zett of zetikettes) {
const block = $('<div class="section">');
@@ -331,4 +62,18 @@ $(document).ready(() => {
}
$('.collapsible').collapsible();
});
}
$(document).ready(async () => {
try {
const resp = await $.ajax({
url: backend_api + 'list',
timeout: 1000,
});
loadAll(resp.tikettes);
} catch(e) {
const appbody = $("#appbody");
appbody.append(`<li>Could not reach backend server`);
throw e;
}
});