use of cz.metacentrum.perun.webgui.json.registrarManager.SetSendingEnabled in project perun by CESNET.
the class MailsTabItem method draw.
public Widget draw() {
final GetApplicationMails mailsRequest;
String title = "";
if (group != null) {
title = group.getName();
entity = PerunEntity.GROUP;
entityId = group.getId();
mailsRequest = new GetApplicationMails(entity, group.getId());
} else {
title = vo.getName();
entityId = vo.getId();
mailsRequest = new GetApplicationMails(entity, vo.getId());
}
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(title) + ": " + "Email notifications");
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// add button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CreateMailTabItem(vo, group, form));
}
}));
// remove button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMail());
menu.addWidget(removeButton);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
String text = "Following mail definitions will be removed and users won't receive them anymore.";
UiElements.showDeleteConfirm(list, text, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1) {
DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton));
request.deleteMail(list.get(i).getId(), entityId);
} else {
// refresh table on last call
DeleteApplicationMail request = new DeleteApplicationMail(entity, JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(mailsRequest)));
request.deleteMail(list.get(i).getId(), entityId);
}
}
}
});
}
});
// enable button
CustomButton enableButton = TabMenu.getPredefinedButton(ButtonType.ENABLE, ButtonTranslation.INSTANCE.enableMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
request.setEnabled(list, true);
}
}
});
menu.addWidget(enableButton);
// disable button
CustomButton disableButton = TabMenu.getPredefinedButton(ButtonType.DISABLE, ButtonTranslation.INSTANCE.disableMail(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<ApplicationMail> list = mailsRequest.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
SetSendingEnabled request = new SetSendingEnabled(JsonCallbackEvents.refreshTableEvents(mailsRequest));
request.setEnabled(list, false);
}
}
});
menu.addWidget(disableButton);
menu.addWidget(new CustomButton(ButtonTranslation.INSTANCE.mailFooterButton() + "…", ButtonTranslation.INSTANCE.editMailFooter(), SmallIcons.INSTANCE.emailIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (group == null) {
session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(vo));
} else {
session.getTabManager().addTabToCurrentTab(new EditMailFooterTabItem(group));
}
}
}));
CustomButton copy;
if (group == null) {
copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromVoButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromVo(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(voId, 0));
}
});
} else {
copy = new CustomButton(ButtonTranslation.INSTANCE.copyFromGroupButton() + "…", ButtonTranslation.INSTANCE.copyMailsFromGroup(), SmallIcons.INSTANCE.copyIcon(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new CopyMailsTabItem(group.getVoId(), groupId));
}
});
}
menu.addWidget(copy);
// TABLE
CellTable<ApplicationMail> table = mailsRequest.getTable(new FieldUpdater<ApplicationMail, String>() {
public void update(int index, ApplicationMail appMail, String value) {
session.getTabManager().addTabToCurrentTab(new EditMailTabItem(appMail));
}
});
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
removeButton.setEnabled(false);
enableButton.setEnabled(false);
disableButton.setEnabled(false);
JsonUtils.addTableManagedButton(mailsRequest, table, removeButton);
JsonUtils.addTableManagedButton(mailsRequest, table, enableButton);
JsonUtils.addTableManagedButton(mailsRequest, table, disableButton);
session.getUiElements().resizePerunTable(sp, 100);
firstTabPanel.add(sp);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations