package gr.grnet.pithos.web.client;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import com.google.gwt.http.client.Response;
+import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
private int invitationsLeft = 0;
+ private List<Invitation> sentInvitations = new ArrayList<Invitation>();
+
@Override
public Date getLastModified() {
return null;
return invitationsLeft;
}
- public void setInvitationsLeft(int invitationsLeft) {
- this.invitationsLeft = invitationsLeft;
- }
-
public static Invitations createFromResponse(Response response) {
Invitations result = new Invitations();
result.populate(response);
private void populate(Response response) {
JSONValue json = JSONParser.parseStrict(response.getText());
JSONObject o = json.isObject();
- if (o != null)
+ if (o != null) {
invitationsLeft = unmarshallInt(o, "invitations");
+ JSONArray sent = o.get("sent").isArray();
+ if (sent != null) {
+ for (int i=0; i<sent.size(); i++) {
+ JSONObject ob = sent.get(i).isObject();
+ if (ob != null) {
+ boolean accepted = unmarshallBoolean(ob, "is_accepted");
+ String email = unmarshallString(ob, "email");
+ String realname = unmarshallString(ob, "realname");
+ Invitation inv = new Invitation(accepted, realname, email);
+ sentInvitations.add(inv);
+ }
+ }
+ }
+ }
+ }
+
+ public List<Invitation> getSentInvitations() {
+ return sentInvitations;
}
}
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
text.setStyleName("pithos-credentialsText");
text.setWidth(WIDTH_TEXT);
inner.add(text);
+
FlexTable table = new FlexTable();
if (inv.getInvitationsLeft() > 0) {
table.setText(0, 0, "Name");
Button confirm = new Button("Send", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- sendInvitation();
+ sendInvitation(emailBox.getText().trim(), name.getText().trim());
}
});
confirm.addStyleName("button");
confirm.setVisible(inv.getInvitationsLeft() > 0);
inner.add(confirm);
+
+ HTML sentLabel = new HTML("Sent invitations");
+ sentLabel.addStyleName("pithos-sentInvitationsTitle");
+ inner.add(sentLabel);
+
+ FlexTable sentInvitationsTable = new FlexTable();
+ Image accepted = new Image("images/invitation_accepted.png");
+ accepted.setAltText("Invitation accepted");
+ Image resend = new Image("images/resend.png");
+ resend.setAltText("Resend invitation");
+
+ HorizontalPanel legend = new HorizontalPanel();
+ legend.add(new HTML("("));
+ legend.add(accepted);
+ legend.add(new HTML(" = Invitation has been accepted)"));
+ legend.add(new HTML("("));
+ legend.add(resend);
+ legend.add(new HTML(" = Send invitation again)"));
+ inner.add(legend);
+
+ int row = 0;
+ for (final Invitation i : inv.getSentInvitations()) {
+ sentInvitationsTable.setText(row, 0, i.getRealname());
+ sentInvitationsTable.setText(row, 1, i.getEmail());
+ if (i.isAccepted())
+ sentInvitationsTable.setWidget(row, 2, new Image("images/invitation_accepted.png"));
+ else {
+ Image img = new Image("images/resend.png");
+ img.addStyleName("pithos-resendInvitation");
+ img.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ sendInvitation(i.getEmail(), i.getRealname());
+ }
+ });
+ sentInvitationsTable.setWidget(row, 2, img);
+ }
+ row++;
+ }
+ inner.add(sentInvitationsTable);
+
outer.add(inner);
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
setWidget(outer);
// either enter or escape is pressed.
switch (evt.getKeyCode()) {
case KeyCodes.KEY_ENTER:
- sendInvitation();
+ sendInvitation(emailBox.getText().trim(), name.getText().trim());
break;
case KeyCodes.KEY_ESCAPE:
hide();
}
}
- void sendInvitation() {
- PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + emailBox.getText().trim() + "&realname=" + name.getText().trim()) {
+ void sendInvitation(String email, String realname) {
+ PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + email + "&realname=" + realname) {
@Override
protected void onUnauthorized(Response response) {