use of cz.metacentrum.perun.webgui.model.Resource in project perun by CESNET.
the class UpdateResource method updateResource.
/**
* Updates resource details
* @param res Resource with updated details
*/
public void updateResource(Resource res) {
if (res == null) {
Window.alert("Resource can't be null");
return;
}
// GROUP OBJECT
JSONObject oldResource = new JSONObject(res);
// RECONSTRUCT OBJECT
JSONObject newResource = new JSONObject();
newResource.put("id", oldResource.get("id"));
newResource.put("name", oldResource.get("name"));
newResource.put("description", oldResource.get("description"));
newResource.put("voId", oldResource.get("voId"));
newResource.put("facilityId", oldResource.get("facilityId"));
newResource.put("beanName", oldResource.get("beanName"));
newResource.put("createdAt", oldResource.get("createdAt"));
newResource.put("createdBy", oldResource.get("createdBy"));
newResource.put("modifiedAt", oldResource.get("modifiedAt"));
newResource.put("modifiedBy", oldResource.get("modifiedBy"));
// whole JSON query
JSONObject jsonQuery = new JSONObject();
jsonQuery.put("resource", newResource);
// new events
JsonCallbackEvents newEvents = new JsonCallbackEvents() {
public void onError(PerunError error) {
session.getUiElements().setLogErrorText("Updating resource failed.");
events.onError(error);
}
public void onFinished(JavaScriptObject jso) {
Resource res = jso.cast();
session.getUiElements().setLogSuccessText("Resource " + res.getName() + " successfully updated!");
events.onFinished(jso);
}
public void onLoadingStart() {
events.onLoadingStart();
}
};
// sending data
JsonPostClient jspc = new JsonPostClient(newEvents);
jspc.sendData(JSON_URL, jsonQuery);
}
use of cz.metacentrum.perun.webgui.model.Resource in project perun by CESNET.
the class SearcherTabItem method loadResourcesTab.
private Widget loadResourcesTab() {
// request
final GetResources request = new GetResources();
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
PerunSearchParametersWidget params = new PerunSearchParametersWidget(PerunEntity.RESOURCE, new PerunSearchParametersWidget.SearchEvent() {
public void search(Map<String, String> map) {
request.clearParameters();
for (Map.Entry<String, String> entry : map.entrySet()) {
request.addSearchParameter(entry.getKey(), entry.getValue());
}
request.search();
}
});
firstTabPanel.add(params);
// get the table
final CellTable<Resource> table = request.getEmptyTable(new FieldUpdater<Resource, String>() {
public void update(int index, Resource object, String value) {
// opens the tab
session.getTabManager().addTab(new ResourceDetailTabItem(object.getId(), object.getFacilityId()));
}
});
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
return firstTabPanel;
}
use of cz.metacentrum.perun.webgui.model.Resource in project perun by CESNET.
the class MemberSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(member.getUser().getFullNameWithTitles().trim()) + ": Settings");
// CONTENT WIDGET
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// MENU
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
menu.addWidget(UiElements.getRefreshButton(this));
// callbacks
final GetAttributesV2 callback = new GetAttributesV2(true);
if (!session.isVoAdmin(member.getVoId()) && !session.isGroupAdmin(groupId)) {
callback.setCheckable(false);
}
// member & user attrs
callback.getMemberAttributes(member.getId(), 1);
final CellTable<Attribute> table = callback.getEmptyTable();
// others callbacks
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
// work with user
ids.put("workWithUserAttributes", 1);
if (groupId != 0)
ids.put("group", groupId);
final GetResourceRequiredAttributesV2 resourceRequired = new GetResourceRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(callback));
final GetRequiredAttributes required = new GetRequiredAttributes(ids, JsonCallbackEvents.passDataToAnotherCallback(callback));
if (lastSelectedFilterIndex == 1 || lastSelectedResourceId == 0) {
// load required by default
required.retrieveData();
}
// listbox with resources
final ListBoxWithObjects<Resource> listbox = new ListBoxWithObjects<Resource>();
// listbox for filtering attributes callbacks
final ListBox filter = new ListBox();
filter.addItem("All filled attributes");
filter.addItem("Required");
filter.addItem("Resource required");
// required as default
filter.setSelectedIndex(lastSelectedFilterIndex);
// change table on selection one of the listboxs
final ChangeHandler changehandler = new ChangeHandler() {
public void onChange(ChangeEvent event) {
// if resource selected
if (listbox.getSelectedIndex() > 0) {
// if all attributes
if (filter.getSelectedIndex() == 0) {
callback.clearTable();
// with user
callback.getMemberAttributes(member.getId(), 1);
callback.retrieveData();
callback.getMemberResourceAttributes(member.getId(), listbox.getSelectedObject().getId());
callback.retrieveData();
callback.getUserFacilityAttributes(listbox.getSelectedObject().getFacilityId(), member.getUser().getId());
callback.retrieveData();
if (groupId != 0) {
callback.getMemberGroupAttributes(member.getId(), groupId);
callback.retrieveData();
}
// if required attributes
} else if (filter.getSelectedIndex() == 1) {
callback.clearTable();
ids.clear();
UiElements.generateInfo("Not valid option", "Skipping to \"Resource required\" option.");
filter.setSelectedIndex(2);
lastSelectedFilterIndex = 2;
ids.put("member", member.getId());
ids.put("resource", listbox.getSelectedObject().getId());
if (groupId != 0)
ids.put("group", groupId);
ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
ids.put("workWithUserAttributes", 1);
resourceRequired.retrieveData();
// if resource required
} else if (filter.getSelectedIndex() == 2) {
callback.clearTable();
ids.clear();
ids.put("member", member.getId());
ids.put("resource", listbox.getSelectedObject().getId());
if (groupId != 0)
ids.put("group", groupId);
ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
ids.put("workWithUserAttributes", 1);
resourceRequired.retrieveData();
}
// if no resource selected
} else {
// if all attributes
if (filter.getSelectedIndex() == 0) {
callback.clearTable();
callback.getMemberAttributes(member.getId(), 1);
callback.retrieveData();
if (groupId != 0) {
callback.getMemberGroupAttributes(member.getId(), groupId);
callback.retrieveData();
}
// if required attributes
} else if (filter.getSelectedIndex() == 1) {
callback.clearTable();
ids.clear();
ids.put("member", member.getId());
ids.put("workWithUserAttributes", 1);
if (groupId != 0)
ids.put("group", groupId);
required.retrieveData();
// if resource required
} else if (filter.getSelectedIndex() == 2) {
callback.clearTable();
((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
UiElements.generateInfo("Not valid option", "You must select resource first.");
}
}
}
};
ChangeHandler resourceChangeHandler = new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (listbox.getSelectedIndex() > 0) {
// if resource selected
// load resource-required (by default)
filter.setSelectedIndex(2);
lastSelectedFilterIndex = 2;
} else {
// else load required by default
filter.setSelectedIndex(1);
lastSelectedFilterIndex = 1;
}
if (listbox.getSelectedObject() != null) {
lastSelectedResourceId = listbox.getSelectedObject().getId();
} else {
lastSelectedResourceId = 0;
}
changehandler.onChange(event);
}
};
ChangeHandler filterChangeHandler = new ChangeHandler() {
public void onChange(ChangeEvent event) {
// if required and resource selected
if (filter.getSelectedIndex() == 1 && listbox.getSelectedIndex() > 0) {
// cance resource selection
listbox.setSelectedIndex(0);
lastSelectedResourceId = 0;
}
lastSelectedFilterIndex = filter.getSelectedIndex();
changehandler.onChange(event);
}
};
// refresh table on listbox change
listbox.addChangeHandler(resourceChangeHandler);
filter.addChangeHandler(filterChangeHandler);
// fill listbox with member's resources
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
listbox.clear();
ArrayList<Resource> res = JsonUtils.jsoAsList(jso);
res = new TableSorter<Resource>().sortByName(res);
if (res != null && !res.isEmpty()) {
listbox.addNotSelectedOption();
} else {
listbox.addItem("No resource available");
}
for (int i = 0; i < res.size(); i++) {
listbox.addItem(res.get(i));
// select last selected
if (res.get(i).getId() == lastSelectedResourceId) {
listbox.setSelected(res.get(i), true);
}
}
if (lastSelectedFilterIndex != 1 && lastSelectedResourceId != 0) {
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), filter);
}
}
public void onLoadingStart() {
listbox.clear();
listbox.addItem("Loading...");
}
public void onError(PerunError error) {
listbox.clear();
listbox.addItem("Error while loading");
}
};
// get member resources
GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, events);
res.retrieveData();
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
// save changes in attributes
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
if (!session.isVoAdmin(member.getVoId()) && !session.isGroupAdmin(groupId))
saveChangesButton.setEnabled(false);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
// if resource selected
if (listbox.getSelectedIndex() > 0) {
// if all attributes
SetAttributes request;
if (filter.getSelectedIndex() == 0) {
request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
// with user
callback.getMemberAttributes(member.getId(), 1);
callback.retrieveData();
callback.getMemberResourceAttributes(member.getId(), listbox.getSelectedObject().getId());
callback.retrieveData();
callback.getUserFacilityAttributes(listbox.getSelectedObject().getFacilityId(), member.getUser().getId());
callback.retrieveData();
if (groupId != 0) {
callback.getMemberGroupAttributes(member.getId(), groupId);
callback.retrieveData();
}
}
}));
} else {
// if required or resource-required
request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
ids.clear();
ids.put("member", member.getId());
ids.put("resource", listbox.getSelectedObject().getId());
if (groupId != 0)
ids.put("group", groupId);
ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
ids.put("workWithUserAttributes", 1);
resourceRequired.retrieveData();
}
}));
}
// make setAttributesCall
ids.clear();
ids.put("member", member.getId());
ids.put("resource", listbox.getSelectedObject().getId());
ids.put("facility", listbox.getSelectedObject().getFacilityId());
ids.put("user", member.getUserId());
if (groupId != 0)
ids.put("group", groupId);
request.setAttributes(ids, callback.getTableSelectedList());
} else {
// if resource not selected
SetAttributes request;
if (filter.getSelectedIndex() == 1) {
// if required attr option - refresh different callback
request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
required.retrieveData();
}
}));
} else {
request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
callback.getMemberAttributes(memberId, 1);
callback.retrieveData();
if (groupId != 0) {
callback.getMemberGroupAttributes(memberId, groupId);
callback.retrieveData();
}
}
}));
}
// make setAttributes call
ids.clear();
ids.put("member", member.getId());
if (groupId != 0)
ids.put("group", groupId);
ids.put("workWithUserAttributes", 1);
request.setAttributes(ids, callback.getTableSelectedList());
}
}
}
});
menu.addWidget(saveChangesButton);
// buttons
CustomButton setNewMemberAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
ids.put("user", member.getUser().getId());
if (groupId != 0)
ids.put("group", groupId);
if (listbox.getSelectedIndex() > 0) {
ids.put("resource", listbox.getSelectedObject().getId());
ids.put("facility", listbox.getSelectedObject().getFacilityId());
}
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids), true);
}
});
if (!session.isVoAdmin(member.getVoId()) && !session.isGroupAdmin(groupId))
setNewMemberAttributeButton.setEnabled(false);
menu.addWidget(setNewMemberAttributeButton);
// REMOVE ATTRIBUTES BUTTON
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// if selected
if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
// if resource selected
if (listbox.getSelectedIndex() > 0) {
// if all attributes
RemoveAttributes request;
if (filter.getSelectedIndex() == 0) {
request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
// with user
callback.getMemberAttributes(member.getId(), 1);
callback.retrieveData();
callback.getMemberResourceAttributes(member.getId(), listbox.getSelectedObject().getId());
callback.retrieveData();
callback.getUserFacilityAttributes(listbox.getSelectedObject().getFacilityId(), member.getUser().getId());
callback.retrieveData();
if (groupId != 0) {
callback.getMemberGroupAttributes(member.getId(), groupId);
callback.retrieveData();
}
}
}));
} else {
// if required or resource-required
request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
ids.clear();
ids.put("member", member.getId());
ids.put("resource", listbox.getSelectedObject().getId());
if (groupId != 0)
ids.put("group", groupId);
ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
ids.put("workWithUserAttributes", 1);
resourceRequired.retrieveData();
}
}));
}
// make removeAttributesCall
ids.clear();
ids.put("member", member.getId());
ids.put("resource", listbox.getSelectedObject().getId());
ids.put("facility", listbox.getSelectedObject().getFacilityId());
ids.put("user", member.getUserId());
if (groupId != 0)
ids.put("group", groupId);
request.removeAttributes(ids, callback.getTableSelectedList());
} else {
// if resource not selected
RemoveAttributes request;
if (filter.getSelectedIndex() == 1) {
// if required attr option - refresh different callback
request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
required.retrieveData();
}
}));
} else {
request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
callback.getMemberAttributes(memberId, 1);
callback.retrieveData();
if (groupId != 0) {
callback.getMemberGroupAttributes(memberId, groupId);
callback.retrieveData();
}
}
}));
}
// make removeAttributes call
ids.clear();
ids.put("member", member.getId());
if (groupId != 0)
ids.put("group", groupId);
ids.put("workWithUserAttributes", 1);
request.removeAttributes(ids, callback.getTableSelectedList());
}
}
}
});
removeButton.setEnabled(false);
if (session.isVoAdmin(member.getVoId()) || session.isGroupAdmin(groupId))
JsonUtils.addTableManagedButton(callback, table, removeButton);
menu.addWidget(removeButton);
// add listbox to menu
menu.addWidget(new HTML("<strong>Assigned resources: </strong>"));
menu.addWidget(listbox);
menu.addWidget(new HTML("<strong>Filter: </strong>"));
menu.addWidget(filter);
// ATTRIBUTES TABLE
vp.add(sp);
vp.setCellHeight(sp, "100%");
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations