Nimbin[12]?Web & Tools / dienstplancreator / js/database/shift-labels.js

dienstplancreator git · main

Dienstplan (roster) creator, PHP/JS web app

php javascript roster web · first commit 2023-07-13 · last commit 2023-09-14 (3 years ago) · synced 3 days ago · upstream: github.com/nimbin2/dienstplancreator

JavaScript 50% PHP 40.5% CSS 8.5%
git clone https://git.christianimmanuel.de/web-tools/dienstplancreator.gitwget https://git.christianimmanuel.de/web-tools/dienstplancreator/archive/dienstplancreator.tar.gz
js/database/shift-labels.js 1.7 KB · 57 lines raw
//[{}]
dbAdd_shift_label = async (name, cut) => { 
	let sl = {name: name, cut: cut}
	let response = await fetch("/api/shift_labels/add.php", {
        method: "POST",
        body: JSON.stringify(sl),
        headers: {
        "Content-Type": "application/json; charset=UTF-8"
        }
    })
    return await response.json()
}
dbGet_shift_labels     = async() => { 
    let response = await fetch("/api/shift_labels/get.php", {
        method: "POST",
        headers: {
        "Content-Type": "application/json; charset=UTF-8"
        }
    })  
    let shift_labels = await response.json()
    return shift_labels.shift_labels
}
// {i: int, n: string, c: string}
dbGet_shift_label      = (id) => { return SHIFT_LABELS.find(l => l.id === id)}
dbGet_shift_label_text = (id) => { return dbGet_shift_label(id)?.name }
dbSet_shift_label_text = (id, value) => {
    let sl = {id: id, name: value, cut: dbGet_shift_label_cut(id)}
    console.log("##", sl)
	fetch("/api/shift_labels/update.php", {
        method: "POST",
        body: JSON.stringify(sl),
        headers: {
        "Content-Type": "application/json; charset=UTF-8"
        }
    })
}
dbGet_shift_label_cut  = (id) => { return dbGet_shift_label(id)?.cut }
dbSet_shift_label_cut  = (id, value) => { 
    let sl = {id: id, name: dbGet_shift_label_text(id), cut: value}
	fetch("/api/shift_labels/update.php", {
        method: "POST",
        body: JSON.stringify(sl),
        headers: {
        "Content-Type": "application/json; charset=UTF-8"
        }
    }) 
}
dbRemove_shift_label   = (id) => { 
	fetch("/api/shift_labels/remove.php", {
        method: "POST",
        body: JSON.stringify({id: id}),
        headers: {
        "Content-Type": "application/json; charset=UTF-8"
        }
    }) 
}