@Override
public void event(UserRequest ureq, Controller source, Event event) {
if(source == tableListParticipants) {
if(event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent tableEvent = (TableEvent)event;
//open window for choosen date to manage the enrolled users or manually add
if(tableEvent.getActionId().equals(DENListTableDataModel.CHANGE_ACTION)) {
selectedEvent = (KalendarEvent)listTableData.getObject(tableEvent.getRowId());
List<Identity> participants = denManager.getEventParticipants(selectedEvent);
participantsTableData = new DENParticipantsTableDataModel(participants);
tableManageParticipants = denManager.createParticipantsTable(ureq, getWindowControl(), getTranslator(), this, participantsTableData);
formManageParticipants = new DENManageParticipantsForm(ureq, getWindowControl());
formManageParticipants.addControllerListener(this);
participantsVC = new VelocityContainer("participants.manage", VELOCITY_ROOT + "/participants.html", getTranslator(), this);
SimpleText dateTitle = new SimpleText("dateTitle", translate("dates.table.subject") + ": " + selectedEvent.getSubject());
DateFormat df = new SimpleDateFormat();
SimpleText dateTimeframe = new SimpleText("dateTimeframe", translate("dates.table.date") + ": " + df.format(selectedEvent.getBegin()) + " - " + df.format(selectedEvent.getEnd()));
participantsVC.put("dateTitle", dateTitle);
participantsVC.put("dateTimeframe", dateTimeframe);
participantsVC.put("participantsTable", tableManageParticipants.getInitialComponent());
participantsVC.put("addParticipants", formManageParticipants.getInitialComponent());
CloseableModalController manageParticipantsModalCntrl = new CloseableModalController(getWindowControl(), "close", participantsVC, true, translate("dates.table.participant.manage"));
manageParticipantsModalCntrl.activate();
}
} else {
TableMultiSelectEvent tmse = (TableMultiSelectEvent)event;
BitSet selection = tmse.getSelection();
//delete all users from the selected dates
if(tmse.getAction().equals(DENListTableDataModel.DELETE_ACTION) && selection.cardinality() > 0) {
removed = denManager.getSelectedEventParticipants(dateList, selection);
dateList = denManager.deleteParticipants(ores, courseNode, denManager.getSelectedEventIDs(dateList, selection));
listTableData.setObjects(dateList);
//send notification mail
createRemovedNotificationMail(ureq, dateList.get(0).getSubject());
} else if(tmse.getAction().equals(DENListTableDataModel.MAIL_ACTION) && selection.cardinality() > 0) {
//send email to all users from the selected dates
List<Identity> participants = denManager.getSelectedEventParticipants(dateList, selection);
createParticipantsMail(ureq, participants);
} else if(selection.cardinality() == 0) {
getWindowControl().setWarning(translate("participants.message.empty"));
}
}
} else if(source == formManageParticipants && event == DENManageParticipantsForm.ADD_PARTICIPANTS) {
//open user search controller to manually add users in date
userSearchCntrl = new UserSearchController(ureq, getWindowControl(), true, true, true);
userSearchCntrl.addControllerListener(this);
userSearchCMC = new CloseableModalController(getWindowControl(), "close", userSearchCntrl.getInitialComponent());
userSearchCMC.activate();
} else if(source == userSearchCntrl) {
if(event == Event.CANCELLED_EVENT) {
userSearchCMC.deactivate();
} else {
List<Identity> toAdd = null;
added = new ArrayList<Identity>();
if (event instanceof SingleIdentityChosenEvent) {
SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
Identity choosenIdentity = singleEvent.getChosenIdentity();
toAdd = new ArrayList<Identity>();
toAdd.add(choosenIdentity);
} else if (event instanceof MultiIdentityChosenEvent) {
MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
toAdd = multiEvent.getChosenIdentities();
}
boolean showMessage = false;
if(toAdd != null && toAdd.size() > 0) {
for( Identity identity : toAdd ) {
status = denManager.doEnroll(identity, selectedEvent, ores, courseNode, true);
if(!status.isEnrolled() && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED))
showMessage = true;
else
added.add(identity);
}
if(showMessage)
getWindowControl().setWarning(translate("enrollment.warning.manual"));
refreshTables();
}
userSearchCMC.deactivate();
if(added.size() > 0) {
//write notification mail
createAddedNotificationMail(ureq, dateList.get(0).getSubject());
}
}
userSearchCntrl.dispose();
userSearchCntrl = null;
} else if(source == tableManageParticipants) {
if(event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent tableEvent = (TableEvent)event;
//delete single user from event
if(tableEvent.getActionId().equals(DENParticipantsTableDataModel.REMOVE_ACTION)) {
Identity identity = participantsTableData.getEntryAt(tableEvent.getRowId());
status = denManager.cancelEnroll(identity, selectedEvent, ores, courseNode);
if(!status.isCancelled()) showError();
//send notification mail
else {
removed.clear();
removed.add(identity);
createRemovedNotificationMail(ureq, dateList.get(0).getSubject());
}
refreshTables();
//write email to single user
} else if(tableEvent.getActionId().equals(DENParticipantsTableDataModel.MAIL_ACTION)) {
List<Identity> participants = new ArrayList<Identity>();
participants.add(participantsTableData.getEntryAt(tableEvent.getRowId()));
createParticipantsMail(ureq, participants);
}
}
} else if(source == addedNotificationCtr && event == Event.DONE_EVENT) {
if(addedNotificationCtr.getMailTemplate() != null) {