use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class TaskFolderCallback method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest urequest, Controller source, Event event) {
if (source == modulesForm) {
boolean onoff = event.getCommand().endsWith("true");
if (event.getCommand().startsWith("task")) {
config.set(TACourseNode.CONF_TASK_ENABLED, new Boolean(onoff));
myTabbedPane.setEnabled(taskTabPosition, onoff);
if (onoff) {
accessabilityVC.put("taskCondition", taskConditionC.getInitialComponent());
} else {
accessabilityVC.remove(taskConditionC.getInitialComponent());
}
} else if (event.getCommand().startsWith("dropbox")) {
config.set(TACourseNode.CONF_DROPBOX_ENABLED, new Boolean(onoff));
myTabbedPane.setEnabled(dropboxTabPosition, onoff);
if (onoff) {
accessabilityVC.put("dropCondition", dropConditionC.getInitialComponent());
} else {
accessabilityVC.remove(dropConditionC.getInitialComponent());
}
} else if (event.getCommand().startsWith("returnbox")) {
config.set(TACourseNode.CONF_RETURNBOX_ENABLED, new Boolean(onoff));
if (onoff) {
accessabilityVC.put("returnboxCondition", returnboxConditionC.getInitialComponent());
} else {
accessabilityVC.remove(returnboxConditionC.getInitialComponent());
}
} else if (event.getCommand().startsWith("scoring")) {
config.set(TACourseNode.CONF_SCORING_ENABLED, new Boolean(onoff));
myTabbedPane.setEnabled(scoringTabPosition, onoff);
if (onoff) {
accessabilityVC.put("scoringCondition", scoringConditionC.getInitialComponent());
} else {
accessabilityVC.remove(scoringConditionC.getInitialComponent());
}
} else if (event.getCommand().startsWith("solution")) {
config.set(TACourseNode.CONF_SOLUTION_ENABLED, new Boolean(onoff));
myTabbedPane.setEnabled(solutionTabPosition, onoff);
if (onoff) {
accessabilityVC.put("solutionCondition", solutionConditionC.getInitialComponent());
} else {
accessabilityVC.remove(solutionConditionC.getInitialComponent());
}
}
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
return;
} else if (source == taskConditionC) {
if (event == Event.CHANGED_EVENT) {
node.setConditionTask(taskConditionC.getCondition());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if (source == dropConditionC) {
if (event == Event.CHANGED_EVENT) {
node.setConditionDrop(dropConditionC.getCondition());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if (source == returnboxConditionC) {
if (event == Event.CHANGED_EVENT) {
node.setConditionReturnbox(returnboxConditionC.getCondition());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if (source == scoringConditionC) {
if (event == Event.CHANGED_EVENT) {
node.setConditionScoring(scoringConditionC.getCondition());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if (source == solutionConditionC) {
if (event == Event.CHANGED_EVENT) {
node.setConditionSolution(solutionConditionC.getCondition());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if (source == dialogBoxController) {
if (DialogBoxUIFactory.isOkEvent(event)) {
// ok: open task folder
String relPath = TACourseNode.getTaskFolderPathRelToFolderRoot(course, node);
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(relPath, null);
OlatNamedContainerImpl namedFolder = new OlatNamedContainerImpl(translate("taskfolder"), rootFolder);
namedFolder.setLocalSecurityCallback(getTaskFolderSecCallback(relPath));
frc = new FolderRunController(namedFolder, false, urequest, getWindowControl());
listenTo(frc);
CloseableModalController cmc = new CloseableModalController(getWindowControl(), translate("folder.close"), frc.getInitialComponent());
cmc.activate();
fireEvent(urequest, Event.CHANGED_EVENT);
}
} else if (source == taskController) {
if (event == Event.CANCELLED_EVENT) {
return;
} else if (event == Event.DONE_EVENT) {
config.set(TACourseNode.CONF_TASK_TYPE, taskController.getTaskType());
config.set(TACourseNode.CONF_TASK_TEXT, taskController.getOptionalText());
config.set(TACourseNode.CONF_TASK_SAMPLING_WITH_REPLACEMENT, new Boolean(taskController.getIsSamplingWithReplacement()));
config.setBooleanEntry(TACourseNode.CONF_TASK_PREVIEW, taskController.isTaskPreviewMode());
config.setBooleanEntry(TACourseNode.CONF_TASK_DESELECT, taskController.isTaskDeselectMode());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
return;
}
} else if (source == scoringController) {
if (event == Event.CANCELLED_EVENT) {
if (hasLogEntries) {
scoringController.setDisplayOnly(true);
}
editScoring.contextPut("isOverwriting", new Boolean(false));
return;
} else if (event == Event.DONE_EVENT) {
scoringController.updateModuleConfiguration(config);
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
}
} else if (source == dropboxForm) {
if (event == Event.CANCELLED_EVENT) {
return;
} else if (event == Event.DONE_EVENT) {
config.set(TACourseNode.CONF_DROPBOX_ENABLEMAIL, new Boolean(dropboxForm.mailEnabled()));
config.set(TACourseNode.CONF_DROPBOX_CONFIRMATION, dropboxForm.getConfirmation());
fireEvent(urequest, NodeEditController.NODECONFIG_CHANGED_EVENT);
return;
}
} else if (source == frc && (event instanceof FolderEvent) && event.getCommand().equals(FolderEvent.DELETE_EVENT)) {
String deletedTaskFile = getFileListAsComaSeparated(((FolderEvent) event).getFilename());
// cancel task assignment
identitiesToBeNotified = removeAssignedTask(course, deletedTaskFile);
if (identitiesToBeNotified.size() > 0) {
// prepare mailTemplate if they are any identities to be notified
removeAsListenerAndDispose(mailCtr);
RepositoryEntry repositoryEntry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
String courseURL = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + repositoryEntry.getKey();
MailTemplate mailTemplate = this.createTaskDeletedMailTemplate(urequest, course.getCourseTitle(), courseURL, deletedTaskFile);
mailCtr = new MailNotificationEditController(getWindowControl(), urequest, mailTemplate, true, false, true);
listenTo(mailCtr);
cmc = new CloseableModalController(getWindowControl(), translate("close"), mailCtr.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
} else if (source == mailCtr) {
if (event == Event.DONE_EVENT) {
cmc.deactivate();
if (identitiesToBeNotified != null && identitiesToBeNotified.size() > 0) {
// sent email to all identities that used to have the deleted task assigned
sendNotificationEmail(urequest, mailCtr.getMailTemplate(), identitiesToBeNotified);
}
} else if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
}
} else {
log.warn("Can not handle event in TACourseNodeEditController source=" + source + " " + event.toString());
}
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class PublishController method doAddAccessRights.
private void doAddAccessRights(UserRequest ureq) {
removeAsListenerAndDispose(addMembersWizard);
Step start = new AddMember_1_ChooseMemberStep(ureq, binder);
StepRunnerCallback finish = new StepRunnerCallback() {
@Override
public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
AccessRightsContext rightsContext = (AccessRightsContext) runContext.get("rightsContext");
MailTemplate mailTemplate = (MailTemplate) runContext.get("mailTemplate");
addMembers(rightsContext, mailTemplate);
return StepsMainRunController.DONE_MODIFIED;
}
};
addMembersWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("add.member"), "o_sel_course_member_import_1_wizard");
listenTo(addMembersWizard);
getWindowControl().pushAsModalDialog(addMembersWizard.getInitialComponent());
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class MailTest method testMailToCcBccTogether.
/**
* Test for the mail template and the context variable methods
*/
@Test
public void testMailToCcBccTogether() {
String subject = "Together Subject: Hello everybody";
String body = "Together Body: \n\n You should go to \n\n'$coursename' @ $courseURL";
final String coursename = "my course";
final String courseURL = "http://www.mytrashmail.com/";
MailTemplate template = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// identity is null in this mode - template parsed only once not for
// everybody
// Put variables from greater context, eg. course id, group name etc.
context.put("coursename", coursename);
context.put("courseURL", courseURL);
}
};
// some recipients data
List<Identity> recipients = new ArrayList<Identity>();
recipients.add(id1);
recipients.add(id2);
recipients.add(id3);
Identity recipientCC = id4;
// tests with / witthout CC and BCC
MailerResult result = new MailerResult();
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, recipientCC, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
result = sendMailAsSeparateMails(null, recipients, null, template, id6, null);
assertEquals(MailerResult.OK, result.getReturnCode());
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class MailTest method testMailAttachments.
/**
* Test for the mail template and the context variable methods
*/
@Test
public void testMailAttachments() {
String subject = "Subject: Hello $firstname with attachment";
String body = "Body: \n\n Hey $login, here's a file for you: ";
// some attachemnts
File[] attachments = new File[1];
File file1;
try {
System.out.println("MailTest.testMailAttachments Url1=" + MailTest.class.getResource("MailTest.class"));
file1 = new File(MailTest.class.getResource("MailTest.class").toURI());
attachments[0] = file1;
// TODO: cg Properties file is in olat_core.jar and not be lookup as resource (jar:file:...)
// System.out.println("MailTest.testMailAttachments Url2=" + MailTest.class.getResource("_i18n/LocalStrings_de.properties") );
// file2 = new File(MailTest.class.getResource("_i18n/LocalStrings_de.properties").toURI());
// attachments[1] = file2;
} catch (URISyntaxException e) {
fail("ups, can't get testfiles from local path: MailTest.class and _i18n/LocalStrings_de.properties");
}
MailTemplate template = new MailTemplate(subject, body, attachments) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("login", identity.getName());
}
};
// some recipients data
List<Identity> recipients = new ArrayList<Identity>();
recipients.add(id1);
MailerResult result = new MailerResult();
result = sendMailAsSeparateMails(null, recipients, null, template, id2, null);
assertEquals(MailerResult.OK, result.getReturnCode());
}
use of org.olat.core.util.mail.MailTemplate in project OpenOLAT by OpenOLAT.
the class GroupController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller sourceController, Event event) {
if (sourceController == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
// Single row selects
TableEvent te = (TableEvent) event;
String actionid = te.getActionId();
final Identity identity = identitiesTableModel.getObject(te.getRowId()).getIdentity();
if (actionid.equals(COMMAND_VCARD)) {
// get identity and open new visiting card controller in new window
ControllerCreator userInfoMainControllerCreator = new ControllerCreator() {
@Override
public Controller createController(UserRequest lureq, WindowControl lwControl) {
return new UserInfoMainController(lureq, lwControl, identity, true, false);
}
};
// wrap the content controller into a full header layout
ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, userInfoMainControllerCreator);
// open in new browser window
PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr);
pbw.open(ureq);
//
} else if (actionid.equals(COMMAND_SELECTUSER)) {
fireEvent(ureq, new SingleIdentityChosenEvent(identity));
} else if (COMMAND_IM.equals(actionid)) {
doIm(ureq, identity);
}
} else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
// Multiselect events
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
if (tmse.getAction().equals(COMMAND_REMOVEUSER)) {
if (tmse.getSelection().isEmpty()) {
// empty selection
showWarning("msg.selectionempty");
return;
}
int size = identitiesTableModel.getObjects().size();
toRemove = identitiesTableModel.getIdentities(tmse.getSelection());
// list is never null, but can be empty
if (keepAtLeastOne && (size == 1 || size - toRemove.size() == 0)) {
// at least one must be kept
// do not delete the last one => ==1
// do not allow to delete all => size - selectedCnt == 0
showError("msg.atleastone");
} else {
// valid selection to be deleted.
if (removeUserMailDefaultTempl == null) {
doBuildConfirmDeleteDialog(ureq);
} else {
removeAsListenerAndDispose(removeUserMailCtr);
removeUserMailCtr = new MailNotificationEditController(getWindowControl(), ureq, removeUserMailDefaultTempl, true, false, true);
listenTo(removeUserMailCtr);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), translate("close"), removeUserMailCtr.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
}
}
}
} else if (sourceController == removeUserMailCtr) {
if (event == Event.DONE_EVENT) {
removeUserMailCustomTempl = removeUserMailCtr.getMailTemplate();
cmc.deactivate();
doBuildConfirmDeleteDialog(ureq);
} else {
cmc.deactivate();
}
} else if (sourceController == usc) {
if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
} else {
if (event instanceof SingleIdentityChosenEvent) {
SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
Identity choosenIdentity = singleEvent.getChosenIdentity();
if (choosenIdentity == null) {
showError("msg.selectionempty");
return;
}
toAdd = new ArrayList<Identity>();
toAdd.add(choosenIdentity);
} else if (event instanceof MultiIdentityChosenEvent) {
MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
toAdd = multiEvent.getChosenIdentities();
if (toAdd.size() == 0) {
showError("msg.selectionempty");
return;
}
} else {
throw new RuntimeException("unknown event ::" + event.getCommand());
}
if (toAdd.size() == 1) {
// check if already in group [makes only sense for a single choosen identity]
if (groupDao.hasRole(group, toAdd.get(0), role)) {
String fullName = userManager.getUserDisplayName(toAdd.get(0));
getWindowControl().setInfo(translate("msg.subjectalreadyingroup", new String[] { fullName }));
return;
}
} else if (toAdd.size() > 1) {
// check if already in group
List<Identity> alreadyInGroup = new ArrayList<Identity>();
for (int i = 0; i < toAdd.size(); i++) {
if (groupDao.hasRole(group, toAdd.get(i), role)) {
tableCtr.setMultiSelectSelectedAt(i, false);
alreadyInGroup.add(toAdd.get(i));
}
}
if (!alreadyInGroup.isEmpty()) {
StringBuilder names = new StringBuilder();
for (Identity ident : alreadyInGroup) {
if (names.length() > 0)
names.append(", ");
names.append(userManager.getUserDisplayName(ident));
toAdd.remove(ident);
}
getWindowControl().setInfo(translate("msg.subjectsalreadyingroup", names.toString()));
}
if (toAdd.isEmpty()) {
return;
}
}
// in both cases continue adding the users or asking for the mail
// template if available (=not null)
cmc.deactivate();
if (addUserMailDefaultTempl == null) {
doAddIdentitiesToGroup(ureq, toAdd, null);
} else {
removeAsListenerAndDispose(addUserMailCtr);
addUserMailCtr = new MailNotificationEditController(getWindowControl(), ureq, addUserMailDefaultTempl, true, mandatoryEmail, true);
listenTo(addUserMailCtr);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), translate("close"), addUserMailCtr.getInitialComponent());
listenTo(cmc);
cmc.activate();
}
}
// in any case cleanup this controller, not used anymore
usc.dispose();
usc = null;
} else if (sourceController == addUserMailCtr) {
if (event == Event.DONE_EVENT) {
MailTemplate customTemplate = addUserMailCtr.getMailTemplate();
doAddIdentitiesToGroup(ureq, toAdd, customTemplate);
cmc.deactivate();
} else if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
} else {
throw new RuntimeException("unknown event ::" + event.getCommand());
}
} else if (sourceController == confirmDelete) {
if (DialogBoxUIFactory.isYesEvent(event)) {
// before deleting, assure it is allowed
if (!mayModifyMembers)
throw new AssertException("not allowed to remove member!");
// list is never null, but can be empty
// TODO: Theoretically it can happen that the table model here is not accurate!
// the 'keep at least one' should be handled by the security manager that should
// synchronizes the method on the group
int size = identitiesTableModel.getObjects().size();
if (keepAtLeastOne && (size - toRemove.size() == 0)) {
showError("msg.atleastone");
} else {
doRemoveIdentitiesFromGroup(ureq, toRemove, removeUserMailCustomTempl);
}
}
} else if (sourceController == userToGroupWizard) {
if (event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
getWindowControl().pop();
removeAsListenerAndDispose(userToGroupWizard);
userToGroupWizard = null;
if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
reloadData();
}
}
}
}
Aggregations