getGroups
getClassMembersNotGrouped
addGroup
removeGroup
changeGroupName
= maxNumberOfGroups) {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
return false;
}
*/
// increment total number of group panels added
totalGroupsAdded++;
// push new group panel and its dataprovider into their respective collections
panels.addItem(newPanel);
panelLearnerDataProviders.addItem(newLearnersCollection);
// set new panelRemove button attributes
newPanelRemoveButton.label = "-";
newPanelRemoveButton.id = "panelRemove_btn";
newPanelRemoveButton.addEventListener(MouseEvent.CLICK, removePanelHandler);
// set spacer attributes
horizontalSpacer.percentWidth = 100;
// set new controlbar attributes
newControlBar.percentWidth = 100;
newControlBar.height = 40;
// add the control bar's components
newControlBar.addChild(horizontalSpacer);
newControlBar.addChild(newPanelRemoveButton);
// disactivate if deletion is not allowed
if(usedForBranching || !mayDelete || viewMode) {
newPanelRemoveButton.enabled = false;
}
// set new panel attributes
newPanel.width = learnerGroups_tile.width / 2 - 15;
newPanel.height = learnerGroups_tile.height / 2 - 6;
newPanel.addEventListener(MouseEvent.CLICK, changePanelTitleHandler);
if(id == null){
newPanel.id = "group" + String(totalGroupsAdded) + "Learners_pnl";
}
else {
newPanel.id = id;
}
if(title == null){
newPanel.title = "Group " + String(totalGroupsAdded);
}
else {
newPanel.title = title;
}
// set new column attributes
newDataGridColumn.headerText = languageXML.language.entry.(@key=="label.grouping.learners").name;
newDataGridColumn.dataField = "displayName";
// set new datagrid attributes
newDataGrid.columns = [newDataGridColumn];
newDataGrid.percentWidth = 100;
newDataGrid.percentHeight = 100;
newDataGrid.allowMultipleSelection = true;
newDataGrid.addEventListener(DragEvent.DRAG_DROP, dragDropHandler);
newDataGrid.dataProvider = newLearnersCollection;
// set dragging properties depending
newDataGrid.dragEnabled = mayDelete;
newDataGrid.dragMoveEnabled= mayDelete;
newDataGrid.allowDragSelection = mayDelete;
newDataGrid.dropEnabled = true;
// add elements to the panel
newPanel.addChild(newDataGrid);
newPanel.addChild(newControlBar);
// add the panel to the tile
learnerGroups_tile.addChild(newPanel);
return true;
}
// removes a given group panel
private function removeGroupPanel(groupId:int):Boolean{
// there must be at least one panel
if(panels.length != 0) {
// the given panel must be in the collection
if(groupId < panels.length && groupId >= 0) {
// get panel information
var lastGroupLearners:ArrayCollection = panelLearnerDataProviders[groupId];
var lastGroupPanel:Panel = panels[groupId];
// get learners to move back to initial grid
var selectedNamesString:String = "";
// format the learner ids as needed serverside
for(var i:int = 0; i < lastGroupLearners.length; i++){
selectedNamesString += lastGroupLearners[i].id;
if(i < lastGroupLearners.length - 1)
{
selectedNamesString += ",";
}
}
// add learners back to server
removeMembersService.request.groupID = lastGroupPanel.id;
removeMembersService.request.members = selectedNamesString;
removeMembersService.send();
// add learners back to main datagrid
for(var i:int = 0; i < lastGroupLearners.length; i++) {
intialLearners.addItem(lastGroupLearners[i]);
}
// remove group from tile
learnerGroups_tile.removeChild(lastGroupPanel);
// remove panel and its dataprovider from their respective collections
panelLearnerDataProviders.removeItemAt(groupId);
panels.removeItemAt(groupId);
return true;
}
}
return false;
}
// click handler for changing a panel's title
private function changePanelTitleHandler(e:Event):void {
if(panels.contains(e.currentTarget) && e.target is UITextField && e.target.text == e.currentTarget.title){
createChangePanelTitleWindow(Panel(e.currentTarget));
}
}
// method for creating new panel title change popups
private function createChangePanelTitleWindow(clickedPanel:Panel):void{
var popup:ChangePanelTitlePopUp = ChangePanelTitlePopUp(PopUpManager.createPopUp(this, ChangePanelTitlePopUp, true));
popup.init(application.width / 2 - popup.width / 2, application.height / 2 - popup.height / 2, languageXML.language.entry.(@key=="label.grouping.popup.change.group.name").name, clickedPanel, languageXML);
}
// call the change panel name service
public function changePanelTitle(panel:Panel, title:String):void {
changeGroupNameService.request.groupID = panel.id;
changeGroupNameService.request.name = title;
changeGroupNameService.send();
}
// find a panel index from its groupID
private function findPanelIndex(groupID:int):int{
for(var i:int = 0; i < panels.length; i++) {
if(Panel(panels[i]).id == String(groupID)){
return i;
}
}
return -1;
}
// convert a string to a boolean
private function stringToBool(string:String):Boolean{
switch(string){
case "1":
case "true":
case "yes":
return true;
case "0":
case "false":
case "no":
return false;
default:
return Boolean(string);
}
}
// click handler for adding a panel
private function addPanelHandler(e:Event):void {
addGroupService.request.name = "Group " + String(totalGroupsAdded + 1);
addGroupService.send();
}
// click handler for removing a panel
private function removePanelHandler(event:Event):void {
if(panels.length != 0) {
lastRemoveEvent = event;
Alert.show(languageXML.language.entry.(@key=="label.grouping.popup.delete.group.message").name, languageXML.language.entry.(@key=="label.grouping.popup.delete.group").name, 3, this, deleteAlertClickHandler);
}
}
// click handler to confirm removing a panel
private function deleteAlertClickHandler(event:CloseEvent):void {
if (event.detail==Alert.YES){
removePanelHandlerComplete(lastRemoveEvent);
}
}
// handler to complete removing a panel
private function removePanelHandlerComplete(e:Event):void {
if(e.target.id == "panelRemove_btn" && panels.contains(e.target.parent.parent)){
removeGroupService.request.groupID = e.target.parent.parent.id;
removeGroupService.send();
}
else if(e.target == globalRemovePanel_btn){
removeGroupService.request.groupID = Panel(panels.getItemAt(panels.length-1)).id;
removeGroupService.send();
}
}
// click handler for the finish button
private function closeWindowHandler(e:MouseEvent):void{
ExternalInterface.call("closeWindow");
}
// handler to complete dragging users
private function dragDropHandler(e:DragEvent):void {
// if the drag and drop source and destination are not the same
if(e.dragInitiator != e.currentTarget){
// get selected items in datagrid
var selectedNames:Array = DataGrid(e.dragInitiator).selectedItems;
var selectedNamesString:String = "";
// format the learner ids as needed serverside
for(var i:int = 0; i < selectedNames.length; i++){
selectedNamesString += selectedNames[i].id;
if(i < selectedNames.length - 1)
{
selectedNamesString += ",";
}
}
// if the source is not the initial learners grid, remove members
if(DataGrid(e.dragInitiator).id != "mainDataGrid_dg") {
removeMembersService.request.groupID = Panel(e.dragInitiator.parent).id;
removeMembersService.request.members = selectedNamesString;
removeMembersService.send();
}
// if the destination is not the initial learners grid, add members
if(DataGrid(e.currentTarget).id != "mainDataGrid_dg") {
addMembersService.request.groupID = Panel(e.currentTarget.parent).id;
addMembersService.request.members = selectedNamesString;
addMembersService.send();
}
}
}
// -- httpservice handlers --
private function getGroupsSuccessHandler(e:ResultEvent):void {
var xmlResult:XMLListCollection = new XMLListCollection(XMLList(e.result).groups.group);
var amountGroupsAdded:int = 0;
// for each group returned, add a group panel and get its learners
for(var i:int = 0; i < xmlResult.length; i++){
addGroupPanel(xmlResult.getItemAt(i).id.toString(), xmlResult.getItemAt(i).name.toString());
getGroupMembersService.request.groupID = xmlResult.getItemAt(i).id.toString();
getGroupMembersService.send();
}
}
private function getGroupsFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function getMembersNotGroupedSuccessHandler(e:ResultEvent):void {
var xmlResult:XMLListCollection = new XMLListCollection(XMLList(e.result).users.user);
var groupID:int = XMLList(e.result).groupID.toString();
for(var i:int = 0; i < xmlResult.length; i++){
intialLearners.addItem({displayName: xmlResult.getItemAt(i).displayName.toString(), id: xmlResult.getItemAt(i).id.toString()});
}
}
private function getMembersNotGroupedFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function getGroupMembersSuccessHandler(e:ResultEvent):void {
var xmlResult:XMLListCollection = new XMLListCollection(XMLList(e.result).users.user);
var groupID:int = XMLList(e.result).groupID.toString();
var indexToUse:int = findPanelIndex(groupID);
for(var i:int = 0; i < xmlResult.length; i++){
panelLearnerDataProviders[indexToUse].addItem({displayName: xmlResult.getItemAt(i).displayName.toString(), id: xmlResult.getItemAt(i).id.toString()});
}
}
private function getGroupMembersFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function addMembersSuccessHandler(e:ResultEvent):void {
// nothing to do here
}
private function addMembersFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function removeMembersSuccessHandler(e:ResultEvent):void {
// nothing to do here
}
private function removeMembersFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function addGroupSuccessHandler(e:ResultEvent):void {
addGroupPanel(XMLList(e.result).group.id.toString()), XMLList(e.result).group.name.toString();
}
private function addGroupFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function removeGroupSuccessHandler(e:ResultEvent):void {
var groupID:int = XMLList(e.result).group.id.toString();
var indexToUse:int = findPanelIndex(groupID);
removeGroupPanel(indexToUse);
}
private function removeGroupFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
private function changeGroupNameSuccessHandler(e:ResultEvent):void {
var groupID:int = XMLList(e.result).group.id.toString();
var groupName:String = XMLList(e.result).group.newName.toString();
var indexToUse:int = findPanelIndex(groupID);
Panel(panels.getItemAt(indexToUse)).title = groupName;
}
private function changeGroupNameFaultHandler(e:Event):void {
Alert.show(languageXML.language.entry.(@key=="error.title").name);
}
// -- getters and setters --
public function getLanguageXML():XML{
return languageXML;
}
]]>
../bin-debug/loading_small.swf