/*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
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.regexp.shared.RegExp;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
private ListBox groupBox = new ListBox();
- private CheckBox read = new CheckBox();
+ private RadioButton read = new RadioButton("permissions");
- private CheckBox write = new CheckBox();
+ private RadioButton write = new RadioButton("permissions");
private PermissionsList permList;
userAdd = _userAdd;
permList = _permList;
- Anchor close = new Anchor();
+ Anchor close = new Anchor("close");
close.addStyleName("close");
close.addClickHandler(new ClickHandler() {
final FlexTable permTable = new FlexTable();
permTable.setText(0, 0, "Users/Groups");
- permTable.setText(0, 1, "Read");
- permTable.setText(0, 2, "Write");
+ permTable.setText(0, 1, "Read Only");
+ permTable.setText(0, 2, "Read/Write");
permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
groupBox.addItem(group.getName(), group.getName());
permTable.setWidget(1, 0, groupBox);
}
-
+
+ read.setValue(true);
permTable.setWidget(1, 1, read);
permTable.setWidget(1, 2, write);
protected void addPermission() {
String selected = null;
if (userAdd) {
- selected = userBox.getText();
- } else {
+ selected = userBox.getText().trim();
+ RegExp emailValidator = RegExp.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+[.][A-Z]{2,4}$", "i");
+ if (!emailValidator.test(selected)) {
+ app.displayWarning("Username must be a valid email address");
+ return;
+ }
+ } else if (groupBox.getSelectedIndex() > -1) {
String groupName = groupBox.getValue(groupBox.getSelectedIndex());
- selected = app.getUsername() + ":" + groupName;
+ selected = app.getUserID() + ":" + groupName;
}
if (permList.getPermissions().get(selected) != null) {
return;
}
+ if (selected == null || selected.length() == 0 || selected.equals(app.getUserID() + ":")) {
+ app.displayWarning("You have to select a username or group");
+ return;
+ }
+
boolean readValue = read.getValue();
boolean writeValue = write.getValue();