Send Feedback now works with the new API
authorChristos KK Loverdos <loverdos@gmail.com>
Thu, 7 Feb 2013 11:15:21 +0000 (13:15 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Thu, 7 Feb 2013 11:15:21 +0000 (13:15 +0200)
I had to reformat the code as well, since formatting was inconsistent.

src/gr/grnet/pithos/web/client/FeedbackDialog.java

index dbd6cd6..0461def 100644 (file)
@@ -34,9 +34,6 @@
  */
 package gr.grnet.pithos.web.client;
 
-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;
@@ -45,14 +42,8 @@ import com.google.gwt.event.dom.client.KeyCodes;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.i18n.client.Dictionary;
 import com.google.gwt.user.client.Event.NativePreviewEvent;
-import com.google.gwt.user.client.ui.Anchor;
-import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.DialogBox;
-import com.google.gwt.user.client.ui.FlexTable;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;
-import com.google.gwt.user.client.ui.TextArea;
-import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.*;
+import gr.grnet.pithos.web.client.rest.PostRequest;
 
 
 /**
@@ -60,111 +51,113 @@ import com.google.gwt.user.client.ui.VerticalPanel;
  */
 public class FeedbackDialog extends DialogBox {
 
-       Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
-       
-       Pithos app;
-       
-       String appData;
-       
-       TextArea msg;
-       
-       /**
-        * The widget constructor.
-        */
-       public FeedbackDialog(final Pithos _app, final String _appData) {
-               app = _app;
-               appData = _appData;
-               
-               // Set the dialog's caption.
-               Anchor close = new Anchor("close");
-               close.addStyleName("close");
-               close.addClickHandler(new ClickHandler() {
-                       
-                       @Override
-                       public void onClick(ClickEvent event) {
-                               hide();
-                       }
-               });
-               setText("Send feedback");
-               setGlassEnabled(true);
-               
-               setStyleName("pithos-DialogBox");
-
-               VerticalPanel outer = new VerticalPanel();
-               outer.add(close);
-               
-               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.");
-               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");
-               msg = new TextArea();
-               msg.setWidth("100%");
-               msg.setHeight("100px");
-               table.setWidget(1, 0, msg);
-
-               table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
-               table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
-               inner.add(table);
-
-               // 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() {
-                       @Override
-                       public void onClick(ClickEvent event) {
-                               sendFeedback();
-                               hide();
-                       }
-               });
-               confirm.addStyleName("button");
-               inner.add(confirm);
-               outer.add(inner);
-               outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
-               setWidget(outer);
-       }
-
-       @Override
-       protected void onPreviewNativeEvent(NativePreviewEvent preview) {
-               super.onPreviewNativeEvent(preview);
-               NativeEvent evt = preview.getNativeEvent();
-               if (evt.getType().equals("keydown")) {
-                       // Use the popup's key preview hooks to close the dialog when
-                       // either enter or escape is pressed.
-                       switch (evt.getKeyCode()) {
-                               case KeyCodes.KEY_ENTER:
-                                       sendFeedback();
-                                       hide();
-                                       break;
-                               case KeyCodes.KEY_ESCAPE:
-                                       hide();
-                                       break;
-                       }
-               }
-       }
-
-       /**
-        */
-       void sendFeedback() {
-               PostRequest sendFeedback = new PostRequest("", "", otherProperties.get("feedbackUrl"), "feedback_msg=" + msg.getText() + "&feedback_data=" + appData + "&auth=" + app.getUserToken()) {
-                       
-                       @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);
-                       }
-               };
-               Scheduler.get().scheduleDeferred(sendFeedback);
-       }
+    Dictionary otherProperties = Dictionary.getDictionary("otherProperties");
+
+    Pithos app;
+
+    String appData;
+
+    TextArea msg;
+
+    /**
+     * The widget constructor.
+     */
+    public FeedbackDialog(final Pithos _app, final String _appData) {
+        app = _app;
+        appData = _appData;
+
+        // Set the dialog's caption.
+        Anchor close = new Anchor("close");
+        close.addStyleName("close");
+        close.addClickHandler(new ClickHandler() {
+
+            @Override
+            public void onClick(ClickEvent event) {
+                hide();
+            }
+        });
+        setText("Send feedback");
+        setGlassEnabled(true);
+
+        setStyleName("pithos-DialogBox");
+
+        VerticalPanel outer = new VerticalPanel();
+        outer.add(close);
+
+        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.");
+        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");
+        msg = new TextArea();
+        msg.setWidth("100%");
+        msg.setHeight("100px");
+        table.setWidget(1, 0, msg);
+
+        table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
+        table.getFlexCellFormatter().setStyleName(0, 1, "props-values");
+        inner.add(table);
+
+        // 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() {
+            @Override
+            public void onClick(ClickEvent event) {
+                sendFeedback();
+                hide();
+            }
+        });
+        confirm.addStyleName("button");
+        inner.add(confirm);
+        outer.add(inner);
+        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
+        setWidget(outer);
+    }
+
+    @Override
+    protected void onPreviewNativeEvent(NativePreviewEvent preview) {
+        super.onPreviewNativeEvent(preview);
+        NativeEvent evt = preview.getNativeEvent();
+        if(evt.getType().equals("keydown")) {
+            // Use the popup's key preview hooks to close the dialog when
+            // either enter or escape is pressed.
+            switch(evt.getKeyCode()) {
+                case KeyCodes.KEY_ENTER:
+                    sendFeedback();
+                    hide();
+                    break;
+                case KeyCodes.KEY_ESCAPE:
+                    hide();
+                    break;
+            }
+        }
+    }
+
+    /**
+     */
+    void sendFeedback() {
+        final String feedbackURL = otherProperties.get("feedbackUrl");
+        PostRequest sendFeedback = new PostRequest("", "", feedbackURL, "feedback_msg=" + msg.getText() + "&feedback_data=" + appData + "&auth=" + app.getUserToken()) {
+
+            @Override
+            protected void onUnauthorized(Response response) {
+                app.sessionExpired();
+            }
+
+            @Override
+            public void onSuccess(Resource result) {
+                app.displayInformation("Feedback sent");
+            }
+
+            @Override
+            public void onError(Throwable t) {
+                app.displayError("Could not send feedback");
+            }
+        };
+        sendFeedback.setHeader("X-Auth-Token", app.getUserToken());
+        Scheduler.get().scheduleDeferred(sendFeedback);
+    }
 }