use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.
the class PreviewFormTabItem method prepareApplicationForm.
/**
* Prepares the widgets from the items as A DISPLAY FOR THE USER
*
* @param sp scroll panel
*/
public void prepareApplicationForm(ScrollPanel sp) {
FlexTable ft = new FlexTable();
ft.setSize("100%", "100%");
ft.setCellPadding(10);
FlexCellFormatter fcf = ft.getFlexCellFormatter();
int i = 0;
for (final ApplicationFormItem item : formItems) {
// skip items not from correct app type
ArrayList<String> itemApplicationTypes = JsonUtils.listFromJsArrayString(item.getApplicationTypes());
if (!itemApplicationTypes.contains(appType))
continue;
// generate correct items
RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, locale);
this.applFormGenerators.add(gen);
gen.addValidationTrigger(new FormValidator() {
public void triggerValidation() {
validateFormValues(false);
}
});
// if button, add onclick
if (item.getType().equals("SUBMIT_BUTTON")) {
this.sendButton = (Button) gen.getWidget();
sendButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// revalidate again, with force validation
if (!validateFormValues(true)) {
return;
}
// sending is disabled
Confirm c = new Confirm("Sending disabled", new Label("Sending form is disabled in preview mode, but form items value validation works."), true);
c.show();
}
});
}
// get localized texts
ItemTexts itemTexts = item.getItemTexts(locale);
if (item.getHidden().equals("ALWAYS")) {
continue;
}
// WITH LABEL (input box ...)
if (gen.isLabelShown()) {
// 0 = label
if (item.isRequired() == true) {
// required
ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "*</strong>");
} else {
// optional
ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong>");
}
// 1 = widget with icons
HorizontalPanel hp = new HorizontalPanel();
hp.setSpacing(10);
Widget w = gen.getWidget();
w.setTitle(itemTexts.getHelp());
if (item.getDisabled().equals("ALWAYS")) {
w.getElement().setAttribute("disabled", "disabled");
}
hp.add(w);
// lock icon
if (item.getDisabled() != "NEVER") {
Image lockIcon = new Image(SmallIcons.INSTANCE.lockIcon());
lockIcon.setStyleName("pointer");
String dependency = item.getDisabledDependencyItemId() == 0 ? "it" : formItems.stream().filter(it -> it.getId() == item.getDisabledDependencyItemId()).collect(Collectors.toList()).get(0).getShortname();
switch(item.getDisabled()) {
case "ALWAYS":
lockIcon.setTitle("Always disabled");
break;
case "IF_EMPTY":
lockIcon.setTitle("Disabled when " + dependency + " is empty");
break;
case "IF_PREFILLED":
lockIcon.setTitle("Disabled when " + dependency + " is prefilled");
break;
}
hp.add(lockIcon);
}
// eye icon
if (item.getHidden() != "NEVER") {
Image eyeIcon = new Image(SmallIcons.INSTANCE.hiddenIcon());
eyeIcon.setStyleName("pointer");
String dependency = item.getHiddenDependencyItemId() == 0 ? "it" : formItems.stream().filter(it -> it.getId() == item.getHiddenDependencyItemId()).collect(Collectors.toList()).get(0).getShortname();
switch(item.getHidden()) {
case "ALWAYS":
eyeIcon.setTitle("Always hidden");
break;
case "IF_EMPTY":
eyeIcon.setTitle("Hidden when " + dependency + " is empty");
break;
case "IF_PREFILLED":
eyeIcon.setTitle("Hidden when " + dependency + " is prefilled");
break;
}
hp.add(eyeIcon);
}
ft.setWidget(i, 1, hp);
// 2 = status
ft.setWidget(i, 2, gen.getStatusWidget());
// 3 = HELP
if (itemTexts.getHelp() != null && itemTexts.getHelp().length() > 0) {
Label help = new Label(itemTexts.getHelp());
ft.setWidget(i, 3, help);
}
// format
fcf.setStyleName(i, 0, "applicationFormLabel");
fcf.setStyleName(i, 1, "applicationFormWidget");
fcf.setStyleName(i, 2, "applicationFormCheck");
fcf.setStyleName(i, 3, "applicationFormHelp");
ft.setWidth("100%");
// ELSE HTML COMMENT
} else {
ft.setWidget(i, 0, gen.getWidget());
// colspan = 2
fcf.setColSpan(i, 0, 4);
fcf.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT);
fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_MIDDLE);
}
i++;
}
sp.setWidget(ft);
}
use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.
the class DeleteSecurityTeam method testDeleting.
/**
* Tests the values, if the process can continue
*
* @return true/false for continue/stop
*/
private boolean testDeleting() {
boolean result = true;
String errorMsg = "";
if (securityTeamId == 0) {
errorMsg += "Wrong parameter <strong>SECURITY TEAM ID</strong>.\n";
result = false;
}
if (errorMsg.length() > 0) {
Confirm c = new Confirm("Error while deleting Security Team", new HTML(errorMsg), true);
c.show();
}
return result;
}
use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.
the class CreateSecurityTeam method testCreating.
/**
* Tests the values, if the process can continue
*
* @return
*/
private boolean testCreating() {
boolean result = true;
String errorMsg = "";
if (name.length() == 0) {
errorMsg += "You must fill in the parameter <strong>Name</strong>.<br />";
result = false;
}
if (errorMsg.length() > 0) {
Confirm c = new Confirm("Error while creating SecurityTeam", new HTML(errorMsg), true);
c.show();
}
return result;
}
use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.
the class UpdateSecurityTeam method testCreating.
/**
* Tests the values, if the process can continue
*
* @return
*/
private boolean testCreating() {
boolean result = true;
String errorMsg = "";
if (team == null) {
errorMsg += "Can't update NULL SecurityTeam.<br />";
result = false;
}
if (team.getName().length() == 0) {
errorMsg += "Security Team must have parameter <strong>Name</strong>.<br />";
result = false;
}
if (errorMsg.length() > 0) {
Confirm c = new Confirm("Error while updating SecurityTeam", new HTML(errorMsg), true);
c.show();
}
return result;
}
use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.
the class GetAllRichSubGroups method getTable.
/**
* Returns the table with subgroups.
* @return
*/
public CellTable<RichGroup> getTable() {
// retrieve data
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<RichGroup>(list);
// Cell table
table = new PerunTable<RichGroup>(list);
table.setHyperlinksAllowed(false);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<RichGroup> columnSortHandler = new ListHandler<RichGroup>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichGroup>createCheckboxManager());
// set empty content & loader
table.setEmptyTableWidget(loaderImage);
loaderImage.setEmptyResultMessage("Group has no sub-groups.");
// checkbox column column
table.addCheckBoxColumn();
table.addIdColumn("Group ID", tableFieldUpdater);
// Add a synchronization clicable icon column.
Column<RichGroup, RichGroup> syncColumn = new Column<RichGroup, RichGroup>(new CustomClickableInfoCellWithImageResource("click")) {
@Override
public RichGroup getValue(RichGroup object) {
return object;
}
@Override
public String getCellStyleNames(Cell.Context context, RichGroup object) {
if (tableFieldUpdater != null) {
return super.getCellStyleNames(context, object) + " pointer image-hover";
} else {
return super.getCellStyleNames(context, object);
}
}
};
syncColumn.setFieldUpdater(new FieldUpdater<RichGroup, RichGroup>() {
@Override
public void update(int index, final RichGroup object, RichGroup value) {
GetEntityById get = new GetEntityById(PerunEntity.RICH_GROUP, object.getId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
final RichGroup object = jso.cast();
String name, syncEnabled, syncInterval, syncStartTimestamp, syncTimestamp, syncSuccessTimestamp, syncState, authGroup, syncTimes, syncSuccessStartTimestamp;
name = object.getName();
if (object.isSyncEnabled()) {
syncEnabled = "enabled";
} else {
syncEnabled = "disabled";
}
if (object.getSynchronizationInterval() == null) {
syncInterval = "N/A";
} else {
if (JsonUtils.checkParseInt(object.getSynchronizationInterval())) {
int time = Integer.parseInt(object.getSynchronizationInterval()) * 5 / 60;
if (time == 0) {
time = Integer.parseInt(object.getSynchronizationInterval()) * 5;
syncInterval = time + " minute(s)";
} else {
syncInterval = time + " hour(s)";
}
} else {
syncInterval = object.getSynchronizationInterval();
}
}
if (object.getSynchronizationTimes() != null && object.getSynchronizationTimes().length() > 0) {
syncTimes = object.getSynchronizationTimes().join(", ");
} else {
syncTimes = "N/A";
}
if (object.getLastSynchronizationState() == null) {
if (object.getLastSuccessSynchronizationTimestamp() != null) {
syncState = "OK";
} else {
syncState = "Not synced yet";
}
} else {
if (session.isPerunAdmin()) {
syncState = object.getLastSynchronizationState();
} else {
syncState = "Internal Error";
}
}
if (object.getLastSynchronizationTimestamp() == null) {
syncTimestamp = "N/A";
} else {
syncTimestamp = object.getLastSynchronizationTimestamp().split("\\.")[0];
}
if (object.getStartOfLastSynchronizationTimestamp() == null) {
syncStartTimestamp = "N/A";
} else {
syncStartTimestamp = object.getStartOfLastSynchronizationTimestamp().split("\\.")[0];
}
if (object.getLastSuccessSynchronizationTimestamp() == null) {
syncSuccessTimestamp = "N/A";
} else {
syncSuccessTimestamp = object.getLastSuccessSynchronizationTimestamp().split("\\.")[0];
}
if (object.getStartOfLastSuccessfulSynchronization() == null) {
syncSuccessStartTimestamp = "N/A";
} else {
syncSuccessStartTimestamp = object.getStartOfLastSuccessfulSynchronization().split("\\.")[0];
}
if (Objects.equals(object.getAuthoritativeGroup(), "1")) {
authGroup = "Yes";
} else {
authGroup = "No";
}
String html = "Group name: <b>" + SafeHtmlUtils.fromString(name).asString() + "</b><br>";
html += "Authoritative group: <b>" + SafeHtmlUtils.fromString(authGroup).asString() + "</b><br>";
html += "Synchronization: <b>" + SafeHtmlUtils.fromString(syncEnabled).asString() + "</b><br>";
html += "Sync. Interval: <b>" + SafeHtmlUtils.fromString(syncInterval).asString() + "</b><br>";
html += "Sync. Times: <b>" + SafeHtmlUtils.fromString(syncTimes).asString() + "</b><br>-----------------<br>";
if (object.isSyncEnabled()) {
html += "Last sync. state: <b>" + SafeHtmlUtils.fromString(syncState).asString() + "</b><br>";
html += "Last sync. timestamp (start): <b>" + SafeHtmlUtils.fromString(syncStartTimestamp).asString() + "</b><br>";
html += "Last sync. timestamp (end): <b>" + SafeHtmlUtils.fromString(syncTimestamp).asString() + "</b><br>";
html += "Last successful sync. timestamp (start): <b>" + SafeHtmlUtils.fromString(syncSuccessStartTimestamp).asString() + "</b><br>";
html += "Last successful sync. timestamp (end): <b>" + SafeHtmlUtils.fromString(syncSuccessTimestamp).asString() + "</b><br>";
}
FlexTable layout = new FlexTable();
layout.setWidth("450px");
layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.informationIcon())));
layout.setHTML(0, 1, "<p style=\"line-height: 1.2;\">" + html);
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");
final CustomButton okButton = new CustomButton("Force synchronization", SmallIcons.INSTANCE.arrowRefreshIcon());
okButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ForceGroupSynchronization call = new ForceGroupSynchronization(JsonCallbackEvents.disableButtonEvents(okButton));
call.synchronizeGroup(object.getId());
}
});
if (!session.isVoAdmin(object.getVoId()) && !session.isGroupAdmin(object.getId()))
okButton.setEnabled(false);
okButton.setVisible(object.isSyncEnabled());
final Confirm c = new Confirm("Group synchronization info", layout, okButton, null, true);
c.setHideOnButtonClick(false);
c.setCancelIcon(SmallIcons.INSTANCE.acceptIcon());
c.setCancelButtonText("OK");
c.setCancelClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
c.hide();
}
});
c.show();
}
});
get.retrieveData();
}
});
syncColumn.setSortable(true);
columnSortHandler.setComparator(syncColumn, new Comparator<RichGroup>() {
@Override
public int compare(RichGroup o1, RichGroup o2) {
if (o1 != null && o2 != null) {
int o1val = 0;
int o2val = 0;
if (o1.isSyncEnabled())
o1val = 5;
if (o2.isSyncEnabled())
o2val = 5;
if (Objects.equals(o1.getAuthoritativeGroup(), "1"))
o1val = o1val + 3;
if (Objects.equals(o2.getAuthoritativeGroup(), "1"))
o2val = o2val + 3;
return o1val - o2val;
}
return 0;
}
});
table.addColumn(syncColumn, "Sync");
table.setColumnWidth(syncColumn, "70px");
table.addNameColumn(tableFieldUpdater);
table.addDescriptionColumn(tableFieldUpdater);
return table;
}
Aggregations