From a80167282178c94f54434d80522b27f396c4ee76 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 16 Dec 2020 12:47:45 -0600 Subject: [PATCH] Improve error handling for feedback form also make sure the message doesn't self-destruct when closing the dialog --- .../themes/falafel/js/tailbone.feedback.js | 19 ++++++++++++++----- tailbone/templates/themes/falafel/base.mako | 6 ++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tailbone/static/themes/falafel/js/tailbone.feedback.js b/tailbone/static/themes/falafel/js/tailbone.feedback.js index a3cd2af2..9b1d9c4f 100644 --- a/tailbone/static/themes/falafel/js/tailbone.feedback.js +++ b/tailbone/static/themes/falafel/js/tailbone.feedback.js @@ -1,11 +1,10 @@ let FeedbackForm = { - props: ['action'], + props: ['action', 'message'], template: '#feedback-template', methods: { showFeedback() { - this.message = '' this.showDialog = true this.$nextTick(function() { this.$refs.textarea.focus() @@ -30,10 +29,21 @@ let FeedbackForm = { if (data.ok) { alert("Message successfully sent.\n\nThank you for your feedback.") this.showDialog = false + // clear out message, in case they need to send another + this.message = "" } else { - alert("Sorry! Your message could not be sent.\n\n" - + "Please try to contact the site admin some other way.") + this.$buefy.toast.open({ + message: "Failed to send feedback: " + data.error, + type: 'is-danger', + duration: 4000, // 4 seconds + }) } + }, response => { + this.$buefy.toast.open({ + message: "Failed to send feedback! (unknown server error)", + type: 'is-danger', + duration: 4000, // 4 seconds + }) }) }, } @@ -43,6 +53,5 @@ let FeedbackFormData = { referrer: null, userUUID: null, userName: null, - message: '', showDialog: false, } diff --git a/tailbone/templates/themes/falafel/base.mako b/tailbone/templates/themes/falafel/base.mako index 46faf30e..95c5e817 100644 --- a/tailbone/templates/themes/falafel/base.mako +++ b/tailbone/templates/themes/falafel/base.mako @@ -334,7 +334,8 @@ ## Feedback Button / Dialog % if request.has_perm('common.feedback'): + action="${url('feedback')}" + :message="feedbackMessage"> % endif @@ -512,7 +513,8 @@ } let WholePageData = { - contentTitleHTML: ${json.dumps(capture(self.content_title))|n} + contentTitleHTML: ${json.dumps(capture(self.content_title))|n}, + feedbackMessage: "", }