From b8f41c8d9454a78acfcb06aef968a94f3d51f643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Thuret?= Date: Sat, 9 Oct 2021 11:25:56 +0200 Subject: [PATCH] Adding a notification after sending --- app/app.py | 7 +++++++ app/templates/index.html | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index ea54a2d..ea69d43 100644 --- a/app/app.py +++ b/app/app.py @@ -613,6 +613,13 @@ def create_app(args): def spec(): return jsonify(swag) + + @app.route("/suggest", methods=["POST"]) + @limiter.exempt + def suggest(): + # TODO: + return jsonify({"success": True}) + SWAGGER_URL = "/docs" # URL for exposing Swagger UI (without trailing '/') API_URL = "/spec" diff --git a/app/templates/index.html b/app/templates/index.html index 2d15cc2..2438e79 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -511,6 +511,8 @@ sendSuggestion: function(e) { e.preventDefault(); + var self = this; + var request = new XMLHttpRequest(); self.transRequest = request; @@ -520,7 +522,28 @@ data.append("source", self.sourceLang); data.append("target", self.targetLang); - request.open('POST', BaseUrl + '/translate', true); + request.open('POST', BaseUrl + '/suggest', true); + request.onload = function() { + try{ + var res = JSON.parse(this.response); + if (res.success){ + M.toast({html: 'Thanks for your correction.'}) + self.closeSuggestTranslation(e) + }else{ + throw new Error(res.error || "Unknown error"); + } + }catch(e){ + self.error = e.message; + self.closeSuggestTranslation(e) + } + }; + + request.onerror = function() { + self.error = "Error while calling /suggest"; + self.loadingTranslation = false; + }; + + request.send(data); }, deleteText: function(e){ e.preventDefault();