aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/assets/scripts.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-27 22:32:27 +0300
committerGravatar Vitaly Takmazov2018-09-27 22:32:27 +0300
commit5f4af8dbe4c431218c4bd186a75f50c23b8e5df0 (patch)
treeef12a02380d18bd92e331c5d29fbdc82b3918edc /juick-server/src/main/assets/scripts.js
parentfc394e0d31e381afd6e88175b54d9ab8a4007e03 (diff)
scripts: post over api
Diffstat (limited to 'juick-server/src/main/assets/scripts.js')
-rw-r--r--juick-server/src/main/assets/scripts.js23
1 files changed, 23 insertions, 0 deletions
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) {