Page:
<apex:page controller="QueueAssignController">
<apex:pagemessages />
<center> <apex:form >
<apex:pageBlock title="Queues">
<apex:outputLabel value="Select a Queue : " />
<apex:selectList size="1" value="{!queue}">
<apex:selectOptions value="{!QueueList}"></apex:selectOptions>
<apex:actionSupport event="onchange" action="{!UpdateList}" rerender="fm"/>
</apex:selectList>
</apex:pageBlock>
</apex:form>
<apex:form id="fm" >
<apex:outputPanel layout="block">
<apex:outPutLabel value="Search for: "/>
<apex:inputText value="{!whereClause}" style=" margin: 10px;"/>
<apex:commandButton action="{!filterAvailableOptions}" value="Find" rerender="availableUsersBlock"/>
</apex:outputPanel>
<apex:outputPanel id="multiselectPanel" layout="block" styleClass="duelingListBox">
<table class="layout">
<tbody>
<tr>
<td class="selectCell">
<apex:outputPanel layout="block" styleClass="selectTitle">
<apex:outputLabel value="Available Members" for="multiselectPanel:leftList" />
</apex:outputPanel>
<apex:selectList id="availableUsersBlock" value="{!selectedUserIds}" multiselect="true" size="15" style="width: 200px;">
<apex:selectOptions value="{!availableUsers}"/>
</apex:selectList>
</td>
<td class="buttonCell">
<apex:outputPanel layout="block" styleClass="text">Add</apex:outputPanel>
<apex:outputPanel layout="block" styleClass="text">
<apex:commandLink action="{!add}" rerender="availableUsersBlock, selectedUsersBlock" id="btnRight">
<apex:image value="/s.gif" alt="Add" styleClass="rightArrowIcon" title="Add" />
</apex:commandLink>
</apex:outputPanel>
<apex:outputPanel layout="block" styleClass="text">
<apex:commandLink action="{!remove}" rerender="availableUsersBlock, selectedUsersBlock" id="btnLeft">
<apex:image value="/s.gif" alt="Remove" styleClass="leftArrowIcon" title="Remove" />
</apex:commandLink>
<apex:outputPanel layout="block" styleClass="duelingText">Remove</apex:outputPanel>
</apex:outputPanel>
</td>
<td class="selectCell">
<apex:outputPanel layout="block" styleClass="selectTitle">
<apex:outputLabel value="Selected Members" for="multiselectPanel:rightList" />
</apex:outputPanel>
<apex:selectList id="selectedUsersBlock" value="{!removedUserIds}" multiselect="true" size="15" style="width: 200px;">
<apex:selectOptions value="{!selectedUsers}"/>
</apex:selectList>
</td>
</tr>
</tbody>
</table>
</apex:outputPanel>
<br/><br/> <apex:commandButton value="save" action="{!save}"/>
</apex:form></center>
</apex:page>
Controller:
public class QueueAssignController{
Public List<SelectOption> QueueList {get;set;}
public List<Group> GroupNameList {get;set;}
Public list<GroupMember> mlist {get;set;}
public String queue {get;set;}
public String queueid {get;set;}
public List<String> selectedUserIds { get; set; }
public List<String> removedUserIds { get; set; }
public String whereClause { get; set; }
private Map<Id, String> availableUsersMap;
private Map<Id, String> selectedUsersMap;
public QueueAssignController() {
initializeCollections();
GroupNameList = new List<Group>();
GroupNameList = [select g.Id, g.Name from Group g where Type = 'Queue' Order by Name Asc];
QueueList = new List<SelectOption>();
for(Group temp : GroupNameList)
{
queueid = temp.id;
QueueList.add(new SelectOption(temp.Id, temp.Name));
}
if(queue == null){
queue = queueid;
getUsers();
}
system.debug('QueueList++++++'+QueueList);
system.debug('queue ++++++'+queue );
}
public PageReference UpdateList() {
initializeCollections();
getUsers();
return null;
}
public void filterAvailableOptions() {
availableUsersMap = new Map<Id, String>();
selectedUserIds = new List<String>();
String likeClause = '%' + whereClause + '%';
for (User u : [SELECT id, name FROM User WHERE name like :likeClause AND Name!='Chatter Expert' AND IsActive = true order by Name Asc]) {
if (!selectedUsersMap.containsKey(u.Id)) {
availableUsersMap.put(u.Id, u.Name);
}
}
}
public void add() {
if (!selectedUserIds.isEmpty()) {
for (String userId : selectedUserIds) {
selectedUsersMap.put(userId, availableUsersMap.get(userId));
availableUsersMap.remove(userId);
}
}
}
public void remove() {
if (!removedUserIds.isEmpty()) {
for (String userId : removedUserIds) {
availableUsersMap.put(userId, selectedUsersMap.get(userId));
selectedUsersMap.remove(userId);
}
}
}
public List<SelectOption> getAvailableUsers() {
List<SelectOption> availableUsers = new List<SelectOption>();
for (Id userId : availableUsersMap.keySet()) {
availableUsers.add(new SelectOption(userId, availableUsersMap.get(userId)));
}
return availableUsers;
}
public List<SelectOption> getSelectedUsers() {
List<SelectOption> selectedUsers = new List<SelectOption>();
for (String userId : selectedUsersMap.keySet()) {
selectedUsers.add(new SelectOption(userId, selectedUsersMap.get(userId)));
}
return selectedUsers;
}
private void initializeCollections() {
selectedUserIds = new List<String>();
removedUserIds = new List<String>();
availableUsersMap = new Map<Id, String>();
selectedUsersMap = new Map<Id, String>();
}
private void getUsers() {
QueueSobject qs = [SELECT QueueId,SobjectType FROM QueueSobject where QueueId=:queue];
list<GroupMember> gms = [SELECT Group.Name,UserOrGroupId FROM GroupMember WHERE Group.Type = 'Queue' AND GroupId =:qs.QueueId];
system.debug(gms);
set<id> gids =new set<id>();
for(GroupMember g:gms){
gids.add(g.UserOrGroupId);
}
list<user> urs = [SELECT id, Name FROM User where IsActive = true AND id NOT IN:gids AND Name!='Chatter Expert' order by Name Asc];
system.debug(urs);
for(user u : urs){
availableUsersMap.put(u.Id, u.Name);
}
list<user> urss = [SELECT id, Name FROM User where IsActive = true AND id IN:gids AND Name!='Chatter Expert' order by Name Asc];
system.debug(urs);
for(user ur : urss){
selectedUsersMap.put(ur.Id, ur.Name);
}
}
public PageReference save(){
List<GroupMember> groups = new List<GroupMember>();
List<GroupMember> groupss = [select Id from GroupMember where Group.Type = 'Queue' and GroupId =:queue ];
if( !groupss.isEmpty() )
{
delete groupss;
}
if(selectedUsersMap.size() == 0){
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.Error, 'Please select a user to Add to Queue') );
}
else{
for(id ids:selectedUsersMap.keyset()){
// ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.INFO, 'Added user to Queue'+queue) );
insert new GroupMember( GroupId = queue , UserOrGroupId = ids);
}
}
return null;
}
}
You by chance don't still have the test class for this do you?
ReplyDelete