use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class CreateService method createService.
/**
* Attempts to create a new Service, it first tests the values and then submits them.
*
* @param name service Name
*/
public void createService(final String name) {
this.serviceName = name;
// test arguments
if (!this.testCreating()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Creating service " + serviceName + " failed.");
// custom events
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Service " + serviceName + " created.");
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, prepareJSONObject());
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class SetLogin method setLogin.
/**
* Set new login for user
*
* @param userId
* @param namespace
* @param login
*/
public void setLogin(final int userId, final String namespace, final String login) {
this.userId = userId;
this.login = login;
this.namespace = namespace;
// test arguments
if (!this.testAdding()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding login to user: " + userId + " failed.");
// custom events
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Login successfully added to user: " + userId);
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, prepareJSONObject());
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class AddRequiredAttribute method addRequiredAttribute.
/**
* Attempts to add required attribute to specified service
*
* @param serviceId ID of service to get new required attribute
* @param attributeId ID of attribute def. which will be added as required
*/
public void addRequiredAttribute(final int serviceId, final int attributeId) {
this.serviceId = serviceId;
this.attributeId = attributeId;
// test arguments
if (!this.testAdding()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding required attribute ID: " + attributeId + " to service ID: " + serviceId + " failed.");
events.onError(error);
}
;
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Attribute ID: " + attributeId + " set as required to service ID: " + serviceId);
;
events.onFinished(jso);
}
;
public void onLoadingStart() {
events.onLoadingStart();
}
;
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, prepareJSONObject());
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class AddServiceToServicesPackage method addServiceToServicesPackage.
/**
* Attempts to add new Service to service package, it first tests the values and then submits them.
*
* @param packageId ID of services package to add service to
* @param serviceId ID of service to be added to services package
*/
public void addServiceToServicesPackage(int packageId, int serviceId) {
this.serviceId = serviceId;
this.packageId = packageId;
// test arguments
if (!this.testAdding()) {
return;
}
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Adding service to services package failed.");
if (error != null && error.getName().equals("ServiceAlreadyAssignedException")) {
UiElements.generateError(error, "Service is already assigned", "Service is already assigned to this services package.");
} else {
JsonErrorHandler.alertBox(error);
}
// custom events
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
session.getUiElements().setLogSuccessText("Service added to services package.");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
// custom error handling
jspc.setHidden(true);
jspc.sendData(JSON_URL, prepareJSONObject());
}
use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.
the class VoMembersTabItem method draw.
public Widget draw() {
// SET TAB NAME
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": members");
// MAIN PANEL
final VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// MENU
TabMenu tabMenu = new TabMenu();
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
// DISABLED CHECKBOX
final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
disabled.setValue(wasDisabled);
disabled.setVisible(false);
// CALLBACKS
final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, null);
final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
members.excludeDisabled(!wasDisabled);
final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInVo());
final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInVo());
if (!session.isVoAdmin(voId))
findMembers.setCheckable(false);
final CellTable<RichMember> table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {
// when user click on a row -> open new tab
public void update(int index, RichMember object, RichMember value) {
session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), 0));
}
});
// refresh
tabMenu.addWidget(UiElements.getRefreshButton(this));
// ADD
CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToVo(), new ClickHandler() {
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddMemberToVoTabItem(voId), true);
}
});
if (!session.isVoAdmin(voId))
addButton.setEnabled(false);
tabMenu.addWidget(addButton);
// REMOVE
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromVo());
if (!session.isVoAdmin(voId))
removeButton.setEnabled(false);
tabMenu.addWidget(removeButton);
/*
final CustomButton addServiceButton = new CustomButton(ButtonTranslation.INSTANCE.createServiceMemberButton(), ButtonTranslation.INSTANCE.createServiceMember(), SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
session.getTabManager().addTabToCurrentTab(new CreateServiceMemberInVoTabItem(vo));
}
});
if (!session.isVoAdmin(voId)) addServiceButton.setEnabled(false);
tabMenu.addWidget(addServiceButton);
*/
// refreshMembers
final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (search) {
findMembers.searchFor(searchString);
} else {
findMembers.clearTable();
members.retrieveData();
}
}
};
// add click handler for remove button
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// state specific events
final ArrayList<RichMember> membersForRemoving = findMembers.getTableSelectedList();
String text = "Following members will be removed from VO and their settings will be lost.<p>You can consider changing their status to \"DISABLED\", which will prevent them from accessing VO resources.";
UiElements.showDeleteConfirm(membersForRemoving, text, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < membersForRemoving.size(); i++) {
DeleteMember request;
if (i == membersForRemoving.size() - 1) {
request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
} else {
request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.deleteMember(membersForRemoving.get(i).getId());
}
}
});
}
});
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
public void searchFor(String text) {
searchString = text;
search = true;
findMembers.searchFor(text);
}
}, searchButton);
searchBox.getTextBox().setText(searchString);
// checkbox click handler
disabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
wasDisabled = disabled.getValue();
if (search) {
// case when update but not triggered by button
searchString = searchBox.getTextBox().getText();
members.excludeDisabled(!disabled.getValue());
} else {
members.excludeDisabled(!disabled.getValue());
members.retrieveData();
}
}
});
findMembers.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
searchBox.getTextBox().setEnabled(true);
listAllButton.setEnabled(true);
}
@Override
public void onError(PerunError error) {
searchBox.getTextBox().setEnabled(true);
listAllButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
searchBox.getTextBox().setEnabled(false);
listAllButton.setEnabled(false);
disabled.setVisible(false);
}
}));
members.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(listAllButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// pass data to table handling callback
findMembers.onFinished(jso);
((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("VO has no members.");
searchBox.getTextBox().setEnabled(true);
searchButton.setEnabled(true);
}
@Override
public void onError(PerunError error) {
// pass data to table handling callback
findMembers.onError(error);
searchBox.getTextBox().setEnabled(true);
searchButton.setEnabled(true);
}
@Override
public void onLoadingStart() {
searchBox.getTextBox().setEnabled(false);
searchButton.setEnabled(false);
disabled.setVisible(true);
// to show progress when reloading
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
}
}));
// LIST ALL BUTTON
listAllButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
search = false;
searchString = "";
searchBox.getTextBox().setText("");
findMembers.clearTable();
members.retrieveData();
}
});
tabMenu.addWidget(listAllButton);
tabMenu.addWidget(disabled);
/* WHEN TAB RELOADS, CHECK THE STATE */
if (search) {
findMembers.searchFor(searchString);
} else {
members.excludeDisabled(!disabled.getValue());
members.retrieveData();
}
ScrollPanel tableWrapper = new ScrollPanel();
table.addStyleName("perun-table");
tableWrapper.setWidget(table);
tableWrapper.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(tableWrapper, 350, this);
// add menu and the table to the main panel
firstTabPanel.add(tableWrapper);
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(findMembers, table, removeButton);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations