private void createGroup(final String groupname) { final StatusRecord sr = StatusHandler.createMessage( StatusHandler.getCreateGroupBusy(groupname), StatusRecord.STATUS_BUSY); RusselApi.createGroup( groupname, new ESBCallback<ESBPacket>() { @Override public void onFailure(Throwable caught) { sr.setMessage(StatusHandler.getCreateGroupError(groupname)); sr.setState(StatusRecord.STATUS_ERROR); StatusHandler.alterMessage(sr); } @Override public void onSuccess(ESBPacket esbPacket) { makeOption(groupname, "groupSelect"); fillGroupDetails(groupname); DOM.getElementById("groupSelect").setPropertyString("value", groupname); sr.setMessage(StatusHandler.getCreateGroupDone(groupname)); sr.setState(StatusRecord.STATUS_DONE); StatusHandler.alterMessage(sr); PageAssembler.closePopup("createGroupModal"); } }); }
private void fillGroupDetails(final String groupname) { DOM.getElementById("memberUserSelect").removeAllChildren(); DOM.getElementById("memberGroupSelect").removeAllChildren(); DOM.getElementById("userList").removeAllChildren(); DOM.getElementById("groupList").removeAllChildren(); RusselApi.getGroupMembers( groupname, new ESBCallback<ESBPacket>() { @Override public void onSuccess(ESBPacket esbPacket) { esbPacket = esbPacket.getObject("obj"); selectedUserMembers = esbPacket.getArray("users"); selectedGroupMembers = esbPacket.getArray("groups"); for (int i = 0; i < selectedUserMembers.size(); i++) makeOption(selectedUserMembers.get(i).isString().stringValue(), "memberUserSelect"); for (int i = 0; i < selectedGroupMembers.size(); i++) makeOption(selectedGroupMembers.get(i).isString().stringValue(), "memberGroupSelect"); RusselApi.getUsers( new ESBCallback<ESBPacket>() { @Override public void onSuccess(ESBPacket esbPacket) { JSONArray jsonArray = esbPacket.getArray("obj"); for (int i = 0; i < jsonArray.size(); i++) { String username = jsonArray.get(i).isString().stringValue(); if (!isMember(username, selectedUserMembers)) makeOption(username, "userList"); } } @Override public void onFailure(Throwable caught) {} }); RusselApi.getGroups( new ESBCallback<ESBPacket>() { @Override public void onSuccess(ESBPacket esbPacket) { JSONArray jsonArray = esbPacket.getArray("obj"); for (int i = 0; i < jsonArray.size(); i++) { String s = jsonArray.get(i).isString().stringValue(); if (!isMember(s, selectedGroupMembers) && groupname != s) makeOption(s, "groupList"); } } @Override public void onFailure(Throwable caught) {} }); } @Override public void onFailure(Throwable caught) {} }); }
private void deleteGroup(final String groupname) { final StatusRecord sr = StatusHandler.createMessage( StatusHandler.getDeleteGroupBusy(groupname), StatusRecord.STATUS_BUSY); RusselApi.removeGroup( groupname, new ESBCallback<ESBPacket>() { @Override public void onFailure(Throwable caught) { sr.setMessage(StatusHandler.getDeleteGroupError(groupname)); sr.setState(StatusRecord.STATUS_ERROR); StatusHandler.alterMessage(sr); } @Override public void onSuccess(ESBPacket esbPacket) { Element e = DOM.getElementById("groupSelect"); Element a = null; for (int i = 0; i < e.getChildCount(); i++) { Node n = e.getChild(i); if (n instanceof Element) { if (((Element) n).getPropertyString("value").equals(groupname)) a = (Element) n; } } if (a != null) { a.removeFromParent(); DOM.getElementById("memberUserSelect").removeAllChildren(); DOM.getElementById("memberGroupSelect").removeAllChildren(); DOM.getElementById("userList").removeAllChildren(); DOM.getElementById("groupList").removeAllChildren(); } sr.setMessage(StatusHandler.getDeleteGroupDone(groupname)); sr.setState(StatusRecord.STATUS_DONE); StatusHandler.alterMessage(sr); } }); }
/** display Renders the Utility screen using appropriate templates and sets up handlers */ public void display() { PageAssembler.ready(new HTML(Russel.htmlTemplates.getGroupManagementPanel().getText())); PageAssembler.buildContents(); DOM.getElementById("r-menuCollections").getParentElement().removeClassName("active"); DOM.getElementById("r-menuProjects").getParentElement().removeClassName("active"); DOM.getElementById("r-menuWorkspace").getParentElement().removeClassName("active"); PageAssembler.attachHandler( "groupPermission", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { Russel.screen.loadScreen( new PermissionScreen( PermissionScreen.TYPE_GROUP, DOM.getElementById("groupSelect").getPropertyString("value")), false); } }); PageAssembler.attachHandler( "groupUser", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { Russel.screen.loadScreen(new UserScreen(), true); } }); PageAssembler.attachHandler( "groupSelect", Event.ONCHANGE, new EventCallback() { @Override public void onEvent(Event event) { fillGroupDetails(DOM.getElementById("groupSelect").getPropertyString("value")); } }); RusselApi.getGroups( new ESBCallback<ESBPacket>() { @Override public void onSuccess(ESBPacket esbPacket) { JSONArray jsonArray = esbPacket.getArray("obj"); for (int i = 0; i < jsonArray.size(); i++) { makeOption(jsonArray.get(i).isString().stringValue(), "groupSelect"); } if (jsonArray.size() > 0) fillGroupDetails(jsonArray.get(0).isString().stringValue()); } @Override public void onFailure(Throwable caught) {} }); PageAssembler.attachHandler( "groupCreate", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { PageAssembler.openPopup("createGroupModal"); } }); PageAssembler.attachHandler( "groupDelete", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { deleteGroup(DOM.getElementById("groupSelect").getPropertyString("value")); } }); PageAssembler.attachHandler( "modalCreateCancel", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { DOM.getElementById("newGroupname").setPropertyString("value", ""); PageAssembler.closePopup("createGroupModal"); } }); PageAssembler.attachHandler( "modalCreateGroup", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { createGroup(DOM.getElementById("newGroupname").getPropertyString("value")); PageAssembler.closePopup("createGroupModal"); DOM.getElementById("newGroupname").setPropertyString("value", ""); } }); PageAssembler.attachHandler( "addMembers", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { Element e = DOM.getElementById("userList"); JsArray entities = (JsArray) e.getPropertyObject("selectedOptions"); for (int i = 0; i < entities.length(); i++) { final Element a = (Element) entities.get(i); RusselApi.addGroupMemberUser( a.getPropertyString("value"), DOM.getElementById("groupSelect").getPropertyString("value"), new ESBCallback<ESBPacket>() { @Override public void onFailure(Throwable caught) {} @Override public void onSuccess(ESBPacket esbPacket) { makeOption(a.getPropertyString("value"), "memberUserSelect"); } }); } int size = entities.length(); for (int i = 0; i < size; i++) ((Element) entities.get(0)).removeFromParent(); e = DOM.getElementById("groupList"); entities = (JsArray) e.getPropertyObject("selectedOptions"); for (int i = 0; i < entities.length(); i++) { final Element a = (Element) entities.get(i); RusselApi.addGroupMemberGroup( a.getPropertyString("value"), DOM.getElementById("groupSelect").getPropertyString("value"), new ESBCallback<ESBPacket>() { @Override public void onFailure(Throwable caught) {} @Override public void onSuccess(ESBPacket esbPacket) { makeOption(a.getPropertyString("value"), "memberGroupSelect"); } }); } size = entities.length(); for (int i = 0; i < size; i++) ((Element) entities.get(0)).removeFromParent(); } }); PageAssembler.attachHandler( "removeMembers", Event.ONCLICK, new EventCallback() { @Override public void onEvent(Event event) { Element e = DOM.getElementById("memberUserSelect"); JsArray entities = (JsArray) e.getPropertyObject("selectedOptions"); for (int i = 0; i < entities.length(); i++) { final Element a = (Element) entities.get(i); RusselApi.removeGroupMemberUser( a.getPropertyString("value"), DOM.getElementById("groupSelect").getPropertyString("value"), new ESBCallback<ESBPacket>() { @Override public void onFailure(Throwable caught) {} @Override public void onSuccess(ESBPacket esbPacket) { makeOption(a.getPropertyString("value"), "userList"); } }); } int size = entities.length(); for (int i = 0; i < size; i++) ((Element) entities.get(0)).removeFromParent(); e = DOM.getElementById("memberGroupSelect"); entities = (JsArray) e.getPropertyObject("selectedOptions"); for (int i = 0; i < entities.length(); i++) { final Element a = (Element) entities.get(i); RusselApi.removeGroupMemberGroup( a.getPropertyString("value"), DOM.getElementById("groupSelect").getPropertyString("value"), new ESBCallback<ESBPacket>() { @Override public void onFailure(Throwable caught) {} @Override public void onSuccess(ESBPacket esbPacket) { makeOption(a.getPropertyString("value"), "groupList"); } }); } size = entities.length(); for (int i = 0; i < size; i++) ((Element) entities.get(0)).removeFromParent(); } }); }