diff --git a/src/main/java/de/bps/course/nodes/den/DENManageParticipantsController.java b/src/main/java/de/bps/course/nodes/den/DENManageParticipantsController.java index 4f05951a328a54d9fd238f47aac480f51cae45ae..f0cfb7631a1b9f9be7b86911fcc158ed12f256cc 100644 --- a/src/main/java/de/bps/course/nodes/den/DENManageParticipantsController.java +++ b/src/main/java/de/bps/course/nodes/den/DENManageParticipantsController.java @@ -63,6 +63,9 @@ import de.bps.course.nodes.DENCourseNode; public class DENManageParticipantsController extends BasicController { + public static final String ADD_ACTION = "denAddParticipants"; + public static final String REMOVE_ACTION = "denRemoveParticipants"; + private DENCourseNode courseNode; private OLATResourceable ores; private DENStatus status; @@ -82,11 +85,10 @@ public class DENManageParticipantsController extends BasicController { private KalendarEvent selectedEvent; //mail notification - private MailNotificationEditController addedNotificationCtr, removedNotificationCtr; + private MailNotificationEditController notificationCtr; private ContactFormController contactCtr; private CloseableModalController notificationCmc; - private List<Identity> added = new ArrayList<Identity>(); - private List<Identity> removed = new ArrayList<Identity>(); + private List<Identity> selectedIds = new ArrayList<Identity>(); private CloseableModalController manageParticipantsModalCntrl; @@ -157,11 +159,11 @@ public class DENManageParticipantsController extends BasicController { 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); + selectedIds = 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()); + createNotificationMail(ureq, courseNode.getShortTitle(), REMOVE_ACTION); } 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); @@ -175,7 +177,7 @@ public class DENManageParticipantsController extends BasicController { userSearchCMC.deactivate(); } else { List<Identity> toAdd = null; - added = new ArrayList<Identity>(); + selectedIds = new ArrayList<Identity>(); if (event instanceof SingleIdentityChosenEvent) { SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event; Identity choosenIdentity = singleEvent.getChosenIdentity(); @@ -192,16 +194,16 @@ public class DENManageParticipantsController extends BasicController { if(!status.isEnrolled() && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED)) showMessage = true; else - added.add(identity); + selectedIds.add(identity); } if(showMessage) showWarning("enrollment.warning.manual"); refreshTables(); } userSearchCMC.deactivate(); - if(added.size() > 0) { + if(selectedIds.size() > 0) { //write notification mail - createAddedNotificationMail(ureq, dateList.get(0).getSubject()); + createNotificationMail(ureq, selectedEvent.getSubject(), ADD_ACTION); } } @@ -215,9 +217,9 @@ public class DENManageParticipantsController extends BasicController { if(!status.isCancelled()) showError(); //send notification mail else { - removed.clear(); - removed.add(identity); - createRemovedNotificationMail(ureq, dateList.get(0).getSubject()); + selectedIds.clear(); + selectedIds.add(identity); + createNotificationMail(ureq, selectedEvent.getSubject(), REMOVE_ACTION); } refreshTables(); //write email to single user @@ -227,40 +229,22 @@ public class DENManageParticipantsController extends BasicController { createParticipantsMail(ureq, participants); } } - } else if(source == addedNotificationCtr && event == Event.DONE_EVENT) { - if(addedNotificationCtr.getMailTemplate() != null) { + } else if(source == notificationCtr && event == Event.DONE_EVENT) { + if(notificationCtr.getMailTemplate() != null) { Identity sender = ureq.getIdentity(); MailerResult result = new MailerResult(); String metaId = UUID.randomUUID().toString().replace("-", ""); MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString()); - MailBundle[] bundles = mailManager.makeMailBundles(context, added, addedNotificationCtr.getMailTemplate(), sender, metaId, result); + MailBundle[] bundles = mailManager.makeMailBundles(context, selectedIds, notificationCtr.getMailTemplate(), sender, metaId, result); result.append(mailManager.sendMessage(bundles)); - if(addedNotificationCtr.getMailTemplate().getCpfrom()) { - MailBundle ccBundles = mailManager.makeMailBundle(context, sender, addedNotificationCtr.getMailTemplate(), sender, metaId, result); + if(notificationCtr.getMailTemplate().getCpfrom()) { + MailBundle ccBundles = mailManager.makeMailBundle(context, sender, notificationCtr.getMailTemplate(), sender, metaId, result); result.append(mailManager.sendMessage(ccBundles)); } MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getLocale()); } notificationCmc.deactivate(); - added.clear(); - } else if(source == removedNotificationCtr && event == Event.DONE_EVENT) { - if(removedNotificationCtr.getMailTemplate() != null) { - - //fxdiff VCRP-16: intern mail system - Identity sender = ureq.getIdentity(); - MailerResult result = new MailerResult(); - String metaId = UUID.randomUUID().toString().replace("-", ""); - MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString()); - MailBundle[] bundles = mailManager.makeMailBundles(context, added, addedNotificationCtr.getMailTemplate(), sender, metaId, result); - result.append(mailManager.sendMessage(bundles)); - if(addedNotificationCtr.getMailTemplate().getCpfrom()) { - MailBundle ccBundle = mailManager.makeMailBundle(context, sender, addedNotificationCtr.getMailTemplate(), sender, metaId, result); - result.append(mailManager.sendMessage(ccBundle)); - } - MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getLocale()); - } - notificationCmc.deactivate(); - removed.clear(); + selectedIds.clear(); } else if(source == contactCtr) { notificationCmc.deactivate(); } @@ -304,28 +288,21 @@ public class DENManageParticipantsController extends BasicController { tableListParticipants.setTableDataModel(listTableData); } - private void createAddedNotificationMail(UserRequest ureq, String subjectStr) { - MailTemplate mailTempl = denManager.getAddedMailTemplate(ureq, subjectStr, getTranslator()); - removeAsListenerAndDispose(addedNotificationCtr); - - addedNotificationCtr = new MailNotificationEditController(getWindowControl(), ureq, mailTempl, false, false, true); - listenTo(addedNotificationCtr); - - removeAsListenerAndDispose(notificationCmc); - notificationCmc = new CloseableModalController(getWindowControl(), "close", addedNotificationCtr.getInitialComponent()); - listenTo(notificationCmc); + private void createNotificationMail(UserRequest ureq, String subjectStr, String action) { + MailTemplate mailTempl; + if (action.equals(REMOVE_ACTION)) { + mailTempl = denManager.getRemovedMailTemplate(ureq, subjectStr, getTranslator()); + } else { + mailTempl = denManager.getAddedMailTemplate(ureq, subjectStr, getTranslator()); + } - notificationCmc.activate(); - } + removeAsListenerAndDispose(notificationCtr); - private void createRemovedNotificationMail(UserRequest ureq, String subjectStr) { - MailTemplate mailTempl = denManager.getRemovedMailTemplate(ureq, subjectStr, getTranslator()); - removeAsListenerAndDispose(addedNotificationCtr); - addedNotificationCtr = new MailNotificationEditController(getWindowControl(), ureq, mailTempl, false, false, true); - listenTo(addedNotificationCtr); + notificationCtr = new MailNotificationEditController(getWindowControl(), ureq, mailTempl, false, false, true); + listenTo(notificationCtr); removeAsListenerAndDispose(notificationCmc); - notificationCmc = new CloseableModalController(getWindowControl(), "close", addedNotificationCtr.getInitialComponent()); + notificationCmc = new CloseableModalController(getWindowControl(), "close", notificationCtr.getInitialComponent()); listenTo(notificationCmc); notificationCmc.activate();