});
var lastEmailTokenAlert = null;
- angular.module('crmMailing').controller('EmailBodyCtrl', function EmailBodyCtrl($scope, crmMailingMgr) {
+ angular.module('crmMailing').controller('EmailBodyCtrl', function EmailBodyCtrl($scope, crmMailingMgr, crmUiAlert, $timeout) {
var ts = CRM.ts(null);
- $scope.hasAllTokens = function hasMissingTokens(mailing, field) {
+ // ex: if (!hasAllTokens(myMailing, 'body_text)) alert('Oh noes!');
+ $scope.hasAllTokens = function hasAllTokens(mailing, field) {
return _.isEmpty(crmMailingMgr.findMissingTokens(mailing, field));
};
- $scope.checkTokens = function checkTokens(mailing) {
+ // ex: checkTokens(myMailing, 'body_text', 'insert:body_text')
+ // ex: checkTokens(myMailing, '*')
+ $scope.checkTokens = function checkTokens(mailing, field, insertEvent) {
if (lastEmailTokenAlert) {
lastEmailTokenAlert.close();
}
- var missing = angular.extend(
- {},
- crmMailingMgr.findMissingTokens(mailing, 'body_html'),
- crmMailingMgr.findMissingTokens(mailing, 'body_text')
- );
- if (! _.isEmpty(missing)) {
- var buf = '<p>' +
- ts('Before submitting this mailing, you must include an address token and an action token as part of the mailing body, mailing header, or mailing footer.') +
- '</p><ul>';
- angular.forEach(missing, function(msg, token) {
- // FIXME LTR RTL
- buf = buf + '<li>{' + token + '} - <em>' + msg + '</em></li>';
+ var missing, insertable;
+ if (field == '*') {
+ insertable = false;
+ missing = angular.extend({},
+ crmMailingMgr.findMissingTokens(mailing, 'body_html'),
+ crmMailingMgr.findMissingTokens(mailing, 'body_text')
+ );
+ } else {
+ insertable = !_.isEmpty(insertEvent);
+ missing = crmMailingMgr.findMissingTokens(mailing, field);
+ }
+ if (!_.isEmpty(missing)) {
+ lastEmailTokenAlert = crmUiAlert({
+ type: 'error',
+ title: ts('Required tokens'),
+ templateUrl: '~/crmMailing/dialog/tokenAlert.html',
+ scope: angular.extend($scope.$new(), {
+ insertable: insertable,
+ insertToken: function(token) {
+ $timeout(function(){
+ $scope.$broadcast(insertEvent, '{' + token + '}');
+ $timeout(function(){
+ checkTokens(mailing, field, insertEvent);
+ });
+ });
+ },
+ missing: missing
+ })
});
- buf += '</ul>';
- lastEmailTokenAlert = CRM.alert(buf, undefined, 'error');
}
};
});
--- /dev/null
+<p ng-show="missing['domain.address']">
+ {{ts('The mailing must include the street address of the organization. Please insert the %1 token.', {1:
+ '{domain.address}'})}}
+</p>
+
+<div ng-show="missing['domain.address'] && insertable">
+ <a ng-click="insertToken('domain.address')" class="button"><span><span
+ class='icon ui-icon-circle-plus'></span> {{ts('Address')}}</span></a>
+
+ <div class="clear"/>
+</div>
+
+<p ng-show="missing['action.optOut']">
+ {{ts('The mailing must allow recipients to (a) unsubscribe from the mailing-list or (b) completely opt-out from all
+ mailings. Please insert an unsubscribe or opt-out token.')}}
+</p>
+
+<div ng-show="missing['action.optOut'] && insertable">
+ <table>
+ <thead>
+ <tr>
+ <th>{{ts('Via Web')}}</th>
+ <th>{{ts('Via Email')}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>
+ <a ng-click="insertToken('action.unsubscribeUrl')" class="button"><span><span
+ class='icon ui-icon-circle-plus'></span> {{ts('Unsubscribe')}}</span></a>
+ </td>
+ <td>
+ <a ng-click="insertToken('action.unsubscribe')" class="button"><span><span
+ class='icon ui-icon-circle-plus'></span> {{ts('Unsubscribe')}}</span></a>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <a ng-click="insertToken('action.optOutUrl')" class="button"><span><span
+ class='icon ui-icon-circle-plus'></span> {{ts('Opt-out')}}</span></a>
+ </td>
+ <td>
+ <a ng-click="insertToken('action.optOut')" class="button"><span><span
+ class='icon ui-icon-circle-plus'></span> {{ts('Opt-out')}}</span></a>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+
+<div ng-show="missing['action.optOut'] && !insertable">
+ <table>
+ <thead>
+ <tr>
+ <th>{{ts('Via Web')}}</th>
+ <th>{{ts('Via Email')}}</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>
+ {action.optOutUrl}
+ </td>
+ <td>
+ {action.optOut}
+ </td>
+ </tr>
+ <tr>
+ <td>
+ {action.unsubscribeUrl}
+ </td>
+ <td>
+ {action.unsubscribe}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+
+<p>
+ {{ts('Alternatively, you may select a header or footer which includes the required tokens.')}}
+</p>
name="header_id"
ui-jq="select2"
ui-options="{dropdownAutoWidth : true, allowClear: true}"
- ng-change="checkTokens(mailing)"
+ ng-change="checkTokens(mailing, '*')"
ng-model="mailing.header_id"
ng-options="mc.id as mc.name for mc in crmMailingConst.headerfooterList | filter:{component_type: 'Header'}">
<option value=""></option>
name="footer_id"
ui-jq="select2"
ui-options="{dropdownAutoWidth : true, allowClear: true}"
- ng-change="checkTokens(mailing)"
+ ng-change="checkTokens(mailing, '*')"
ng-model="mailing.footer_id"
ng-options="mc.id as mc.name for mc in crmMailingConst.headerfooterList | filter:{component_type: 'Footer'}">
<option value=""></option>