/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS,
* <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) 1999-2006 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
* Description:<br>
* The MailNotificationEditController allows the user to enter a mailtext based
* on the MailTemplate. It will be surrounded by some comments which variables
* that can be used in this context.
* <p>
* Events:
* <ul>
* <li>Event.DONE_EVENT</li>
* <li>Event.CANCEL_EVENT</li>
* </ul>
* <p>
* Initial Date: 23.11.2006 <br>
*
* @author Florian Gnaegi, frentix GmbH<br>
* http://www.frentix.com
*/
package org.olat.core.util.mail;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.DefaultController;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.translator.PackageTranslator;
import org.olat.core.gui.translator.Translator;
import org.olat.core.util.Util;
public class MailNotificationEditController extends DefaultController {
protected static final String PACKAGE = Util.getPackageName(MailNotificationEditController.class);
protected static final String VELOCITY_ROOT = Util.getPackageVelocityRoot(MailNotificationEditController.class);
// components
private VelocityContainer mainVC;
private MailTemplateForm mailForm;
private Translator trans;
// data model
private MailTemplate mailTemplate;
private String orgMailSubject;
private String orgMailBody;
private Boolean cpFrom;
/**
* Constructor for the email
* @param wControl
* @param ureq
* @param mailTemplate
* @param useCancel
*/
public MailNotificationEditController(WindowControl wControl, UserRequest ureq, MailTemplate mailTemplate, boolean useCancel) {
super(wControl);
this.mailTemplate = mailTemplate;
orgMailSubject = mailTemplate.getSubjectTemplate();
orgMailBody = mailTemplate.getBodyTemplate();
cpFrom = mailTemplate.getCpfrom();
this.trans = new PackageTranslator(PACKAGE, ureq.getLocale());
this.mainVC = new VelocityContainer("mainVC", VELOCITY_ROOT + "/mailnotification.html", trans, this);
this.mailForm = new MailTemplateForm(ureq.getLocale(), mailTemplate, useCancel, this);
this.mainVC.put("mailForm", mailForm);
setInitialComponent(mainVC);
}
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (source == mailForm) {
if (event == Form.EVNT_VALIDATION_OK) {
mailForm.updateTemplateFromForm(mailTemplate);
fireEvent(ureq, Event.DONE_EVENT);
} else if (event == Form.EVNT_FORM_CANCELLED) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}
}
}
/**
* @return The mail template containing the configured mail or null if user
* decided to not send a mail
*/
public MailTemplate getMailTemplate() {
if (mailForm.sendMailSwitchEnabled()) {
return mailTemplate;
} else {
return null;
}
}
/**
*
* @return Boolean
*/
public boolean isTemplateChanged() {
return !orgMailSubject.equals(mailTemplate.getSubjectTemplate())
|| !orgMailBody.equals(mailTemplate.getBodyTemplate())
|| !cpFrom.equals(mailTemplate.getCpfrom());
}
@Override
protected void doDispose() {
// TODO Auto-generated method stub
}
}