From 4b44632f2ee2ab0df286e7710efd5ac7e64ba95c Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 7 Jun 2018 08:06:09 +0000 Subject: [PATCH] add contact form --- lib/extensions/admin/index.html | 46 ++++++++++++++++++++++---- lib/extensions/admin/js/app.js | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/lib/extensions/admin/index.html b/lib/extensions/admin/index.html index a307304..d2bfd48 100644 --- a/lib/extensions/admin/index.html +++ b/lib/extensions/admin/index.html @@ -67,20 +67,52 @@ TCP # Run ssh with (your domain, no port): ssh lucky-duck-42.telebit.cloud -

-
diff --git a/lib/extensions/admin/js/app.js b/lib/extensions/admin/js/app.js index 6d2c296..5783b4a 100644 --- a/lib/extensions/admin/js/app.js +++ b/lib/extensions/admin/js/app.js @@ -3,4 +3,61 @@ document.body.hidden = false; +function formSubmit() { + var msg = { + address: document.querySelector('.js-list-address').value + , comment: 'telebit.cloud: ' + (document.querySelector('.js-list-comment').value || '') + }; + + window.fetch('https://api.ppl.family/api/ppl.family/public/list', { + method: 'POST' + , cors: true + , headers: new Headers({ 'Content-Type': 'application/json' }) + , body: JSON.stringify(msg) + }).then(function (resp) { + return resp.json().then(function (data) { + if (data.error) { + window.alert("Couldn't save your message. Email coolaj86@gmail.com instead."); + return; + } + document.querySelector('.js-list-form').hidden = true; + document.querySelector('.js-list-form').className += ' hidden'; + document.querySelector('.js-list-thanks').hidden = false; + document.querySelector('.js-list-thanks').className = document.querySelector('.js-list-thanks').className.replace(/\s*hidden\b/, ''); + }, function () { + window.alert("Couldn't save your message. Email coolaj86@gmail.com instead."); + }); + }, function () { + window.alert("Didn't get your message. Bad network connection? Email coolaj86@gmail.com instead."); + }); +} +document.body.addEventListener('submit', function (ev) { + if (ev.target.matches('.js-list-form')) { + ev.preventDefault(); + ev.stopPropagation(); + formSubmit(); + return; + } +}); +document.body.addEventListener('click', function (ev) { + if (ev.target.matches('.js-list-submit')) { + ev.preventDefault(); + ev.stopPropagation(); + formSubmit(); + return; + } + /* + if (ev.target.closest('.js-navbar-toggle')) { + ev.preventDefault(); + ev.stopPropagation(); + if (/show/.test(document.querySelector('.js-navbar-collapse').className)) { + document.querySelector('.js-navbar-collapse').className = document.querySelector('.js-navbar-collapse').className.replace(/\s+show\b/, ''); + } else { + document.querySelector('.js-navbar-collapse').className += ' show'; + } + return; + } + */ +}); + }());