root / src / gr / grnet / pithos / web / client / InvitationsDialog.java @ 0f797b1b
History | View | Annotate | Download (5.5 kB)
1 | 29c80d38 | Christos Stathis | /*
|
---|---|---|---|
2 | 29c80d38 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 29c80d38 | Christos Stathis | *
|
4 | 29c80d38 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 29c80d38 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 29c80d38 | Christos Stathis | * conditions are met:
|
7 | 29c80d38 | Christos Stathis | *
|
8 | 29c80d38 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 29c80d38 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 29c80d38 | Christos Stathis | * disclaimer.
|
11 | 29c80d38 | Christos Stathis | *
|
12 | 29c80d38 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 29c80d38 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 29c80d38 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 29c80d38 | Christos Stathis | * provided with the distribution.
|
16 | 29c80d38 | Christos Stathis | *
|
17 | 29c80d38 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 29c80d38 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 29c80d38 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 29c80d38 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 29c80d38 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 29c80d38 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 29c80d38 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 29c80d38 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 29c80d38 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 29c80d38 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 29c80d38 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 29c80d38 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 29c80d38 | Christos Stathis | *
|
30 | 29c80d38 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 29c80d38 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 29c80d38 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 29c80d38 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 29c80d38 | Christos Stathis | */
|
35 | 29c80d38 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | 29c80d38 | Christos Stathis | |
37 | fd1da2eb | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
38 | fd1da2eb | Christos Stathis | import gr.grnet.pithos.web.client.rest.PostRequest; |
39 | fd1da2eb | Christos Stathis | |
40 | fd1da2eb | Christos Stathis | import com.google.gwt.core.client.GWT; |
41 | fd1da2eb | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
42 | 29c80d38 | Christos Stathis | import com.google.gwt.dom.client.NativeEvent; |
43 | 29c80d38 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
44 | 29c80d38 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
45 | 29c80d38 | Christos Stathis | import com.google.gwt.event.dom.client.KeyCodes; |
46 | fd1da2eb | Christos Stathis | import com.google.gwt.http.client.Response; |
47 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.Event.NativePreviewEvent; |
48 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.Anchor; |
49 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
50 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.DialogBox; |
51 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
52 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
53 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
54 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
55 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.TextBox; |
56 | 29c80d38 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
57 | 29c80d38 | Christos Stathis | |
58 | 29c80d38 | Christos Stathis | |
59 | 29c80d38 | Christos Stathis | /**
|
60 | 29c80d38 | Christos Stathis | * A dialog box that displays info about invitations
|
61 | 29c80d38 | Christos Stathis | */
|
62 | 29c80d38 | Christos Stathis | public class InvitationsDialog extends DialogBox { |
63 | 29c80d38 | Christos Stathis | |
64 | 29c80d38 | Christos Stathis | private final String WIDTH_FIELD = "35em"; |
65 | 29c80d38 | Christos Stathis | private final String WIDTH_TEXT = "42em"; |
66 | 29c80d38 | Christos Stathis | |
67 | 29c80d38 | Christos Stathis | /**
|
68 | 29c80d38 | Christos Stathis | * The widget constructor.
|
69 | 29c80d38 | Christos Stathis | */
|
70 | fd1da2eb | Christos Stathis | public InvitationsDialog(final Pithos app, Invitations inv) { |
71 | 29c80d38 | Christos Stathis | Anchor close = new Anchor();
|
72 | 29c80d38 | Christos Stathis | close.addStyleName("close");
|
73 | 29c80d38 | Christos Stathis | close.addClickHandler(new ClickHandler() {
|
74 | 29c80d38 | Christos Stathis | |
75 | 29c80d38 | Christos Stathis | @Override
|
76 | 29c80d38 | Christos Stathis | public void onClick(ClickEvent event) { |
77 | 29c80d38 | Christos Stathis | hide(); |
78 | 29c80d38 | Christos Stathis | } |
79 | 29c80d38 | Christos Stathis | }); |
80 | 29c80d38 | Christos Stathis | // Set the dialog's caption.
|
81 | fd1da2eb | Christos Stathis | setText("Invite people (" + inv.getInvitationsLeft() + " invitations left)"); |
82 | 29c80d38 | Christos Stathis | setAnimationEnabled(true);
|
83 | 29c80d38 | Christos Stathis | setGlassEnabled(true);
|
84 | 29c80d38 | Christos Stathis | setStyleName("pithos-DialogBox");
|
85 | 29c80d38 | Christos Stathis | VerticalPanel outer = new VerticalPanel();
|
86 | 29c80d38 | Christos Stathis | outer.add(close); |
87 | 29c80d38 | Christos Stathis | |
88 | 29c80d38 | Christos Stathis | VerticalPanel inner = new VerticalPanel();
|
89 | 29c80d38 | Christos Stathis | inner.addStyleName("inner");
|
90 | 29c80d38 | Christos Stathis | // Create the text and set a style name so we can style it with CSS.
|
91 | fd1da2eb | Christos Stathis | HTML text = new HTML("You have " + inv.getInvitationsLeft() + " invitations left in your account."); |
92 | 29c80d38 | Christos Stathis | text.setStyleName("pithos-credentialsText");
|
93 | 29c80d38 | Christos Stathis | text.setWidth(WIDTH_TEXT); |
94 | 29c80d38 | Christos Stathis | inner.add(text); |
95 | 29c80d38 | Christos Stathis | FlexTable table = new FlexTable();
|
96 | 29c80d38 | Christos Stathis | table.setText(0, 0, "Name"); |
97 | 29c80d38 | Christos Stathis | table.setText(1, 0, "E-mail"); |
98 | fd1da2eb | Christos Stathis | final TextBox name = new TextBox(); |
99 | 29c80d38 | Christos Stathis | name.setWidth(WIDTH_FIELD); |
100 | 29c80d38 | Christos Stathis | table.setWidget(0, 1, name); |
101 | 29c80d38 | Christos Stathis | |
102 | fd1da2eb | Christos Stathis | final TextBox emailBox = new TextBox(); |
103 | 29c80d38 | Christos Stathis | emailBox.setWidth(WIDTH_FIELD); |
104 | 29c80d38 | Christos Stathis | table.setWidget(1, 1, emailBox); |
105 | 29c80d38 | Christos Stathis | |
106 | 29c80d38 | Christos Stathis | table.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
107 | 29c80d38 | Christos Stathis | table.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
108 | 29c80d38 | Christos Stathis | table.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); |
109 | 29c80d38 | Christos Stathis | table.getFlexCellFormatter().setStyleName(1, 1, "props-values"); |
110 | 29c80d38 | Christos Stathis | inner.add(table); |
111 | 29c80d38 | Christos Stathis | |
112 | 29c80d38 | Christos Stathis | Button confirm = new Button("Send", new ClickHandler() { |
113 | 29c80d38 | Christos Stathis | @Override
|
114 | 29c80d38 | Christos Stathis | public void onClick(ClickEvent event) { |
115 | 5300a16e | Christos Stathis | PostRequest sendInvitation = new PostRequest("/im/", "", "invite", "uniq=" + emailBox.getText().trim() + "&realname=" + name.getText().trim()) { |
116 | fd1da2eb | Christos Stathis | |
117 | fd1da2eb | Christos Stathis | @Override
|
118 | fd1da2eb | Christos Stathis | protected void onUnauthorized(Response response) { |
119 | fd1da2eb | Christos Stathis | app.sessionExpired(); |
120 | fd1da2eb | Christos Stathis | } |
121 | fd1da2eb | Christos Stathis | |
122 | fd1da2eb | Christos Stathis | @Override
|
123 | fd1da2eb | Christos Stathis | public void onSuccess(Resource result) { |
124 | 5300a16e | Christos Stathis | app.displayInformation("Invitation sent");
|
125 | fd1da2eb | Christos Stathis | } |
126 | fd1da2eb | Christos Stathis | |
127 | fd1da2eb | Christos Stathis | @Override
|
128 | fd1da2eb | Christos Stathis | public void onError(Throwable t) { |
129 | fd1da2eb | Christos Stathis | GWT.log("", t);
|
130 | fd1da2eb | Christos Stathis | } |
131 | fd1da2eb | Christos Stathis | }; |
132 | fd1da2eb | Christos Stathis | sendInvitation.setHeader("X-Auth-Token", app.getToken());
|
133 | fd1da2eb | Christos Stathis | Scheduler.get().scheduleDeferred(sendInvitation); |
134 | 29c80d38 | Christos Stathis | hide(); |
135 | 29c80d38 | Christos Stathis | } |
136 | 29c80d38 | Christos Stathis | }); |
137 | 29c80d38 | Christos Stathis | confirm.addStyleName("button");
|
138 | 29c80d38 | Christos Stathis | inner.add(confirm); |
139 | 29c80d38 | Christos Stathis | outer.add(inner); |
140 | 29c80d38 | Christos Stathis | outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
141 | 29c80d38 | Christos Stathis | setWidget(outer); |
142 | 29c80d38 | Christos Stathis | } |
143 | 29c80d38 | Christos Stathis | |
144 | 29c80d38 | Christos Stathis | @Override
|
145 | 29c80d38 | Christos Stathis | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
146 | 29c80d38 | Christos Stathis | super.onPreviewNativeEvent(preview);
|
147 | 29c80d38 | Christos Stathis | NativeEvent evt = preview.getNativeEvent(); |
148 | 29c80d38 | Christos Stathis | if (evt.getType().equals("keydown")) |
149 | 29c80d38 | Christos Stathis | // Use the popup's key preview hooks to close the dialog when
|
150 | 29c80d38 | Christos Stathis | // either enter or escape is pressed.
|
151 | 29c80d38 | Christos Stathis | switch (evt.getKeyCode()) {
|
152 | 29c80d38 | Christos Stathis | case KeyCodes.KEY_ENTER:
|
153 | 29c80d38 | Christos Stathis | case KeyCodes.KEY_ESCAPE:
|
154 | 29c80d38 | Christos Stathis | hide(); |
155 | 29c80d38 | Christos Stathis | break;
|
156 | 29c80d38 | Christos Stathis | } |
157 | 29c80d38 | Christos Stathis | } |
158 | 29c80d38 | Christos Stathis | } |