Files
Kurswerkstatt-Pan/schedule.html
2020-03-12 22:03:31 +01:00

235 lines
8.3 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- development version, includes helpful console warnings -->
<!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
<!-- production version, optimized for size and speed -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.js"></script>
<title>Stundenplan Pflege</title>
<style>
#editmode table, th, td {
border: 1px solid black;
}
#edit-heading {
font-size: x-large;
padding-left: 30px;
}
#editmode input {
border: 0;
/* color: white;
background-color: #996861; */
}
#editmode #item-title textarea {
border: 1px dotted grey;
text-align: center;
}
#editmode #item-reset {
color: rgb(211, 206, 206);
}
#readonlydiv {
color: white;
background-color: #996861;
font-family: sans-serif;
font-size: large;
}
#readonly-heading {
font-size: xx-large;
padding-left: 30px;
margin-top: 0;
}
#readonly-table {
border:none;
border-collapse: collapse;
background-color: #996861;
}
#readonly-table th {
border-top: none;
border-bottom: 4px solid white;
border-left: 4px solid white;
border-right: 4px solid white;
padding: 15px;
}
#readonly-table td {
border-left: 4px solid white;
border-right: 4px solid white;
border-top: none;
border-bottom: none;
padding-left: 15px;
padding-right: 15px;
text-align: center;
}
#readonly-table th:first-child {
border-left: none;
}
#readonly-table th:last-child {
border-right: none;
}
#readonly-table td:first-child {
border-left: none;
}
#readonly-table td:last-child {
border-right: none;
}
</style>
</head>
<body>
<div id="app">
<input type="button"
v-on:click="scheduleToImage()"
value="Bild speichern">
<div id="readonlydiv">
<p id="readonly-heading">{{heading}}</p>
<table id="readonly-table"
ref="table">
<tr>
<th v-for="day in Object.keys(scheduleData)">{{ day }}</th>
</tr>
<tr v-for="slot in amountSlots">
<td v-for="day in Object.keys(scheduleData)">
<div v-if="getSchuduleItem(day, slot).to">
<p id="item-time"><span>{{getSchuduleItem(day, slot).from}}</span> - <span>{{getSchuduleItem(day, slot).to}}</span></p>
<p id="item-title"><span style="white-space: pre-line;">{{getSchuduleItem(day, slot).title}}</span></p>
</div>
</td>
</tr>
</table>
<p style="text-align: center"><span style="white-space: pre-line;">{{caption}}</span></p>
</div>
<div id="editmode">
<input id="edit-heading" type="text"
v-model="heading">
<table id="table"
ref="table"
style="border: 1px solid">
<tr>
<th v-for="day in Object.keys(scheduleData)">{{ day }}</th>
</tr>
<tr v-for="slot in amountSlots">
<td v-for="day in Object.keys(scheduleData)">
<div>
<p id="item-time"><input id="item-from"
max="20:00"
min="09:00"
step="900"
type="time"
v-model="getSchuduleItem(day, slot).from"> - <input id="item-to"
max="20:00"
min="09:00"
step="900"
type="time"
v-model="getSchuduleItem(day, slot).to"></p>
<p id="item-title">
<textarea v-model="getSchuduleItem(day, slot).title"></textarea></p>
</div><input type="button" v-on:click="resetScheduleItem(day, slot)" value="Zurücksetzen">
</td>
</tr>
</table><input style="border: 1px solid black"
type="text"
v-model="pw"
v-on:click="pw=undefined">
<textarea cols="50"
rows="4"
v-model="caption"></textarea> <input type="submit"
v-on:click="saveSchedule()"
value="Speichern"> <input type="button"
v-on:click="exportSchedule()"
value="Datei exportieren">
</div>
</div>
<script>
var app = new Vue({
el: '#app',
data: () => {
return {
amountSlots: 6,
pw: "Passwort",
heading: "Stundenplan 2019",
caption: "* mit Stillberaterin und Kinderkrankenschwester Rhianon Grill\nfür mehr Angebote rund um Mama/Baby www.stillberatungimrottal.de",
scheduleData:{"Montag": [{"from": "09:00", "to": "10:15", "title": "Hatha Joga"}, {"from": "10:30", "to": "11:45", "title": "Joga für Schwangere"}, {}, {"title": ""}, {"from": "", "to": "", "title": ""}, {}], "Dienstag": [{}, {}, {"from": "15:30", "to": "16:30", "title": "Musikgarten"}, {"from": "18:00", "to": "19:30", "title": "Hatha/Vinjasa Yoga"}, {}, {}], "Mittwoch": [{"from": "09:00", "to": "10:15", "title": "Rückbildung"}, {"from": "10:30", "to": "11:30", "title": "Fit für Dich"}, {}, {}, {}, {}], "Donnerstag": [{"from": "09:00", "to": "10:00", "title": "Babymassage"}, {"from": "10:00", "to": "11:15", "title": "Rückbildung"}, {}, {}, {}, {}], "Freitag": [{"from": "09:00", "to": "10:30", "title": "Stilltreff * 2 wöchentlich"}, {}, {"from": "16:00", "to": "19:00", "title": "Geburtsvorbereitung"}, {}, {}, {}], "Samstag": [{"from": "09:00", "to": "12:00", "title": "Geburtsvorbereitung"}, {}, {}, {}, {}, {}]}
}
},
created() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;
if (this.status == 200) {
var data = JSON.parse(this.response);
window.app.restoreSettings(data);
}
};
xhr.open("GET", "https://kurswerkstatt-pan.de/api/schedule", true);
xhr.send();
},
methods: {
restoreSettings: function(data) {
this.scheduleData = data.schedule;
this.heading = data.heading;
this.caption = data.caption;
},
getSchuduleItem: function(day, slot) {
return this.scheduleData[day][slot-1];
},
resetScheduleItem: function(day, slot) {
this.scheduleData[day][slot-1].from = undefined;
this.scheduleData[day][slot-1].to = undefined;
this.scheduleData[day][slot-1].title = undefined;
},
saveSchedule: function() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://kurswerkstatt-pan.de/api/schedule", true);
xhr.setRequestHeader('Content-Type', 'application/html');
xhr.onload = function(e) {
e.target.status === 200 ? alert("Gespeichert") : alert("Fehler: Falsches Passwort?")
}
xhr.onerror = function(e) {
alert("Fehler: \"Datei exportieren\"-Button klicken und Datei Felix schicken")
}
domtoimage.toJpeg(document.getElementById('readonlydiv'), { quality: 0.95 })
.then((scheduleImage) => {
xhr.send(JSON.stringify({
pw: this.pw,
schedule: this.scheduleData,
caption: this.caption,
heading: this.heading,
image: scheduleImage.split(',')[1]
}));
})
},
scheduleToImage: function () {
domtoimage.toJpeg(document.getElementById('readonlydiv'), { quality: 0.95 })
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = 'Stundenplan.jpg';
link.href = dataUrl;
link.click();
})
},
exportSchedule: function downloadObjectAsJson(){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify({'schedule': this.scheduleData, 'caption': this.caption, heading: this.heading}));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", "Studenplan" + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}
}
})
</script>
</body>
</html>