2017-04-20 03:33:32 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Tooty</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
2017-05-18 04:33:46 -04:00
|
|
|
<link href="bootstrap/css/bootstrap.min.css" media="all" rel="stylesheet" />
|
2017-04-30 06:56:09 -04:00
|
|
|
<link href="style.css" media="all" rel="stylesheet" />
|
|
|
|
<link rel="icon" type="image/png" sizes="192x192" href="images/favicon-192x192.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="96x96" href="images/favicon-96x96.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
|
|
|
|
<meta name="msapplication-TileColor" content="#272b30">
|
|
|
|
<meta name="theme-color" content="#272b30">
|
2017-04-20 03:33:32 -04:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<script src="app.js"></script>
|
|
|
|
<script>
|
2017-05-09 12:43:12 -04:00
|
|
|
// Note: this is a transitional upgrade to new client storage format, which
|
|
|
|
// is now now a list of clients, which all require an "account" property set.
|
|
|
|
const oldClient = JSON.parse(localStorage.getItem("tooty.client"));
|
|
|
|
const defaultClients = oldClient ? [oldClient] : [];
|
|
|
|
const clients = (JSON.parse(localStorage.getItem("tooty.clients")) || defaultClients)
|
|
|
|
.map(client => {
|
|
|
|
if (!client.hasOwnProperty("account")) {
|
|
|
|
client.account = null;
|
|
|
|
}
|
|
|
|
return client;
|
|
|
|
});
|
2017-05-04 02:31:58 -04:00
|
|
|
|
2017-04-20 03:33:32 -04:00
|
|
|
const app = Elm.Main.fullscreen({
|
2017-05-09 12:43:12 -04:00
|
|
|
clients: clients,
|
2017-04-20 03:33:32 -04:00
|
|
|
registration: JSON.parse(localStorage.getItem("tooty.registration"))
|
|
|
|
});
|
2017-05-04 02:31:58 -04:00
|
|
|
|
2017-05-09 12:43:12 -04:00
|
|
|
app.ports.saveClients.subscribe(json => {
|
|
|
|
localStorage.setItem("tooty.clients", json);
|
2017-04-20 03:33:32 -04:00
|
|
|
});
|
2017-05-04 02:31:58 -04:00
|
|
|
|
2017-04-20 03:33:32 -04:00
|
|
|
app.ports.saveRegistration.subscribe(json => {
|
|
|
|
localStorage.setItem("tooty.registration", json);
|
|
|
|
});
|
2017-05-04 02:31:58 -04:00
|
|
|
|
2017-05-09 12:43:12 -04:00
|
|
|
app.ports.deleteRegistration.subscribe(json => {
|
|
|
|
localStorage.removeItem("tooty.registration");
|
|
|
|
});
|
|
|
|
|
2017-05-01 16:10:34 -04:00
|
|
|
app.ports.setStatus.subscribe(function(data) {
|
|
|
|
var element = document.getElementById(data.id);
|
|
|
|
if (element) {
|
|
|
|
element.value = data.status;
|
|
|
|
// Reset cursor at the end
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
});
|
2017-05-04 02:31:58 -04:00
|
|
|
|
|
|
|
app.ports.scrollIntoView.subscribe(function(id) {
|
|
|
|
requestAnimationFrame(function() {
|
|
|
|
var element = document.getElementById(id);
|
|
|
|
if (element) {
|
2017-05-06 04:36:17 -04:00
|
|
|
element.scrollIntoView(false);
|
2017-05-04 02:31:58 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-11 04:55:15 -04:00
|
|
|
app.ports.uploadMedia.subscribe(data => {
|
|
|
|
const files = Array.from(document.getElementById(data.id).files);
|
|
|
|
const formData = new FormData();
|
|
|
|
formData.append("file", files[0]);
|
|
|
|
fetch(data.url, {
|
|
|
|
method: "POST",
|
|
|
|
headers: { Authorization: "Bearer " + data.token },
|
|
|
|
body: formData,
|
|
|
|
})
|
|
|
|
.catch(err => app.ports.uploadError.send(err.message))
|
|
|
|
.then(response => response.text())
|
|
|
|
.then(app.ports.uploadSuccess.send);
|
|
|
|
});
|
2017-06-02 08:11:50 -04:00
|
|
|
|
|
|
|
function notify(data) {
|
|
|
|
const notif = new Notification(data.title, {
|
|
|
|
icon: data.icon,
|
|
|
|
body: data.body,
|
|
|
|
});
|
|
|
|
notif.onclick = () => location.hash = data.clickUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
app.ports.notify.subscribe(data => {
|
|
|
|
if (Notification.permission === "granted") {
|
|
|
|
notify(data);
|
|
|
|
} else if (Notification.permission !== "denied") {
|
|
|
|
Notification.requestPermission(permission => {
|
|
|
|
if (permission === "granted") {
|
|
|
|
notify(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-04-20 03:33:32 -04:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|