From 5f4af8dbe4c431218c4bd186a75f50c23b8e5df0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 27 Sep 2018 22:32:27 +0300 Subject: scripts: post over api --- juick-server/src/main/assets/scripts.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'juick-server/src/main/assets') diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js index 5bbbe6f2..5a5fad6b 100644 --- a/juick-server/src/main/assets/scripts.js +++ b/juick-server/src/main/assets/scripts.js @@ -677,6 +677,29 @@ ready(function () { } }); }); + postmsg.addEventListener('submit', e => { + e.preventDefault(); + let formData = new FormData(postmsg); + fetch('/api/post' + '?hash=' + document.getElementById('body').getAttribute('data-hash'), { + method: 'POST', + body: formData, + credentials: 'omit' + }).then(response => { + if (response.ok) { + response.json().then(result => { + if (result.newMessage) { + window.location = new URL(`/m/${result.newMessage.mid}`, window.location.href); + } else { + alert(result.text); + } + }); + } else { + alert('Something went wrong :('); + } + }).catch(error => { + alert(error.message); + }); + }); } document.querySelectorAll('.msg-menu').forEach(function (el) { -- cgit v1.2.3