use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class TaskFolderCallback method createTaskDeletedMailTemplate.
/**
* Create MailTemplate for task deleted action.
* @param ureq
* @param courseName
* @param courseLink
* @param fileName
* @return
*/
private MailTemplate createTaskDeletedMailTemplate(UserRequest ureq, String courseName, String courseLink, String fileName) {
String subjectTemplate = courseName + ": " + translate("task.deleted.subject");
String bodyTemplate = getTaskDeletedMailBody(ureq, fileName, courseName, courseLink);
MailTemplate mailTempl = new MailTemplate(subjectTemplate, bodyTemplate, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity recipient) {
// nothing to do
}
};
return mailTempl;
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
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 klemens.
the class AbstractBusinessGroupListController method confirmUserManagementEmail.
private void confirmUserManagementEmail(UserRequest ureq, MembershipModification mod, List<BusinessGroup> groups) {
removeAsListenerAndDispose(cmc);
removeAsListenerAndDispose(userManagementSendMailController);
MailTemplate defaultTemplate = null;
int totalModification = (mod.size() * groups.size());
if (totalModification == 1) {
MailType type = BusinessGroupMailing.getDefaultTemplateType(mod);
if (type != null) {
defaultTemplate = BusinessGroupMailing.getDefaultTemplate(type, groups.get(0), ureq.getIdentity());
}
}
MailTemplate template = new BGUserMailTemplate(groups, mod, defaultTemplate);
boolean mandatoryEmail = !mod.getAddParticipants().isEmpty() && groupModule.isMandatoryEnrolmentEmail(ureq.getUserSession().getRoles());
userManagementSendMailController = new BGMailNotificationEditController(getWindowControl(), ureq, template, totalModification == 1, totalModification == 1, false, mandatoryEmail);
Component cmp = userManagementSendMailController.getInitialComponent();
listenTo(userManagementSendMailController);
cmc = new CloseableModalController(getWindowControl(), translate("close"), cmp, true, translate("users.group"));
cmc.activate();
listenTo(cmc);
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class BGMailHelper method createMailTemplate.
/**
* Internal helper - does all the magic
*
* @param group
* @param actor
* @param subjectKey
* @param bodyKey
* @return
*/
private static MailTemplate createMailTemplate(BusinessGroupShort group, Identity actor, String subjectKey, String bodyKey) {
// get some data about the actor and fetch the translated subject / body via i18n module
String[] bodyArgs = null;
String lang = null;
if (actor != null) {
lang = actor.getUser().getPreferences().getLanguage();
}
Locale locale = I18nManager.getInstance().getLocaleOrDefault(lang);
if (actor != null) {
bodyArgs = new String[] { actor.getUser().getProperty(UserConstants.FIRSTNAME, null), actor.getUser().getProperty(UserConstants.LASTNAME, null), UserManager.getInstance().getUserDisplayEmail(actor, locale), // 2x for compatibility with old i18m properties
UserManager.getInstance().getUserDisplayEmail(actor, locale) };
}
Translator trans = Util.createPackageTranslator(BGMailHelper.class, locale, Util.createPackageTranslator(BusinessGroupListController.class, locale));
String subject = trans.translate(subjectKey);
String body = trans.translate(bodyKey, bodyArgs);
// build learning resources as list of url as string
final BGMailTemplateInfos infos;
if (group != null) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
infos = getTemplateInfos(group, repoEntries);
subject = subject.replace("$groupname", infos.getGroupName());
body = body.replace("$groupname", infos.getGroupNameWithUrl());
body = body.replace("$groupdescription", infos.getGroupDescription());
if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
body = body.replace("$courselist", infos.getCourseList());
} else {
body = body.replace("$courselist", trans.translate("notification.mail.no.ressource", null));
}
} else {
infos = new BGMailTemplateInfos("", "", "", "");
}
// create a mail template which all these data
MailTemplate mailTempl = new MailTemplate(subject, body, null) {
@Override
public void putVariablesInMailContext(VelocityContext context, Identity identity) {
// Put user variables into velocity context
User user = identity.getUser();
context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
// the email of the user, needs to stay named 'login'
context.put("login", user.getProperty(UserConstants.EMAIL, null));
// Put variables from greater context
context.put("groupname", infos.getGroupNameWithUrl());
context.put("groupdescription", infos.getGroupDescription());
if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
context.put("courselist", infos.getCourseList());
} else {
context.put("courselist", trans.translate("notification.mail.no.ressource", null));
}
context.put("courselistempty", trans.translate("notification.mail.no.ressource", null));
}
};
return mailTempl;
}
use of org.olat.core.util.mail.MailTemplate in project openolat by klemens.
the class BusinessGroupMembersController method addMembers.
private void addMembers(StepsRunContext runContext) {
@SuppressWarnings("unchecked") List<Identity> members = (List<Identity>) runContext.get("members");
MemberPermissionChangeEvent changes = (MemberPermissionChangeEvent) runContext.get("permissions");
// commit all changes to the group memberships
List<BusinessGroupMembershipChange> allModifications = changes.generateBusinessGroupMembershipChange(members);
MailTemplate template = (MailTemplate) runContext.get("mailTemplate");
MailPackage mailing = new MailPackage(template, getWindowControl().getBusinessControl().getAsString(), template != null);
businessGroupService.updateMemberships(getIdentity(), allModifications, mailing);
MailHelper.printErrorsAndWarnings(mailing.getResult(), getWindowControl(), false, getLocale());
}
Aggregations