use of cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2 in project perun by CESNET.
the class GroupResourceRequiredAttributesTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings for " + Utils.getStrippedStringWithEllipsis(resource.getName()));
if (JsonUtils.isExtendedInfoVisible()) {
columnId = 3;
} else {
columnId = 2;
}
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
TabMenu menu = new TabMenu();
final Label facilityId = new Label();
JsonCallbackEvents events = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
Facility fac = (Facility) jso;
facilityId.setText(String.valueOf(fac.getId()));
}
};
GetFacility facility = new GetFacility(resourceId, events);
facility.retrieveData();
mainTab.add(new HTML("<hr size=\"2px\" />"));
// set attributes type to group_resource
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("group", groupId);
// gets all required group attributes for specified group and resource
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
reqAttrsTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
// get all required group_resource attributes too
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
final ListBoxWithObjects<RichMember> listBox = new ListBoxWithObjects<RichMember>();
listBox.setTitle(WidgetTranslation.INSTANCE.selectingMember());
// local event fills the listBox
JsonCallbackEvents localEvents = new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
mems = new TableSorter<RichMember>().sortByName(mems);
listBox.addNotSelectedOption();
for (int i = 0; i < mems.size(); i++) {
listBox.addItem(mems.get(i));
}
listBox.addAllOption();
}
};
final GetGroupRichMembers getGroupRichMembers = new GetGroupRichMembers(groupId, localEvents);
getGroupRichMembers.retrieveData();
reqAttrsTable.addStyleName("perun-table");
final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
sp.addStyleName("perun-tableScrollPanel");
// store for column with values
final Column<Attribute, ?> columnStore = reqAttrsTable.getColumn(columnId);
listBox.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
int selectedIndex = listBox.getSelectedIndex();
// no member selected
if (selectedIndex == 0) {
// offer just group and group resource attributes
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get groups attributes
ids.put("group", groupId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// get group_resource attributes
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
reqAttrs.sortTable();
// some member is selected
} else {
reqAttrs.clearTable();
ids.clear();
ids.put("resourceToGetServicesFrom", resourceId);
// get member, member-resource, user, user-facility attributes
ids.put("member", listBox.getSelectedObject().getId());
ids.put("resource", resourceId);
// to get user, user-facility attrs
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// all members are selected
if (selectedIndex == 1) {
// remove value column
reqAttrsTable.removeColumn(columnId);
// create own value column
// Value column
Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {
public Attribute getValue(Attribute attribute) {
attribute.setValueAsJso(null);
return attribute;
}
}, new FieldUpdater<Attribute, Attribute>() {
public void update(int index, Attribute object, Attribute value) {
object = value;
reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
}
});
// add to table
reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
} else {
// member selected
// return original column
reqAttrsTable.removeColumn(columnId);
reqAttrsTable.insertColumn(columnId, columnStore, "Value");
}
}
}
});
CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// send lists
ArrayList<Attribute> groupList = new ArrayList<Attribute>();
ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> memberList = new ArrayList<Attribute>();
ArrayList<Attribute> memberResourceList = new ArrayList<Attribute>();
ArrayList<Attribute> userList = new ArrayList<Attribute>();
ArrayList<Attribute> userFacilityList = new ArrayList<Attribute>();
SetAttributes request = new SetAttributes();
int selectedIndex = listBox.getSelectedIndex();
// if all selected
if (selectedIndex == 1) {
// TODO - USE NEW CONFIRM DESIGN
if (!Window.confirm("Same values for selected attributes will be set to all members in group." + "\n\nDo you want to continue ?")) {
return;
}
}
// get different attributes
for (Attribute attr : list) {
if (attr.getNamespace().contains("urn:perun:group:")) {
groupList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
groupResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member:")) {
memberList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:member_resource:")) {
memberResourceList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user:")) {
userList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:user_facility:")) {
userFacilityList.add(attr);
}
}
// if not empty, send request
if (!(groupList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
request.setAttributes(ids, groupList);
}
if (!(groupResourceList.isEmpty())) {
ids.clear();
ids.put("group", groupId);
ids.put("resource", resourceId);
request.setAttributes(ids, groupResourceList);
}
if (!(memberList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberList);
}
} else {
// for one member
ids.clear();
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberList);
}
}
if (!(memberResourceList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("resource", resourceId);
ids.put("member", (listBox.getObjectAt(i)).getId());
request.setAttributes(ids, memberResourceList);
}
} else {
// for one member
ids.clear();
ids.put("resource", resourceId);
ids.put("member", listBox.getSelectedObject().getId());
request.setAttributes(ids, memberResourceList);
}
}
if (!(userList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", (listBox.getObjectAt(i)).getUser().getId());
request.setAttributes(ids, userList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
request.setAttributes(ids, userList);
}
}
if (!(userFacilityList.isEmpty())) {
if (selectedIndex == 1) {
// for all members
for (int i = 0; i < listBox.getItemCount(); i++) {
ids.clear();
ids.put("user", listBox.getObjectAt(i).getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
} else {
// for one member
ids.clear();
ids.put("user", listBox.getSelectedObject().getUser().getId());
ids.put("facility", Integer.parseInt(facilityId.getText()));
request.setAttributes(ids, userFacilityList);
}
}
reqAttrs.clearTableSelectedSet();
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
saveChangesButton.setEnabled(false);
menu.addWidget(new HTML("<strong>Group members:</strong>"));
menu.addWidget(listBox);
// table content
session.getUiElements().resizePerunTable(sp, 350, this);
mainTab.add(menu);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
mainTab.setCellHeight(menu, "30px");
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2 in project perun by CESNET.
the class GroupsResourceRequiredAttributesTabItem method draw.
public Widget draw() {
if (groups == null || groups.get(0) == null) {
Window.alert("No groups in list.");
}
if (JsonUtils.isExtendedInfoVisible()) {
columnId = 3;
} else {
columnId = 2;
}
final VerticalPanel mainTab = new VerticalPanel();
mainTab.setSize("100%", "100%");
TabMenu menu = new TabMenu();
mainTab.add(new HTML("<hr size=\"2px\" />"));
// set attributes type to group_resource
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resourceToGetServicesFrom", resourceId);
ids.put("group", groups.get(0).getId());
// gets all required group attributes for specified group and resource
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
// remove value column
reqAttrsTable.removeColumn(columnId);
// create own value column
Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {
public Attribute getValue(Attribute attribute) {
// set empty value
attribute.setValueAsJso(null);
return attribute;
}
}, new FieldUpdater<Attribute, Attribute>() {
public void update(int index, Attribute object, Attribute value) {
object = value;
reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
}
});
// add to table
reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
// get all required group_resource attributes too
ids.put("resource", resourceId);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
reqAttrsTable.addStyleName("perun-table");
final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
sp.addStyleName("perun-tableScrollPanel");
CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
ArrayList<Attribute> groupList = new ArrayList<Attribute>();
ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
SetAttributes request = new SetAttributes();
// TODO - use new confirm dialog
if (!Window.confirm("Same values for selected attributes will be set to all groups you are about to assign." + "\n\nDo you want to continue ?")) {
return;
}
// get different attributes
for (Attribute attr : list) {
if (attr.getNamespace().contains("urn:perun:group:")) {
groupList.add(attr);
} else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
groupResourceList.add(attr);
}
}
if (!(groupList.isEmpty())) {
ids.clear();
for (int i = 0; i < groups.size(); i++) {
ids.put("group", groups.get(i).getId());
request.setAttributes(ids, groupList);
}
}
if (!(groupResourceList.isEmpty())) {
ids.clear();
ids.put("resource", resourceId);
for (int i = 0; i < groups.size(); i++) {
ids.put("group", groups.get(i).getId());
request.setAttributes(ids, groupResourceList);
}
}
reqAttrs.clearTableSelectedSet();
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
if (!session.isGroupAdmin() && !session.isVoAdmin())
saveChangesButton.setEnabled(false);
// table content
session.getUiElements().resizePerunTable(sp, 350, this);
mainTab.add(menu);
mainTab.add(sp);
mainTab.setCellHeight(sp, "100%");
mainTab.setCellHeight(menu, "30px");
this.contentWidget.setWidget(mainTab);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2 in project perun by CESNET.
the class GroupSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings");
// Main panel
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final TabMenu menu = new TabMenu();
// Adds menu to the main panel
vp.add(menu);
vp.setCellHeight(menu, "30px");
// IDS
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("group", groupId);
// define GET ATTRIBUTES callback
final GetAttributesV2 jsonCallback = new GetAttributesV2(true);
jsonCallback.setIds(ids);
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
jsonCallback.setCheckable(false);
final CellTable<Attribute> table = jsonCallback.getEmptyTable();
table.setWidth("100%");
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
vp.add(sp);
// define GET RES. REQ ATTRIBUTES callback
final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(null, JsonCallbackEvents.passDataToAnotherCallback(jsonCallback));
// GROUP RESOURCES LISTBOX
final ListBoxWithObjects<Resource> resourceDropDown = new ListBoxWithObjects<Resource>();
resourceDropDown.setTitle("By selecting a resource you will switch to either group-resource or member-resource setting (you must pick member too)");
// fill table with group attributes on page load
if (lastSelectedMemberId == 0 && lastSelectedResourceId == 0) {
jsonCallback.retrieveData();
} else {
// load attrs by listbox selection after calls are done
Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
// load proper table if something was selected
if (resCallDone && memCallDone) {
// trigger change event
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), resourceDropDown);
return false;
}
return true;
}
}, 200);
}
// fill resources listbox
if (resources == null) {
// get assigned resources
GetAssignedResources resources = new GetAssignedResources(groupId, PerunEntity.GROUP, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<Resource> resources = JsonUtils.jsoAsList(jso);
resourceDropDown.clear();
if (resources != null && !resources.isEmpty()) {
resources = new TableSorter<Resource>().sortByName(resources);
resourceDropDown.addNotSelectedOption();
for (int i = 0; i < resources.size(); i++) {
resourceDropDown.addItem(resources.get(i));
if (lastSelectedResourceId == resources.get(i).getId()) {
resourceDropDown.setSelected(resources.get(i), true);
}
}
} else {
resourceDropDown.addItem("No resources available");
}
resCallDone = true;
}
public void onError(PerunError error) {
resourceDropDown.clear();
resourceDropDown.addItem("Error while loading");
resCallDone = true;
}
public void onLoadingStart() {
resCallDone = false;
resourceDropDown.clear();
resourceDropDown.addItem("Loading...");
}
});
resources.retrieveData();
} else {
// use predefined resources
resourceDropDown.addNotSelectedOption();
resources = new TableSorter<Resource>().sortByName(resources);
resourceDropDown.addAllItems(resources);
}
// GROUP MEMBERS LISTBOX
final ListBoxWithObjects<RichMember> membersDropDown = new ListBoxWithObjects<RichMember>();
membersDropDown.setTitle("By selecting a member you will switch to either member or member-resource settings (you must pick resource too)");
// fill members listbox
GetGroupRichMembers members = new GetGroupRichMembers(groupId, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
membersDropDown.clear();
if (mems != null && !mems.isEmpty()) {
mems = new TableSorter<RichMember>().sortByName(mems);
membersDropDown.addNotSelectedOption();
for (int i = 0; i < mems.size(); i++) {
membersDropDown.addItem(mems.get(i));
if (mems.get(i).getId() == lastSelectedMemberId) {
membersDropDown.setSelected(mems.get(i), true);
}
}
} else {
membersDropDown.addItem("No members available");
}
memCallDone = true;
}
public void onError(PerunError error) {
membersDropDown.clear();
membersDropDown.addItem("Error while loading");
memCallDone = true;
}
public void onLoadingStart() {
memCallDone = false;
membersDropDown.clear();
membersDropDown.addItem("Loading...");
}
});
members.retrieveData();
// CHECKBOXES "FOR ALL MEMBERS"
final CheckBox memChb = new CheckBox();
memChb.setText("To all members");
memChb.setVisible(false);
memChb.setTitle("Uses this setting for all members of this group.");
memChb.setValue(false);
// SAVE CHANGES BUTTON
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
saveChangesButton.setEnabled(false);
// click handler to save group and member-user attributes
final ClickHandler saveAttrsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// refresh table and disable button a event for GetAttributes
final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(saveChangesButton, JsonCallbackEvents.refreshTableEvents(jsonCallback));
if (memChb.getValue() == true) {
// to all members selected
UiElements.generateInfo(WidgetTranslation.INSTANCE.saveConfirmTitle(), "Same value(s) for selected attribute(s) will be set to ALL members of group.", new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<RichMember> memList = membersDropDown.getAllObjects();
for (int i = 0; i < memList.size(); i++) {
SetAttributes request = new SetAttributes();
if (i == memList.size() - 1) {
request.setEvents(events);
} else {
request.setEvents(JsonCallbackEvents.disableButtonEvents(saveChangesButton));
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", memList.get(i).getId());
ids.put("workWithUserAttributes", 1);
request.setAttributes(ids, list);
}
}
});
} else {
// just one group / memeber
SetAttributes request = new SetAttributes(events);
request.setAttributes(jsonCallback.getIds(), list);
}
}
}
};
// click handler to save required attributes
final ClickHandler saveReqAttrsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
// check if not empty
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// refresh table and disable button a event for GetResourceRequiredAttributes
final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
jsonCallback.clearTable();
// set back resourceToGetServicesFrom
Map<String, Integer> ids = reqAttrs.getIds();
if (ids.containsKey("resource")) {
ids.put("resourceToGetServicesFrom", ids.get("resource"));
}
if (ids.containsKey("user")) {
ids.put("workWithUserAttributes", 1);
}
if (ids.containsKey("resource") && ids.containsKey("group")) {
ids.put("workWithGroupAttributes", 1);
}
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
}
});
final SetAttributes request = new SetAttributes();
if (memChb.getValue() == true) {
// to all members selected
UiElements.generateInfo(WidgetTranslation.INSTANCE.saveConfirmTitle(), "Same value(s) for selected attribute(s) will be set to ALL members of group.", new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<RichMember> memList = membersDropDown.getAllObjects();
for (int i = 0; i < memList.size(); i++) {
if (i == 0) {
events.onLoadingStart();
}
// trigger disable button if first
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", memList.get(i).getId());
ids.put("user", memList.get(i).getUserId());
ids.put("resource", resourceDropDown.getSelectedObject().getId());
ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
if (i == memList.size() - 1) {
request.setEvents(events);
}
// set events to last to get refresh and button enable
request.setAttributes(ids, list);
}
}
});
} else {
// group or member
// disable button events
request.setEvents(events);
request.setAttributes(reqAttrs.getIds(), list);
}
}
}
};
// REMOVE BUTTON
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
removeButton.setEnabled(false);
// click handler to remove group and member-user attributes
final ClickHandler removeAttrsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// refresh table and disable button a event for GetAttributes
final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(jsonCallback));
final RemoveAttributes request = new RemoveAttributes();
if (memChb.getValue() == true) {
// to all members selected
UiElements.generateInfo(WidgetTranslation.INSTANCE.deleteConfirmTitle(), "Selected attribute(s) will be removed from ALL members of group.", new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<RichMember> memList = membersDropDown.getAllObjects();
for (int i = 0; i < memList.size(); i++) {
// trigger disable button if first
if (i == 0) {
events.onLoadingStart();
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", memList.get(i).getId());
ids.put("workWithUserAttributes", 1);
// set events to last to get refresh and button enable
if (i == memList.size() - 1) {
request.setEvents(events);
}
request.removeAttributes(ids, list);
}
}
});
} else {
// just one group / memeber
// disable button events
request.setEvents(events);
request.removeAttributes(jsonCallback.getIds(), list);
}
}
}
};
// click handler to remove ResourceRequiredAttributes
final ClickHandler removeReqAttrsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
// refresh table and disable button a event for GetAttributes
final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
jsonCallback.clearTable();
// set back resourceToGetServicesFrom
Map<String, Integer> ids = reqAttrs.getIds();
if (ids.containsKey("resource")) {
ids.put("resourceToGetServicesFrom", ids.get("resource"));
}
if (ids.containsKey("user")) {
ids.put("workWithUserAttributes", 1);
}
if (ids.containsKey("resource") && ids.containsKey("group")) {
ids.put("workWithGroupAttributes", 1);
}
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
}
});
final RemoveAttributes request = new RemoveAttributes();
if (memChb.getValue() == true) {
// to all members selected
UiElements.generateInfo(WidgetTranslation.INSTANCE.deleteConfirmTitle(), "Selected attribute(s) will be removed from ALL members of group.", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ArrayList<RichMember> memList = membersDropDown.getAllObjects();
for (int i = 0; i < memList.size(); i++) {
// trigger disable button if first
if (i == 0) {
events.onLoadingStart();
}
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", memList.get(i).getId());
ids.put("user", memList.get(i).getUserId());
ids.put("resource", resourceDropDown.getSelectedObject().getId());
ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
// set events to last to get refresh and button enable
if (i == memList.size() - 1) {
request.setEvents(events);
}
request.removeAttributes(ids, list);
}
}
});
} else {
// just one group / member
// disable button events
request.setEvents(events);
request.removeAttributes(reqAttrs.getIds(), list);
}
}
}
};
// SET NEW ATTR BUTTON
final CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes());
if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
setNewAttributeButton.setEnabled(false);
// click handler
setNewAttributeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ids.clear();
if (resourceDropDown.getSelectedIndex() > 0) {
if (membersDropDown.getSelectedIndex() > 0) {
ids.put("member", membersDropDown.getSelectedObject().getId());
ids.put("user", membersDropDown.getSelectedObject().getUserId());
ids.put("resource", resourceDropDown.getSelectedObject().getId());
ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
} else {
ids.put("resource", resourceDropDown.getSelectedObject().getId());
ids.put("group", groupId);
ids.put("workWithGroupAttributes", 1);
}
} else {
if (membersDropDown.getSelectedIndex() > 0) {
ids.put("member", membersDropDown.getSelectedObject().getId());
ids.put("user", membersDropDown.getSelectedObject().getUserId());
} else {
ids.put("group", groupId);
}
}
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true);
}
});
// ClickHandlersRegistration - save onClicks for GetAttributes
final ArrayList<HandlerRegistration> clickHandlers = new ArrayList<HandlerRegistration>();
clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
// DEFINE CHANGE HANDLER FOR ALL DROP DOWNS
ChangeHandler changeHandler = new ChangeHandler() {
public void onChange(ChangeEvent event) {
int resIndex = resourceDropDown.getSelectedIndex();
int memIndex = membersDropDown.getSelectedIndex();
// no resource or member selected
if (resIndex == 0 && memIndex == 0) {
lastSelectedMemberId = 0;
lastSelectedResourceId = 0;
memChb.setValue(false);
memChb.setVisible(false);
jsonCallback.clearTable();
ids.clear();
ids.put("group", groupId);
jsonCallback.setIds(ids);
jsonCallback.retrieveData();
for (HandlerRegistration handler : clickHandlers) {
if (handler != null) {
handler.removeHandler();
}
}
clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
}
// no resource but member selected
if (resIndex == 0 && memIndex > 0) {
lastSelectedMemberId = membersDropDown.getSelectedObject().getId();
lastSelectedResourceId = 0;
memChb.setValue(false);
memChb.setVisible(true);
jsonCallback.clearTable();
ids.clear();
ids.put("member", membersDropDown.getSelectedObject().getId());
ids.put("workWithUserAttributes", 1);
jsonCallback.setIds(ids);
jsonCallback.retrieveData();
for (HandlerRegistration handler : clickHandlers) {
if (handler != null) {
handler.removeHandler();
}
}
clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
}
// resource and no member selected
if (resIndex > 0 && memIndex == 0) {
lastSelectedMemberId = 0;
lastSelectedResourceId = resourceDropDown.getSelectedObject().getId();
memChb.setValue(false);
memChb.setVisible(false);
jsonCallback.clearTable();
ids.clear();
ids.put("group", groupId);
ids.put("resource", resourceDropDown.getSelectedObject().getId());
ids.put("resourceToGetServicesFrom", ids.get("resource"));
ids.put("workWithGroupAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// set ids back to make saveChanges work
ids.remove("resourceToGetServicesFrom");
reqAttrs.setIds(ids);
for (HandlerRegistration handler : clickHandlers) {
if (handler != null) {
handler.removeHandler();
}
}
clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler));
clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler));
}
// resource and member selected
if (resIndex > 0 && memIndex > 0) {
lastSelectedMemberId = membersDropDown.getSelectedObject().getId();
lastSelectedResourceId = resourceDropDown.getSelectedObject().getId();
memChb.setValue(false);
memChb.setVisible(true);
jsonCallback.clearTable();
ids.clear();
ids.put("resource", resourceDropDown.getSelectedObject().getId());
ids.put("resourceToGetServicesFrom", ids.get("resource"));
ids.put("member", membersDropDown.getSelectedObject().getId());
ids.put("workWithUserAttributes", 1);
reqAttrs.setIds(ids);
reqAttrs.retrieveData();
// set ids back to make saveChanges work
ids.clear();
ids.put("member", membersDropDown.getSelectedObject().getId());
ids.put("user", membersDropDown.getSelectedObject().getUser().getId());
ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
ids.put("resource", resourceDropDown.getSelectedObject().getId());
reqAttrs.setIds(ids);
for (HandlerRegistration handler : clickHandlers) {
if (handler != null) {
handler.removeHandler();
}
}
clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler));
clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler));
}
}
};
// ADD CHANGE HANDLERS TO DROP-DOWN MENUS
resourceDropDown.addChangeHandler(changeHandler);
membersDropDown.addChangeHandler(changeHandler);
// PUT ELEMENTS IN MENU
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
//menu.addWidget(resChb);
menu.addWidget(memChb);
menu.addWidget(setNewAttributeButton);
menu.addWidget(removeButton);
menu.addWidget(new HTML("<strong>Resources:</strong>"));
menu.addWidget(resourceDropDown);
menu.addWidget(new HTML("<strong>Members:</strong>"));
menu.addWidget(membersDropDown);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations