001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.email;
019
020import java.util.Map;
021
022/**
023 * A version of the ContactableEmailer meant to be extended from Javascript.
024 * Every method that one would normally override now has a version that passes in the object.
025 * This is to prevent the problem whereby classes extended by nashorn do not get access to "this"
026 * So we have to manually pass in the instance as the first argument. It's like python all over again!
027 *
028 * @param <T>
029 */
030public abstract class JsExtendableContactableEmailer<T extends Contactable> extends ContactableEmailer<T> {
031
032    public JsExtendableContactableEmailer(T user) {
033        super(user);
034    }
035
036    public JsExtendableContactableEmailer(T user, Map<String, Object> context) {
037        super(user, context);
038    }
039
040    public String getTemplate() {
041        return getTemplate(this.getContext());
042    }
043    public abstract String getTemplate(Object self);
044
045    public String getSubject() {
046        return getSubjectJs(this.getContext());
047    }
048    public abstract String getSubjectJs(Object self);
049
050    public String getFromAddress() {
051        return getFromAddressJs(this);
052    }
053    public String getFromAddressJs(JsExtendableContactableEmailer<T> self) {
054        return super.getFromAddress();
055    }
056
057    public String getReplyTo() {
058        return getReplyToJs(this);
059    }
060    public String getReplyToJs(JsExtendableContactableEmailer<T> self) {
061        return super.getReplyTo();
062    }
063
064
065    public String getCc() {
066        return getCcJs(this);
067    }
068    public String getCcJs(JsExtendableContactableEmailer<T> self) {
069        return super.getCc();
070    }
071
072    public String getUniqueKey() {
073        return getUniqueKey(this);
074    }
075    public String getUniqueKey(JsExtendableContactableEmailer<T> self) {
076        return super.getUniqueKey();
077    }
078
079
080    protected void onPrepareContext() {
081        onPrepareContext(this);
082    }
083
084    protected void onPrepareContext(JsExtendableContactableEmailer<T> self) {
085        super.onPrepareContext();
086    }
087
088
089    public String getEmailType() {
090        return getEmailType(this);
091    }
092
093    public String getEmailType(JsExtendableContactableEmailer<T> self) {
094        return super.getEmailType();
095    }
096
097
098
099    public boolean checkOptOut() {
100        return checkOptOut(this);
101    }
102
103    public boolean checkOptOut(JsExtendableContactableEmailer<T> self) {
104        return super.checkOptOut();
105    }
106
107}