Revision 5300a16e

b/src/gr/grnet/pithos/web/client/Invitations.java
2 2

  
3 3
import java.util.Date;
4 4

  
5
import com.google.gwt.http.client.Response;
6
import com.google.gwt.json.client.JSONObject;
7
import com.google.gwt.json.client.JSONParser;
8
import com.google.gwt.json.client.JSONValue;
9

  
5 10
import gr.grnet.pithos.web.client.foldertree.Resource;
6 11

  
7 12
public class Invitations extends Resource {
8 13

  
9
	private int invitationsLeft;
14
	private int invitationsLeft = 0;
10 15
	
11 16
	@Override
12 17
	public Date getLastModified() {
......
21 26
		this.invitationsLeft = invitationsLeft;
22 27
	}
23 28

  
29
	public static Invitations createFromResponse(Response response) {
30
		Invitations result = new Invitations();
31
		result.populate(response);
32
		return result;
33
	}
34

  
35
	private void populate(Response response) {
36
        JSONValue json = JSONParser.parseStrict(response.getText());
37
        JSONObject o = json.isObject();
38
        if (o != null)
39
        	invitationsLeft = unmarshallInt(o, "invitations");
40
	}
41

  
24 42
}
b/src/gr/grnet/pithos/web/client/InvitationsDialog.java
112 112
		Button confirm = new Button("Send", new ClickHandler() {
113 113
			@Override
114 114
			public void onClick(ClickEvent event) {
115
				PostRequest sendInvitation = new PostRequest("/im/", "", "invitations?uniq=" + emailBox.getText().trim() + "&realname=" + name.getText().trim()) {
115
				PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + emailBox.getText().trim() + "&realname=" + name.getText().trim()) {
116 116
					
117 117
					@Override
118 118
					protected void onUnauthorized(Response response) {
......
121 121
					
122 122
					@Override
123 123
					public void onSuccess(Resource result) {
124
						app.displayInformation("Invitation sent");
124 125
					}
125 126
					
126 127
					@Override
b/src/gr/grnet/pithos/web/client/TopPanel.java
111 111
			
112 112
			@Override
113 113
			public void execute() {
114
				GetRequest<Invitations> getInvitations = new GetRequest<Invitations> (Invitations.class, "/im/", "", "invitations") {
114
				GetRequest<Invitations> getInvitations = new GetRequest<Invitations> (Invitations.class, "/im/", "", "invite?format=json") {
115 115

  
116 116
					@Override
117 117
					public void onSuccess(Invitations _result) {
b/src/gr/grnet/pithos/web/client/foldertree/Resource.java
43 43
import com.google.gwt.json.client.JSONObject;
44 44
import com.google.gwt.json.client.JSONString;
45 45

  
46
import gr.grnet.pithos.web.client.Invitations;
46 47
import gr.grnet.pithos.web.client.SharingUsers;
47 48

  
48 49
import java.util.Date;
......
116 117
        else if (aClass.equals(FileVersions.class)) {
117 118
        	result1 = (T) FileVersions.createFromResponse(response);
118 119
        }
120
        else if (aClass.equals(Invitations.class)) {
121
        	result1 = (T) Invitations.createFromResponse(response);
122
        }
119 123
        return result1;
120 124
    }
121 125
    
b/src/gr/grnet/pithos/web/client/rest/PostRequest.java
53 53
    protected String owner;
54 54

  
55 55
    private String path;
56
    
57
    String data = "";
56 58

  
57 59
    private Map<String, String> headers = new HashMap<String, String>();
58 60

  
......
66 68
        this.path = path;
67 69
    }
68 70

  
71
    public PostRequest(String api, String owner, String path, String data) {
72
        this.api = api;
73
        this.owner = owner;
74
        this.path = path;
75
        this.data = data;
76
    }
77

  
69 78
    @Override
70 79
    public void execute() {
71 80
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, api + owner + path);
......
73 82
            builder.setHeader(header, headers.get(header));
74 83
        }
75 84
        try {
76
            builder.sendRequest("", new RestRequestCallback<Resource>(api + owner + path, Response.SC_ACCEPTED) {
85
            builder.sendRequest(data, new RestRequestCallback<Resource>(api + owner + path, Response.SC_ACCEPTED) {
77 86
                @Override
78 87
                public void onSuccess(Resource object) {
79 88
                    PostRequest.this.onSuccess(object);

Also available in: Unified diff