use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class DeleteCategory method deleteCategory.
/**
* Attempts to delete a Category, it first tests the values and then submits them.
*
* @param categoryId ID of category to be deleted
*/
public void deleteCategory(final int categoryId) {
this.categoryId = categoryId;
// test arguments
if (!this.testDeleting()) {
return;
}
// json object
JSONObject jsonQuery = prepareJSONObject();
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Deleting category " + categoryId + " failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Category " + categoryId + " deleted.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class AddExtSource method addGroupExtSource.
/**
* Attempts to add external source to Group in DB - make RPC call
*
* @param groupId ID of Group, where should be ext source added
* @param extSourceId ID of external source to be added
*/
public void addGroupExtSource(final int groupId, final int extSourceId) {
this.extSourceId = extSourceId;
// create whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("source", new JSONNumber(extSourceId));
jsonQuery.put("group", new JSONNumber(groupId));
// local events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding external source: " + extSourceId + " to group: " + groupId + " failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("External source: " + extSourceId + " successfully added to group: " + groupId);
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// create request
JsonPostClient request = new JsonPostClient(newEvents);
request.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class PerunWebSession method setActiveVoId.
/**
* Sets currently active VO (refresh links in menu)
* when only ID is provided.
*
* @param voId ID of VO which user is editing now
*/
public void setActiveVoId(final int voId) {
new GetEntityById(PerunEntity.VIRTUAL_ORGANIZATION, voId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
VirtualOrganization vo = jso.cast();
setActiveVo(vo);
}
}).retrieveData();
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class WebGui method showCurrentGDPRApproval.
private void showCurrentGDPRApproval(Map<String, Integer> ids, Attribute a, Map<String, String> approvedAdminGDPR, String currentVersion, JsonCallbackEvents finishEvents) {
String gdprApprovalText = session.getConfiguration().getGDPRproperty("text");
String agreeButtonText = session.getConfiguration().getGDPRproperty("agree");
String disagreeButtonText = session.getConfiguration().getGDPRproperty("disagree");
String disagreeResult = session.getConfiguration().getGDPRproperty("disagree_result");
String title = session.getConfiguration().getGDPRproperty("title");
String backToGdprConfirm = session.getConfiguration().getGDPRproperty("disagree_back");
HTML html = new HTML("<div height=\"500\" width=\"420\">" + gdprApprovalText + "</div>");
Confirm gdprConfirm = new Confirm(title, html, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
SetAttribute setAttribute = new SetAttribute(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// approved finish loading UI
finishEvents.onFinished(null);
}
@Override
public void onError(PerunError error) {
error.setErrorInfo("Failed to store your GDPR approval for version: " + currentVersion);
finishEvents.onError(error);
}
});
approvedAdminGDPR.put(currentVersion, JsonUtils.getCurrentDateAsString());
a.setValueAsMap(approvedAdminGDPR);
setAttribute.setAttribute(ids, a);
}
}, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Confirm disagreeConfirm = new Confirm(title, new HTML(disagreeResult), false);
disagreeConfirm.setNonScrollable(true);
disagreeConfirm.setAutoHide(false);
disagreeConfirm.setOkButtonText(backToGdprConfirm);
disagreeConfirm.setOkClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
finishEvents.onError(null);
Window.Location.reload();
}
});
disagreeConfirm.show();
}
}, agreeButtonText, disagreeButtonText, true);
gdprConfirm.setNonScrollable(true);
gdprConfirm.setAutoHide(false);
gdprConfirm.show();
}
use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.
the class WebGui method checkIfMailVerification.
/**
* Check if URL parameters contains data for mail verification and display different GUI instead.
*
* @return TRUE if parameters are contained and valid in URL, FALSE otherwise.
*/
public boolean checkIfMailVerification() {
// Trigger validation if necessary
if (Location.getParameterMap().keySet().contains("token") && Location.getParameterMap().keySet().contains("u")) {
String verifyToken = Location.getParameter("token");
String verifyU = Location.getParameter("u");
if (verifyToken != null && !verifyToken.isEmpty() && verifyU != null && !verifyU.isEmpty() && JsonUtils.checkParseInt(verifyU)) {
ValidatePreferredEmailChange call = new ValidatePreferredEmailChange(verifyToken, Integer.parseInt(verifyU), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType over = jso.cast();
RootLayoutPanel body = RootLayoutPanel.get();
body.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>" + "The email address: <i>" + (SafeHtmlUtils.fromString(over.getString())).asString() + "</i></h2><h2>was verified and set as your preferred email.</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
body.add(ft);
}
@Override
public void onLoadingStart() {
RootLayoutPanel body = RootLayoutPanel.get();
body.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setWidget(0, 0, new AjaxLoaderImage());
body.add(ft);
}
@Override
public void onError(PerunError error) {
RootLayoutPanel body = RootLayoutPanel.get();
body.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.deleteIcon()) + "<h2>Your new email address couldn't be verified !</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
if (error == null) {
ft.setHTML(1, 0, "Request timeout exceeded.");
ft.getFlexCellFormatter().setStyleName(1, 0, "serverResponseLabelError");
} else {
// display raw message
ft.setHTML(1, 0, "<strong>" + error.getErrorInfo() + "</strong>");
}
ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
body.add(ft);
}
});
call.retrieveData();
}
return true;
}
return false;
}
Aggregations