use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class WebGui method loadPerunPrincipal.
/**
* Performs a login into the RPC, loads user and his roles into session and enables GUI.
*/
private void loadPerunPrincipal() {
// WEB PAGE SPLITTER
final DockLayoutPanel bodySplitter = new DockLayoutPanel(Unit.PX);
body.add(bodySplitter);
// MAIN CONTENT WRAPPER - make content resize-able
final ResizeLayoutPanel contentWrapper = new ResizeLayoutPanel();
contentWrapper.setSize("100%", "100%");
// MAIN CONTENT
AbsolutePanel contentPanel = new AbsolutePanel();
contentPanel.setSize("100%", "100%");
// put content into wrapper
contentWrapper.setWidget(contentPanel);
// SETUP SESSION
// store handler for main contetn's elements (tabs etc.) into session
session.setUiElements(new UiElements(contentPanel));
// Store TabManager into session for handling tabs (add/remove/close...)
session.setTabManager(new TabManager());
// Store this class into session
session.setWebGui(webgui);
// Set this class as browser's History handler
History.addValueChangeHandler(webgui);
// show loading box
final PopupPanel loadingBox = session.getUiElements().perunLoadingBox();
loadingBox.show();
// events after getting PerunPrincipal from RPC
final JsonCallbackEvents events = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// store perun principal into session for future use
final PerunPrincipal pp = (PerunPrincipal) jso;
session.setPerunPrincipal(pp);
GetGuiConfiguration getConfig = new GetGuiConfiguration(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
session.setConfiguration((BasicOverlayType) jso.cast());
String newGuiAlertContent = session.getConfiguration().getCustomProperty("newAdminGuiAlert");
if (newGuiAlertContent != null && !newGuiAlertContent.isEmpty()) {
DOM.getElementById("perun-new-gui-alert").setInnerHTML(newGuiAlertContent);
DOM.getElementById("perun-new-gui-alert").setClassName("newGuiAlertActive");
}
// check if user exists
if (session.getUser() == null && !pp.getRoles().hasAnyRole()) {
// if not and no role, redraw page body
RootLayoutPanel body = RootLayoutPanel.get();
loadingBox.hide();
body.clear();
body.add(new NotUserOfPerunWidget());
return;
}
// check if user exists
if (session.getUser().isServiceUser()) {
// if not and no role, redraw page body
RootLayoutPanel body = RootLayoutPanel.get();
loadingBox.hide();
body.clear();
body.add(new CantLogAsServiceUserWidget());
return;
}
// Sets URL mapper for loading proper tabs
urlMapper = new UrlMapper();
// MENU WRAPPER
VerticalPanel menuWrapper = new VerticalPanel();
menuWrapper.setHeight("100%");
// add menu
menuWrapper.add(session.getUiElements().getMenu().getWidget());
menuWrapper.setCellVerticalAlignment(session.getUiElements().getMenu().getWidget(), HasVerticalAlignment.ALIGN_TOP);
// Put all panels into web page splitter
// bodySplitter.addNorth(session.getUiElements().getHeader(), 78);
bodySplitter.addNorth(session.getUiElements().getHeader(), 64);
bodySplitter.addSouth(session.getUiElements().getFooter(), 30);
bodySplitter.addWest(menuWrapper, 202);
// content must be added as last !!
bodySplitter.add(contentWrapper);
// Append more GUI elements from UiElements class which are not part of splitted design
if ("true".equalsIgnoreCase(Location.getParameter("log"))) {
// log
bodySplitter.getElement().appendChild(session.getUiElements().getLog().getElement());
}
// status
bodySplitter.getElement().appendChild(session.getUiElements().getStatus().getElement());
// keep alive
VerticalPanel vp = new VerticalPanel();
vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
vp.add(new HTML("<h2>Connection to Perun has been lost.</h2><strong>Please check your internet connection.</strong>"));
final FlexTable layout = new FlexTable();
layout.setVisible(false);
layout.setHTML(0, 0, "<p>You can also try to <strong>refresh the browser window</strong>. However, all <strong>unsaved changes will be lost</strong>.");
layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_TOP);
vp.add(layout);
vp.setSpacing(10);
final Confirm c = new Confirm("", vp, true);
c.setAutoHide(false);
c.setHideOnButtonClick(false);
c.setOkIcon(SmallIcons.INSTANCE.arrowRefreshIcon());
c.setOkButtonText("Re-connect");
c.setNonScrollable(true);
c.setOkClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
KeepAlive call = new KeepAlive(JsonCallbackEvents.disableButtonEvents(c.getOkButton(), new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
checkPending = true;
}
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType type = jso.cast();
checkPending = false;
connected = true;
keepAliveCounter = 0;
if (type.getString().equals("OK")) {
if (c.isShowing()) {
c.hide();
}
}
// If ok, append new keepalive checker
appendKeepAliveChecker(c);
}
@Override
public void onError(PerunError error) {
checkPending = false;
// connection lost only IF TIMEOUT
if (error != null && error.getErrorId().equals("0")) {
keepAliveCounter++;
if (keepAliveCounter >= keepAliveTreshold) {
connected = false;
if (!c.isShowing()) {
c.show();
}
layout.setVisible(true);
c.getOkButton().setText("Reload");
c.getOkButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.Location.reload();
}
});
} else {
// not connected but under treshold
appendKeepAliveChecker(c);
}
}
}
}));
call.retrieveData();
}
});
appendKeepAliveChecker(c);
// store users roles and editable entities into session
session.setRoles(pp.getRoles());
// display logged user
session.getUiElements().setLoggedUserInfo(pp);
session.getUiElements().setLogText("Welcome " + pp.getUser().getFullNameWithTitles());
// show extended info ?
boolean showExtendedInfo = false;
// is perun admin ?
if (session.isPerunAdmin()) {
showExtendedInfo = true;
}
// replace by local storage if possible
Storage localStorage = Storage.getLocalStorageIfSupported();
if (localStorage != null) {
String value = localStorage.getItem("urn:perun:gui:preferences:extendedInfo");
if (value != null) {
showExtendedInfo = Boolean.parseBoolean(value);
}
}
// finally set it
JsonUtils.setExtendedInfoVisible(showExtendedInfo);
// set extended info button
session.getUiElements().getExtendedInfoButtonWidget().setDown(showExtendedInfo);
// Specific GDPR approval is required only from admins
if (session.isFacilityAdmin() || session.isVoAdmin() || session.isVoObserver() || session.isGroupAdmin() || session.isPerunAdmin() || session.isSecurityAdmin()) {
checkGdprApproval(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// FINISH LOADING UI ONCE ITS CHECKED
// perun loaded = true
perunLoaded = true;
// loads the page based on URL or default
loadPage();
// hides the loading box
loadingBox.hide();
// load proper parts of menu (based on roles)
session.getUiElements().getMenu().prepare();
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error != null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
} else {
String checkFailed = session.getConfiguration().getGDPRproperty("check_failed");
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(checkFailed);
}
loadingFailedBox.show();
}
});
} else {
// NO GDPR CHECK NEEDED
// perun loaded = true
perunLoaded = true;
// loads the page based on URL or default
loadPage();
// hides the loading box
loadingBox.hide();
// load proper parts of menu (based on roles)
session.getUiElements().getMenu().prepare();
}
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error != null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
if (!error.getErrorId().equals("0")) {
loadingFailedBox.show();
}
}
});
getConfig.retrieveData();
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error == null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
loadingFailedBox.show();
}
};
GetPerunPrincipal loggedUserRequst = new GetPerunPrincipal(events);
loggedUserRequst.retrieveData();
}
use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class WebGui method appendKeepAliveChecker.
/**
* Append keep-alive checker.
*
* @param c Confirm displayed when connection is lost
*/
private void appendKeepAliveChecker(final Confirm c) {
// Check RPC URL every 15 sec if call not pending
Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
KeepAlive call = new KeepAlive(new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
checkPending = true;
}
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType type = jso.cast();
checkPending = false;
keepAliveCounter = 0;
if (type.getString().equals("OK")) {
if (c.isShowing()) {
c.hide();
}
}
}
@Override
public void onError(PerunError error) {
checkPending = false;
if (error != null && error.getErrorId().equals("0")) {
keepAliveCounter++;
if (keepAliveCounter >= keepAliveTreshold) {
// connection lost only IF TIMEOUT and treshold
if (!c.isShowing()) {
c.show();
}
connected = false;
}
}
}
});
if (!checkPending && perunLoaded && connected) {
call.retrieveData();
}
return connected;
}
}, 15000);
}
use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class ApplicationDetailTabItem method draw.
public Widget draw() {
tab = this;
row = 0;
boolean buttonsEnabled = ((session.isVoAdmin(app.getVo().getId())) || (app.getGroup() != null && session.isGroupAdmin(app.getGroup().getId())));
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
final FlexTable ft = new FlexTable();
String text = "<strong>Submitted by:</strong> ";
if (app.getUser() != null) {
text += SafeHtmlUtils.fromString(app.getUser().getFullNameWithTitles() + " (" + app.getCreatedBy() + ")").asString();
} else {
text += SafeHtmlUtils.fromString(app.getCreatedBy()).asString();
}
text += " <strong>from External Source:</strong> " + SafeHtmlUtils.fromString(app.getExtSourceName()).asString() + " <strong>with Level of Assurance:</strong> " + app.getExtSourceLoa();
text += " <strong>on: </strong> " + app.getCreatedAt().split("\\.")[0];
ft.setHTML(row, 0, text);
ft.setCellSpacing(5);
row++;
if (app.getGroup() != null) {
ft.setHTML(row, 0, "<strong>Application for group: </strong>" + SafeHtmlUtils.fromString((app.getGroup().getName() != null) ? app.getGroup().getName() : "").asString() + "<strong> in VO: </strong>" + SafeHtmlUtils.fromString((app.getVo().getName() != null) ? app.getVo().getName() : "").asString());
} else {
ft.setHTML(row, 0, "<strong>Application for VO: </strong>" + SafeHtmlUtils.fromString((app.getVo().getName() != null) ? app.getVo().getName() : "").asString());
}
if (app.getState().equalsIgnoreCase("APPROVED")) {
row++;
ft.setHTML(row, 0, "<strong>Approved by:</strong> " + ((app.getModifiedBy().equalsIgnoreCase("perunRegistrar")) ? "automatically" : Utils.convertCertCN(app.getModifiedBy())) + " <strong>on: </strong> " + app.getModifiedAt().split("\\.")[0]);
}
if (app.getState().equalsIgnoreCase("REJECTED")) {
row++;
ft.setHTML(row, 0, "<strong>Rejected by:</strong> " + ((app.getModifiedBy().equalsIgnoreCase("perunRegistrar")) ? "automatically" : Utils.convertCertCN(app.getModifiedBy())) + " <strong>on: </strong> " + app.getModifiedAt().split("\\.")[0]);
}
// for extension in VO if not approved or rejected
if (app.getType().equalsIgnoreCase("EXTENSION") && app.getUser() != null && !app.getState().equalsIgnoreCase("APPROVED") && !app.getState().equalsIgnoreCase("REJECTED")) {
GetNewExtendMembership ex = new GetNewExtendMembership(app.getVo().getId(), app.getUser().getId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (jso != null) {
BasicOverlayType basic = jso.cast();
row++;
ft.setHTML(row, 0, "<strong>New membership expiration:</strong> " + SafeHtmlUtils.fromString(basic.getString()).asString());
}
}
});
ex.retrieveData();
}
// for initial in VO, if not approved or rejected
if (app.getType().equalsIgnoreCase("INITIAL") && app.getGroup() == null && !app.getState().equalsIgnoreCase("APPROVED") && !app.getState().equalsIgnoreCase("REJECTED")) {
GetNewExtendMembershipLoa ex = new GetNewExtendMembershipLoa(app.getVo().getId(), app.getExtSourceLoa(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (jso != null) {
BasicOverlayType basic = jso.cast();
row++;
ft.setHTML(row, 0, "<strong>New membership expiration:</strong> " + SafeHtmlUtils.fromString(basic.getString()).asString());
}
}
});
ex.retrieveData();
}
vp.add(ft);
vp.add(new HTML("<hr size=\"1\" style=\"color: #ccc;\"/>"));
// only NEW apps can be Verified
if (app.getState().equals("NEW")) {
if (session.isPerunAdmin()) {
// verify button
final CustomButton verify = TabMenu.getPredefinedButton(ButtonType.VERIFY, ButtonTranslation.INSTANCE.verifyApplication());
menu.addWidget(verify);
verify.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(verify, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
app = jso.cast();
draw();
refreshParent = true;
}
}));
request.verifyApplication(appId);
}
});
}
}
// only VERIFIED apps can be approved/rejected
if (app.getState().equals("VERIFIED") || app.getState().equals("NEW")) {
// accept button
final CustomButton approve = TabMenu.getPredefinedButton(ButtonType.APPROVE, ButtonTranslation.INSTANCE.approveApplication());
approve.setEnabled(buttonsEnabled);
menu.addWidget(approve);
approve.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(approve, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
refreshParent = true;
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
request.approveApplication(app);
}
});
// reject button
final CustomButton reject = TabMenu.getPredefinedButton(ButtonType.REJECT, ButtonTranslation.INSTANCE.rejectApplication());
reject.setEnabled(buttonsEnabled);
menu.addWidget(reject);
reject.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// confirm content
FlexTable content = new FlexTable();
content.setCellSpacing(10);
content.setHTML(0, 0, "Please specify reason of rejection to let user know why was application rejected.");
content.getFlexCellFormatter().setColSpan(0, 0, 2);
final TextArea reason = new TextArea();
reason.setSize("300px", "150px");
content.setHTML(1, 0, "<strong>Reason: </strong>");
content.setWidget(1, 1, reason);
Confirm c = new Confirm("Specify reason", content, new ClickHandler() {
public void onClick(ClickEvent event) {
HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(reject, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
refreshParent = true;
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
request.rejectApplication(appId, reason.getText());
}
}, true);
c.show();
}
});
}
if (app.getState().equals("NEW") || app.getState().equals("REJECTED")) {
// delete button
final CustomButton delete = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteApplication());
delete.setEnabled(buttonsEnabled);
menu.addWidget(delete);
delete.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
HandleApplication request = new HandleApplication(JsonCallbackEvents.disableButtonEvents(delete, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
refreshParent = true;
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
request.deleteApplication(appId);
}
});
}
// NOTIFICATION SENDER
final CustomButton send = new CustomButton("Re-send notifications...", SmallIcons.INSTANCE.emailIcon());
send.setEnabled(buttonsEnabled);
menu.addWidget(send);
send.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final FlexTable ft = new FlexTable();
ft.setStyleName("inputFormFlexTable");
ft.setWidth("400px");
final ListBox selection = new ListBox();
selection.setWidth("200px");
if (session.isPerunAdmin()) {
// add all except user invite
for (ApplicationMail.MailType mail : ApplicationMail.MailType.values()) {
if (!mail.equals(ApplicationMail.MailType.USER_INVITE)) {
selection.addItem(ApplicationMail.getTranslatedMailType(mail.toString()), mail.toString());
}
}
} else {
// add TYPEs based on actual APP-STATE
if (app.getState().equals("NEW")) {
selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_USER"), "APP_CREATED_USER");
selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_VO_ADMIN"), "APP_CREATED_VO_ADMIN");
selection.addItem(ApplicationMail.getTranslatedMailType("MAIL_VALIDATION"), "MAIL_VALIDATION");
} else if (app.getState().equals("VERIFIED")) {
selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_USER"), "APP_CREATED_USER");
selection.addItem(ApplicationMail.getTranslatedMailType("APP_CREATED_VO_ADMIN"), "APP_CREATED_VO_ADMIN");
} else if (app.getState().equals("APPROVED")) {
selection.addItem(ApplicationMail.getTranslatedMailType("APP_APPROVED_USER"), "APP_APPROVED_USER");
} else if (app.getState().equals("REJECTED")) {
selection.addItem(ApplicationMail.getTranslatedMailType("APP_REJECTED_USER"), "APP_REJECTED_USER");
}
// FIXME - how to handle APPROVABLE_GROUP_APP_USER
}
ft.setHTML(0, 0, "Select notification:");
ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
ft.setWidget(0, 1, selection);
final TextArea reason = new TextArea();
reason.setSize("250px", "100px");
selection.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (selection.getValue(selection.getSelectedIndex()).equals("APP_REJECTED_USER")) {
ft.setHTML(1, 0, "Reason:");
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
ft.setWidget(1, 1, reason);
} else {
ft.setHTML(1, 0, "");
ft.setHTML(1, 1, "");
}
}
});
// if pre-selected
if (selection.getValue(selection.getSelectedIndex()).equals("APP_REJECTED_USER")) {
ft.setHTML(1, 0, "Reason:");
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
ft.setWidget(1, 1, reason);
} else {
ft.setHTML(1, 0, "");
ft.setHTML(1, 1, "");
}
final Confirm c = new Confirm("Re-send notifications", ft, null, true);
c.setOkIcon(SmallIcons.INSTANCE.emailIcon());
c.setOkButtonText("Send");
c.setNonScrollable(true);
c.setOkClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ResendNotification call = new ResendNotification(appId, JsonCallbackEvents.disableButtonEvents(c.getOkButton(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
c.hide();
}
}));
if (selection.getValue(selection.getSelectedIndex()).equals("APP_REJECTED_USER")) {
call.resendNotification(selection.getValue(selection.getSelectedIndex()), reason.getValue().trim());
} else {
call.resendNotification(selection.getValue(selection.getSelectedIndex()), null);
}
}
});
c.setCancelClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
c.hide();
}
});
c.show();
}
});
menu.addWidget(new HTML("<strong>TYPE: </strong>" + Application.getTranslatedType(app.getType())));
menu.addWidget(new HTML("<strong>STATE: </strong>" + Application.getTranslatedState(app.getState())));
GetApplicationDataById data = new GetApplicationDataById(appId);
data.setEditable(app.getState().equals("VERIFIED") || app.getState().equals("NEW"));
data.setEmbedded(app.getType().equals("EMBEDDED"), app.getUser());
data.retrieveData();
ScrollPanel sp = new ScrollPanel(data.getContents());
sp.setSize("100%", "100%");
vp.add(sp);
vp.setCellHeight(sp, "100%");
vp.setCellHorizontalAlignment(sp, HasHorizontalAlignment.ALIGN_CENTER);
session.getUiElements().resizePerunTable(sp, 400, this);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations