Implemented POST for sending user feedback
[pithos] / web_client / src / gr / grnet / pithos / web / client / FeedbackDialog.java
index a435f2c..4dd3d56 100644 (file)
  */
 package gr.grnet.pithos.web.client;
 
+import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.rest.PostRequest;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.event.dom.client.ClickEvent;
 import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.event.dom.client.KeyCodes;
+import com.google.gwt.http.client.Response;
 import com.google.gwt.user.client.Event.NativePreviewEvent;
 import com.google.gwt.user.client.ui.Anchor;
 import com.google.gwt.user.client.ui.Button;
@@ -62,7 +68,7 @@ public class FeedbackDialog extends DialogBox {
        /**
         * The widget constructor.
         */
-       public FeedbackDialog() {
+       public FeedbackDialog(final Pithos app) {
                // Set the dialog's caption.
                Anchor close = new Anchor();
                close.addStyleName("close");
@@ -83,12 +89,12 @@ public class FeedbackDialog extends DialogBox {
                VerticalPanel inner = new VerticalPanel();
                inner.addStyleName("inner");
                // Create the text and set a style name so we can style it with CSS.
-               HTML text = new HTML("Pithos+ is currently in alpha test and we would appreciate any<br>" + "kind of feedback. We welcome any suggestions, questions and<br>" + " bug reports you may have.");
+               HTML text = new HTML("Pithos is currently in alpha test and we would appreciate any<br>" + "kind of feedback. We welcome any suggestions, questions and<br>" + " bug reports you may have.");
                text.setStyleName("pithos-credentialsText");
                inner.add(text);
                FlexTable table = new FlexTable();
                table.setText(0, 0, "Please describe your problem here, provide as many details as possible");
-               TextArea msg = new TextArea();
+               final TextArea msg = new TextArea();
                msg.setWidth("100%");
                msg.setHeight("100px");
                table.setWidget(1, 0, msg);
@@ -99,9 +105,28 @@ public class FeedbackDialog extends DialogBox {
 
                // Create the 'OK' button, along with a listener that hides the dialog
                // when the button is clicked.
-               Button confirm = new Button("submit feedback", new ClickHandler() {
+               Button confirm = new Button("Submit feedback", new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
+                               PostRequest sendFeedback = new PostRequest("/tools/", "", "feedback", "feedback-msg=" + msg.getText()) {
+                                       
+                                       @Override
+                                       protected void onUnauthorized(Response response) {
+                                               app.sessionExpired();
+                                       }
+                                       
+                                       @Override
+                                       public void onSuccess(Resource result) {
+                                               app.displayInformation("Feedback sent");
+                                       }
+                                       
+                                       @Override
+                                       public void onError(Throwable t) {
+                                               GWT.log("", t);
+                                       }
+                               };
+                               sendFeedback.setHeader("X-Auth-Token", app.getToken());
+                               Scheduler.get().scheduleDeferred(sendFeedback);
                                hide();
                        }
                });