use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.
the class TestJSONParserTabItem method draw.
public Widget draw() {
Button sendMessageButton = new Button("Parse response");
final FlexTable ft = new FlexTable();
ft.setCellSpacing(15);
int row = 0;
ft.setText(row, 0, "Server response:");
ft.setWidget(row, 1, returnedValue);
row++;
ft.setText(row, 0, "Callback name:");
ft.setHTML(row, 1, "callbackPost");
row++;
ft.setWidget(row, 0, sendMessageButton);
row++;
sendMessageButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String resp = returnedValue.getText();
// trims the whitespace
resp = resp.trim();
// short comparing
if (("callbackPost(null);").equalsIgnoreCase(resp)) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
RegExp re = RegExp.compile("^" + "callbackPost" + "\\((.*)\\)|\\);$");
MatchResult result = re.exec(resp);
if (result != null) {
resp = result.getGroup(1);
}
UiElements.generateInfo("Unwrapped value", "Non-null unwrapped value is: " + resp);
// if response = null - return null
if (resp.equals("null")) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// normal object
JavaScriptObject jso = JsonUtils.parseJson(resp);
BasicOverlayType basic = jso.cast();
UiElements.generateInfo("Parser result", "Parsed result is: " + basic.getString());
}
});
this.contentWidget.setWidget(ft);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.
the class GetFormItems method prepareErrorSettings.
private void prepareErrorSettings(PerunError error) {
FlexTable ft = new FlexTable();
ft.setWidth("100%");
ft.setCellPadding(8);
FlexCellFormatter fcf = ft.getFlexCellFormatter();
ft.addStyleName("borderTable");
ft.setHTML(0, 0, "<strong>Short name</strong>");
ft.setHTML(0, 1, "<strong>Type</strong>");
ft.setHTML(0, 2, "<strong>Preview</strong>");
ft.setHTML(0, 3, "<strong>Edit</strong>");
fcf.setStyleName(0, 0, "header");
fcf.setStyleName(0, 1, "header");
fcf.setStyleName(0, 2, "header");
fcf.setStyleName(0, 3, "header");
if (error != null && error.getName().equalsIgnoreCase("FormNotExistsException")) {
// no form, add create button
final CustomButton create = new CustomButton("Create empty form", ButtonTranslation.INSTANCE.createEmptyApplicationForm(), SmallIcons.INSTANCE.addIcon());
create.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// disable button event with refresh page on finished
CreateApplicationForm request = new CreateApplicationForm(entity, id, JsonCallbackEvents.disableButtonEvents(create, new JsonCallbackEvents() {
private TabItem item = null;
@Override
public void onFinished(JavaScriptObject jso) {
if (item != null) {
item.draw();
}
}
@Override
public void onLoadingStart() {
item = session.getTabManager().getActiveTab();
}
}));
request.createApplicationForm();
}
});
if (PerunEntity.VIRTUAL_ORGANIZATION.equals(entity) && !session.isVoAdmin(id)) {
create.setEnabled(false);
} else if (PerunEntity.GROUP.equals(entity) && !session.isGroupAdmin(id) && !session.isVoAdmin(group.getVoId())) {
create.setEnabled(false);
}
loaderImage.setEmptyResultMessage("Application form doesn't exists.");
loaderImage.loadingFinished();
ft.setWidget(1, 0, loaderImage);
ft.getFlexCellFormatter().addStyleName(1, 0, "noBorder");
ft.getFlexCellFormatter().setColSpan(1, 0, 4);
ft.setWidget(2, 0, create);
ft.getFlexCellFormatter().addStyleName(2, 0, "noBorder");
ft.getFlexCellFormatter().setColSpan(2, 0, 4);
ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
ft.getFlexCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_MIDDLE);
} else {
// standard error
ft.setWidget(1, 0, loaderImage);
fcf.setColSpan(1, 0, 4);
}
contents.setWidget(ft);
}
use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.
the class HandleApplication method approveApplication.
/**
* Approve application
*
* @param app
*/
public void approveApplication(final Application app) {
this.appId = app.getId();
// test arguments
if (!this.testApplication()) {
return;
}
// new events
final JsonCallbackEvents newEvents = new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Approving application failed.");
events.onError(error);
}
@Override
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Application approved.");
events.onFinished(jso);
}
@Override
public void onLoadingStart() {
events.onLoadingStart();
}
};
final JSONObject appIdObj = new JSONObject();
appIdObj.put("appId", new JSONNumber(appId));
final JSONObject idObj = new JSONObject();
idObj.put("id", new JSONNumber(appId));
// check if can be approved
JsonPostClient jspc = new JsonPostClient(new JsonCallbackEvents() {
@Override
public void onError(final PerunError error) {
session.getUiElements().setLogErrorText("Checking approval failed.");
events.onError(error);
if (error == null) {
PerunError e = (PerunError) JsonUtils.parseJson("{\"errorId\":\"0\",\"name\":\"Cross-site request\",\"type\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteType() + "\",\"message\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteText() + "\"}").cast();
JsonErrorHandler.alertBox(e);
} else if (!error.getName().equals("CantBeApprovedException")) {
JsonErrorHandler.alertBox(error);
} else {
FlexTable layout = new FlexTable();
layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.errorIcon())));
if ("NOT_ACADEMIC".equals(error.getReason())) {
layout.setHTML(0, 1, "<p>User is not active academia member and application shouldn't be approved.<p><b>LoA:</b> " + app.getExtSourceLoa() + "</br><b>IdP category:</b> " + (!(error.getCategory().equals("")) ? error.getCategory() : "N/A") + "</br><b>Affiliation:</b> " + (!(error.getAffiliation().equals("")) ? error.getAffiliation().replace(";", ", ") : "N/A") + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
} else {
layout.setHTML(0, 1, "<p>" + error.getErrorInfo() + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
}
layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
if (error.isSoft()) {
Confirm c = new Confirm("Application shouldn't be approved", layout, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// ok approve sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
}
}, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
events.onFinished(null);
}
}, true);
c.setOkButtonText("Approve anyway");
c.setNonScrollable(true);
c.show();
} else {
Confirm c = new Confirm("Application can't be approved", layout, true);
c.setNonScrollable(true);
c.show();
}
}
}
@Override
public void onFinished(JavaScriptObject jso) {
if (app.getUser() != null) {
// ok approve sending data
JsonPostClient jspc2 = new JsonPostClient(newEvents);
jspc2.sendData(JSON_URL_APPROVE, prepareJSONObject());
} else {
JsonPostClient checkJspc = new JsonPostClient(new JsonCallbackEvents() {
@Override
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Approving application failed.");
events.onError(error);
}
@Override
public void onFinished(JavaScriptObject jso) {
ArrayList<Identity> users = JsonUtils.jsoAsList(jso);
if (users != null && !users.isEmpty()) {
FlexTable ft = new FlexTable();
ft.setWidth("600px");
ft.setHTML(0, 0, "<p><strong>Following similar user(s) were found in system:");
ft.getFlexCellFormatter().setColSpan(0, 0, 3);
ft.setHTML(1, 0, "<strong>" + ApplicationMessages.INSTANCE.name() + "</strong>");
ft.setHTML(1, 1, "<strong>" + ApplicationMessages.INSTANCE.email() + "</strong>");
ft.setHTML(1, 2, "<strong>" + ApplicationMessages.INSTANCE.organization() + "</strong>");
int i = 2;
for (Identity user : users) {
ft.setHTML(i, 0, user.getName());
if (user.getEmail() != null && !user.getEmail().isEmpty()) {
ft.setHTML(i, 1, user.getEmail());
} else {
ft.setHTML(i, 1, "N/A");
}
if (user.getOrganization() != null && !user.getOrganization().isEmpty()) {
ft.setHTML(i, 2, user.getOrganization());
} else {
ft.setHTML(i, 2, "N/A");
}
i++;
}
String type = "";
if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
type = "cert";
} else if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceIdp")) {
type = "fed";
}
ft.setHTML(i, 0, "<p>Please contact new applicant with question, if he/she isn't already member of any other VO." + "<ul><li>If YES, ask him/her to join identities at <a href=\"" + Utils.getIdentityConsolidatorLink(type, false) + "\" target=\"_blank\">identity consolidator</a> before approving this application." + "</li><li>If NO, you can approve this application anyway. " + "</li><li>If UNSURE, contact <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">support</a> to help you.</li></ul>");
ft.getFlexCellFormatter().setColSpan(i, 0, 3);
i++;
ft.setHTML(i, 0, "<strong>Do you wish to approve this application anyway ?</strong>");
ft.getFlexCellFormatter().setColSpan(i, 0, 3);
Confirm c = new Confirm("Similar users found!", ft, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// ok approve sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
}
}, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
events.onFinished(null);
}
}, true);
c.setOkButtonText("Approve");
c.setNonScrollable(true);
c.show();
} else {
// ok approve sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
}
}
@Override
public void onLoadingStart() {
events.onLoadingStart();
}
});
checkJspc.sendData("registrarManager/checkForSimilarUsers", appIdObj);
}
}
@Override
public void onLoadingStart() {
events.onLoadingStart();
}
});
// we have own error handling
jspc.setHidden(true);
jspc.sendData(JSON_URL_CHECK, idObj);
}
use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.
the class AddFacilityManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// pass empty items to menu to ensure drawing of rest
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(new HTML(""));
tabMenu.addWidget(2, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(3, box);
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
final TabItem tab = this;
tabMenu.addWidget(1, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of com.google.gwt.event.dom.client.ClickEvent in project perun by CESNET.
the class AddFacilityManagerTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager");
final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
ArrayList<User> list = JsonUtils.jsoAsList(jso);
if (list != null && list.size() == 1) {
users.getSelectionModel().setSelected(list.get(0), true);
}
}
}));
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<User> table;
if (session.isPerunAdmin()) {
table = users.getTable(new FieldUpdater<User, String>() {
public void update(int i, User user, String s) {
session.getTabManager().addTab(new UserDetailTabItem(user));
}
});
} else {
table = users.getTable();
}
final TabItem tab = this;
// already added
rebuildAlreadyAddedWidget();
// search textbox
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
startSearching(text);
searchString = text;
}
}, searchButton);
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToFacility());
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<User> list = users.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// proceed
for (int i = 0; i < list.size(); i++) {
final int n = i;
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
alreadyAddedList.add(list.get(n));
rebuildAlreadyAddedWidget();
// unselect added person
users.getSelectionModel().setSelected(list.get(n), false);
// clear search
searchBox.getTextBox().setText("");
}
}));
request.addFacilityAdmin(facility, list.get(i));
}
}
}
});
tabMenu.addWidget(addButton);
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
startSearching(searchString);
}
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(alreadyAdded);
firstTabPanel.add(sp);
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(users, table, addButton);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations