span.crmMailing2-exclude {
color: #600;
text-decoration: line-through;
+}
+
+.crmMailing2 input[name=preview_test_email], .crmMailing2-preview select[name=preview_test_group] {
+ width: 80%;
+}
+
+.crmMailing2 .preview-popup, .crmMailing2 .preview-contact, .crmMailing2 .preview-group {
+ width: 30%;
+ height: 4.5em;
+ margin: 0.5em;
+ text-align: center;
+ vertical-align: middle;
+ float: left;
+}
+.crmMailing2 .preview-popup, .crmMailing2 .preview-contact {
+ border-right: 1px solid black;
+}
+.crmMailing2 .preview-group, .crmMailing2 .preview-contact {
+}
+
+/* Odd: These placeholder directives break if combined */
+input[name=preview_test_email]:-moz-placeholder {
+ text-align: center;
+}
+input[name=preview_test_email]::-moz-placeholder {
+ text-align: center;
+}
+input[name=preview_test_email]::-webkit-input-placeholder {
+ text-align: center;
+}
+input[name=preview_test_email]:-ms-input-placeholder {
+ text-align: center;
}
\ No newline at end of file
};
},
+ // @param mailing Object (per APIv3)
+ // @return Promise an object with "subject", "body_text", "body_html"
+ preview: function preview(mailing) {
+ var params = _.extend({}, mailing, {
+ options: {force_rollback: 1},
+ 'api.Mailing.preview': {
+ id: '$value.id',
+ }
+ });
+ return crmApi('Mailing', 'create', params).then(function(result){
+ console.log('preview', params, result);
+ return result.values[result.id]['api.Mailing.preview'].values;
+ });
+ },
+
// @param mailing Object (per APIv3)
// @param int previewLimit
// @return Promise for a list of recipients (mailing_id, contact_id, api.contact.getvalue, api.email.getvalue)
crmMailing2.controller('PreviewRecipCtrl', function ($scope) {
$scope.ts = CRM.ts('CiviMail');
});
+
+ // Controller for the "Preview Mailing" segment
+ // Note: Expects $scope.model to be an object with properties:
+ // - mailing: object
+ crmMailing2.controller('PreviewMailingCtrl', function ($scope, dialogService, crmMailingMgr) {
+ $scope.ts = CRM.ts('CiviMail');
+ $scope.testContact = {email: ''};
+ $scope.testGroup = {gid: null};
+
+ $scope.previewHtml = function() {
+ $scope.previewDialog(partialUrl('dialog/previewHtml.html'));
+ };
+ $scope.previewText = function() {
+ $scope.previewDialog(partialUrl('dialog/previewText.html'));
+ };
+ $scope.previewFull = function() {
+ $scope.previewDialog(partialUrl('dialog/previewFull.html'));
+ };
+ // Open a dialog with a preview of the current mailing
+ // @param template string URL of the template to use in the preview dialog
+ $scope.previewDialog = function(template) {
+ CRM.status(ts('Previewing'));
+ crmMailingMgr
+ .preview($scope.mailing)
+ .then(function(content){
+ var options = {
+ autoOpen: false,
+ modal: true,
+ title: ts('Subject: %1', {
+ 1: content.subject
+ }),
+ };
+ dialogService.open('previewDialog', template, content, options);
+ });
+ };
+ $scope.sendTestToContact = function() {
+ CRM.alert('Send test to contact, ' + $scope.testContact.email);
+ };
+ $scope.sendTestToGroup = function() {
+ CRM.alert('Send test to group, ' + $scope.testGroup.gid);
+ };
+ });
+
+ // Controller for the "Preview Mailing" dialog
+ // Note: Expects $scope.model to be an object with properties:
+ // - "subject"
+ // - "body_html"
+ // - "body_text"
+ crmMailing2.controller('PreviewMailingDialogCtrl', function ($scope, crmMailingMgr) {
+ $scope.ts = CRM.ts('CiviMail');
+ });
+
})(angular, CRM.$, CRM._);
--- /dev/null
+<div ng-controller="PreviewMailingDialogCtrl">
+ <div crm-ui-tab-set>
+ <div crm-ui-tab id="preview-html" crm-title="ts('HTML')">
+ <iframe crm-ui-iframe="model.body_html"></iframe>
+ </div>
+ <div crm-ui-tab id="preview-text" crm-title="ts('Plain Text')">
+ <pre>{{model.body_text}}</pre>
+ </div>
+ </div>
+</div>
\ No newline at end of file
--- /dev/null
+<div ng-controller="PreviewMailingDialogCtrl">
+ <iframe crm-ui-iframe="model.body_html"></iframe>
+</div>
\ No newline at end of file
--- /dev/null
+<div ng-controller="PreviewMailingDialogCtrl">
+ <pre>{{model.body_text}}</pre>
+</div>
\ No newline at end of file
-preview.html
+<div ng-controller="PreviewMailingCtrl" class="crmMailing2-preview">
+ <!-- Note:
+ In Firefox (at least), clicking the preview buttons causes the browser to display validation warnings
+ for unrelated fields *and* display preview. To avoid this weird UX, we disable preview buttons when the form is incomplete/invalid.
+ -->
+ <div class="preview-popup">
+ <div ng-show="!mailing.body_html && !mailing.body_text">
+ <em>({{ts('No content to preview')}})</em>
+ </div>
+ <div ng-hide="!mailing.body_html">
+ <button ng-disabled="crmMailing2.$invalid" ng-click="previewHtml()">{{ts('Preview as HTML')}}</button>
+ </div>
+ <div ng-hide="!mailing.body_text">
+ <button ng-disabled="crmMailing2.$invalid" ng-click="previewText()">{{ts('Preview as Plain Text')}}</button>
+ </div>
+ <!--
+ <div ng-hide="!mailing.body_html && !mailing.body_text">
+ <button ng-disabled="crmMailing2.$invalid" ng-click="previewFull()">{{ts('Preview')}}</button>
+ </div>
+ -->
+ </div>
+ <div class="preview-contact" ng-form>
+ <div>
+ {{ts('Send test email to:')}}
+ </div>
+ <div>
+ <input
+ name="preview_test_email"
+ type="email"
+ class="crm-form-text"
+ ng-model="testContact.email"
+ placeholder="example@example.org"
+ />
+ </div>
+ <button ng-disabled="crmMailing2.$invalid || !testContact.email" ng-click="sendTestToContact()">{{ts('Send test')}}</button>
+ </div>
+ <div class="preview-group" ng-form>
+ <div>
+ {{ts('Send test email to group:')}}
+ </div>
+ <div>
+ <select
+ name="preview_test_group"
+ ui-jq="select2"
+ ui-options="{dropdownAutoWidth : true, allowClear: true, placeholder: ts('Select Group')}"
+ ng-model="testGroup.gid"
+ ng-options="group.id as group.title for group in crmMailingConst.groupNames|orderBy:'title'"
+ >
+ <option value=""></option>
+ </select>
+ </div>
+ <button ng-disabled="crmMailing2.$invalid || !testGroup.gid" ng-click="sendTestToGroup()">{{ts('Send test')}}</button>
+ </div>
+ <div class="clear"></div>
+</div>