*/
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;
/**
* The widget constructor.
*/
- public InvitationsDialog() {
+ public InvitationsDialog(final Pithos app, Invitations inv) {
Anchor close = new Anchor();
close.addStyleName("close");
close.addClickHandler(new ClickHandler() {
}
});
// Set the dialog's caption.
- setText("Invite people (# invitations left)");
+ setText("Invite people (" + inv.getInvitationsLeft() + " invitations left)");
setAnimationEnabled(true);
setGlassEnabled(true);
setStyleName("pithos-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("You have # invitations left in your account.");
+ HTML text = new HTML("You have " + inv.getInvitationsLeft() + " invitations left in your account.");
text.setStyleName("pithos-credentialsText");
text.setWidth(WIDTH_TEXT);
inner.add(text);
FlexTable table = new FlexTable();
- table.setText(0, 0, "Name");
- table.setText(1, 0, "E-mail");
- TextBox name = new TextBox();
+ if (inv.getInvitationsLeft() > 0) {
+ table.setText(0, 0, "Name");
+ table.setText(1, 0, "E-mail");
+ }
+ final TextBox name = new TextBox();
name.setWidth(WIDTH_FIELD);
+ name.setVisible(inv.getInvitationsLeft() > 0);
table.setWidget(0, 1, name);
- TextBox emailBox = new TextBox();
+ final TextBox emailBox = new TextBox();
emailBox.setWidth(WIDTH_FIELD);
+ emailBox.setVisible(inv.getInvitationsLeft() > 0);
table.setWidget(1, 1, emailBox);
table.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
Button confirm = new Button("Send", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
+ PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + emailBox.getText().trim() + "&realname=" + name.getText().trim()) {
+
+ @Override
+ protected void onUnauthorized(Response response) {
+ app.sessionExpired();
+ }
+
+ @Override
+ public void onSuccess(Resource result) {
+ app.displayInformation("Invitation sent");
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ GWT.log("", t);
+ }
+ };
+ sendInvitation.setHeader("X-Auth-Token", app.getToken());
+ Scheduler.get().scheduleDeferred(sendInvitation);
hide();
}
});
confirm.addStyleName("button");
+ confirm.setVisible(inv.getInvitationsLeft() > 0);
inner.add(confirm);
outer.add(inner);
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);