Revision c8f8690d src/gr/grnet/pithos/web/client/AddUserDialog.java
b/src/gr/grnet/pithos/web/client/AddUserDialog.java | ||
---|---|---|
45 | 45 |
import com.google.gwt.http.client.URL; |
46 | 46 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
47 | 47 |
import com.google.gwt.user.client.ui.*; |
48 |
import gr.grnet.pithos.web.client.catalog.UpdateUserCatalogs; |
|
49 |
import gr.grnet.pithos.web.client.catalog.UserCatalogs; |
|
48 | 50 |
import gr.grnet.pithos.web.client.grouptree.Group; |
49 | 51 |
import gr.grnet.pithos.web.client.rest.PostRequest; |
50 | 52 |
import gr.grnet.pithos.web.client.rest.RestException; |
51 | 53 |
|
54 |
import java.util.Arrays; |
|
55 |
|
|
52 | 56 |
/** |
53 | 57 |
* The 'Folder properties' dialog box implementation. |
54 | 58 |
*/ |
... | ... | |
60 | 64 |
/** |
61 | 65 |
* The widget that holds the folderName of the folder. |
62 | 66 |
*/ |
63 |
TextBox userName = new TextBox(); |
|
67 |
TextBox userNameInput = new TextBox();
|
|
64 | 68 |
|
65 | 69 |
final VerticalPanel inner; |
66 | 70 |
|
... | ... | |
101 | 105 |
FlexTable generalTable = new FlexTable(); |
102 | 106 |
generalTable.setText(0, 0, "Username"); |
103 | 107 |
|
104 |
generalTable.setWidget(0, 1, userName); |
|
108 |
generalTable.setWidget(0, 1, userNameInput);
|
|
105 | 109 |
|
106 | 110 |
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
107 | 111 |
generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
... | ... | |
131 | 135 |
@Override |
132 | 136 |
public void center() { |
133 | 137 |
super.center(); |
134 |
userName.setFocus(true); |
|
138 |
userNameInput.setFocus(true);
|
|
135 | 139 |
} |
136 | 140 |
|
137 | 141 |
@Override |
... | ... | |
165 | 169 |
hide(); |
166 | 170 |
} |
167 | 171 |
|
168 |
/** |
|
169 |
* Generate an RPC request to create a new folder. |
|
170 |
*/ |
|
171 |
void addUser() { |
|
172 |
String name = userName.getText().trim(); |
|
173 |
if(name.length() == 0) { |
|
174 |
return; |
|
175 |
} |
|
176 |
if(!Const.EMAIL_REGEX.test(name)) { |
|
177 |
app.displayWarning("Username must be a valid email address"); |
|
178 |
return; |
|
179 |
} |
|
180 |
|
|
181 |
group.addMember(name); |
|
172 |
private void doAddUser(final String userID) { |
|
173 |
group.addMember(userID); |
|
182 | 174 |
String path = "?update="; |
183 | 175 |
PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUserID(), path) { |
184 | 176 |
|
... | ... | |
212 | 204 |
updateGroup.setHeader(Const.X_ACCOUNT_GROUP_ + URL.encodePathSegment(group.getName()), groupMembers); |
213 | 205 |
Scheduler.get().scheduleDeferred(updateGroup); |
214 | 206 |
} |
207 |
/** |
|
208 |
* Generate an RPC request to create a new folder. |
|
209 |
*/ |
|
210 |
void addUser() { |
|
211 |
final String userDisplayName = userNameInput.getText().trim(); |
|
212 |
if(userDisplayName.length() == 0) { |
|
213 |
return; |
|
214 |
} |
|
215 |
if(!Const.EMAIL_REGEX.test(userDisplayName)) { |
|
216 |
app.displayWarning("Username must be a valid email address"); |
|
217 |
return; |
|
218 |
} |
|
219 |
|
|
220 |
if(app.hasIDForUserDisplayName(userDisplayName)) { |
|
221 |
final String userID = app.getIDForUserDisplayName(userDisplayName); |
|
222 |
doAddUser(userID); |
|
223 |
} |
|
224 |
else { |
|
225 |
new UpdateUserCatalogs(app, null, Arrays.asList(userDisplayName)) { |
|
226 |
@Override |
|
227 |
public void onSuccess(UserCatalogs requestedUserCatalogs, UserCatalogs updatedUserCatalogs) { |
|
228 |
final String userID = app.getIDForUserDisplayName(userDisplayName); |
|
229 |
doAddUser(userID); |
|
230 |
} |
|
231 |
}.scheduleDeferred(); |
|
232 |
} |
|
233 |
|
|
234 |
|
|
235 |
} |
|
215 | 236 |
} |
Also available in: Unified diff