From 118a74b183807d5ed2cbda639aee5c2a4e5f8712 Mon Sep 17 00:00:00 2001 From: Giovane Date: Fri, 18 Sep 2015 14:15:32 -0300 Subject: #442 Creates feedback sender component. --- web-ui/app/js/mail_view/data/feedback_sender.js | 49 +++++++++++++++++++++++++ web-ui/app/js/mail_view/ui/feedback_box.js | 4 +- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 web-ui/app/js/mail_view/data/feedback_sender.js (limited to 'web-ui/app') diff --git a/web-ui/app/js/mail_view/data/feedback_sender.js b/web-ui/app/js/mail_view/data/feedback_sender.js new file mode 100644 index 00000000..2232dbe4 --- /dev/null +++ b/web-ui/app/js/mail_view/data/feedback_sender.js @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see . + */ +define( + [ + 'flight/lib/component', + 'helpers/monitored_ajax', + 'page/events' + ], + function (defineComponent, monitoredAjax, events) { + 'use strict'; + + return defineComponent(function () { + this.defaultAttrs({ + feedbackResource: '/feedback' + }); + + this.successSubmittingFeedback = function() { + this.trigger(document, events.feedback.submitted); + }; + + this.submitFeedback = function(event, data) { + monitoredAjax.call(_, this, this.attr.feedbackResource, { + type: 'POST', + dataType: 'json', + contentType: 'application/json; charset=utf-8', + data: JSON.stringify(data) + }).done(this.successSubmittingFeedback()); + }; + + this.after('initialize', function () { + this.on(document, events.feedback.submit, this.submitFeedback); + }); + + }); +}); diff --git a/web-ui/app/js/mail_view/ui/feedback_box.js b/web-ui/app/js/mail_view/ui/feedback_box.js index f6994554..aad35f2a 100644 --- a/web-ui/app/js/mail_view/ui/feedback_box.js +++ b/web-ui/app/js/mail_view/ui/feedback_box.js @@ -43,8 +43,8 @@ define(['flight/lib/component', 'views/templates', 'page/events', 'features'], this.submitFeedback = function () { var feedback = this.select('textBox').val(); - this.trigger(document, events.feedback.submit, { feedback: feedback}); - } + this.trigger(document, events.feedback.submit, { feedback: feedback }); + }; this.after('initialize', function () { if (features.isEnabled('feedback')) { -- cgit v1.2.3