var RECIPIENTS_DEBOUNCE_MS = 100;
var RECIPIENTS_PREVIEW_LIMIT = 10000;
+ var APPROVAL_STATUSES = {'Approved': 1, 'Rejected': 2, 'None': 3};
+
angular.module('crmMailing').config([
'$routeProvider',
function ($routeProvider) {
'/wizard': '~/crmMailing/edit-wizard.html'
};
angular.forEach(editorPaths, function(editTemplate, pathSuffix) {
+ if (CRM && CRM.crmMailing && CRM.crmMailing.workflowEnabled) {
+ editTemplate = '~/crmMailing/edit-workflow.html'; // override
+ }
$routeProvider.when('/mailing/new' + pathSuffix, {
template: '<p>' + ts('Initializing...') + '</p>',
controller: 'CreateMailingCtrl',
$scope.mailing = selectedMail;
$scope.attachments = attachments;
$scope.crmMailingConst = CRM.crmMailing;
+ $scope.checkPerm = CRM.checkPerm;
var ts = $scope.ts = CRM.ts(null);
var block = $scope.block = crmBlocker();
+ var myAutosave = null;
$scope.isSubmitted = function isSubmitted() {
return _.size($scope.mailing.jobs) > 0;
};
+ // usage: approve('Approved')
+ $scope.approve = function approve(status, options) {
+ $scope.mailing.approval_status_id = APPROVAL_STATUSES[status];
+ return myAutosave.suspend($scope.submit(options));
+ };
+
// @return Promise
$scope.previewMailing = function previewMailing(mailing, mode) {
return crmMailingPreviewMgr.preview(mailing, mode);
};
// @return Promise
- $scope.submit = function submit() {
+ $scope.submit = function submit(options) {
+ options = options || {};
if (block.check() || $scope.crmMailing.$invalid) {
return;
}
return crmMailingMgr.submit($scope.mailing);
})
.then(function () {
- $scope.leave('scheduled');
+ if (!options.stay) {
+ $scope.leave('scheduled');
+ }
})
;
return block(crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, promise));
}
};
- var myAutosave = new CrmAutosaveCtrl({
+ myAutosave = new CrmAutosaveCtrl({
save: $scope.save,
saveIf: function() {
return true;
var refreshRecipients = _.debounce(function () {
$scope.$apply(function () {
$scope.recipients = null;
+ if (!$scope.mailing) return;
crmMailingMgr.previewRecipients($scope.mailing, RECIPIENTS_PREVIEW_LIMIT).then(function (recipients) {
$scope.recipients = recipients;
});
// The following directives have the same simple implementation -- load
// a template and export a "mailing" object into scope.
var simpleBlocks = {
+ crmMailingBlockApprove: '~/crmMailing/approve.html',
crmMailingBlockHeaderFooter: '~/crmMailing/headerFooter.html',
crmMailingBlockMailing: '~/crmMailing/mailing.html',
crmMailingBlockPublication: '~/crmMailing/publication.html',
crmMailingBodyText: '~/crmMailing/body_text.html'
};
_.each(simpleBlocks, function(templateUrl, directiveName){
- angular.module('crmMailing').directive(directiveName, function () {
+ angular.module('crmMailing').directive(directiveName, function ($q, crmMetadata) {
return {
scope: {
crmMailing: '@'
scope.crmMailingConst = CRM.crmMailing;
scope.ts = CRM.ts(null);
scope[directiveName] = attr[directiveName] ? scope.$parent.$eval(attr[directiveName]) : {};
+ $q.when(crmMetadata.getFields('Mailing'), function(fields) {
+ scope.mailingFields = fields;
+ });
}
};
});
--- /dev/null
+<div class="crm-block" ng-form="apprForm" crm-ui-id-scope>
+ <div class="crm-group">
+ <div crm-ui-field crm-title="ts('Status')">
+ {{mailingFields.approval_status_id.optionsMap[mailing.approval_status_id] || ts('Unreviewed')}}
+ </div>
+ <div crm-ui-field="apprForm.approval_note" crm-title="ts('Note')">
+ <textarea
+ crm-ui-id="apprForm.approval_note"
+ name="approval_note"
+ ng-model="mailing.approval_note"
+ ></textarea>
+ </div>
+ </div>
+</div>
--- /dev/null
+<div crm-ui-accordion crm-title="ts('Debug')" crm-collapsed="true">
+ <pre>{{mailing|json}}</pre>
+</div>
+
+<div ng-show="isSubmitted()">
+ {{ts('This mailing has been submitted.')}}
+</div>
+
+<form name="crmMailing" novalidate ng-hide="isSubmitted()">
+ <div class="crm-block crm-form-block crmMailing">
+
+ <div crm-ui-wizard>
+
+ <div crm-ui-wizard-step="10" crm-title="ts('Content')" ng-form="contentForm" ng-if="checkPerm('create mailings')">
+ <div crm-mailing-block-summary crm-mailing="mailing"/>
+ <div crm-mailing-block-mailing crm-mailing="mailing"/>
+ <div crm-ui-accordion crm-title="ts('HTML')">
+ <div crm-mailing-body-html crm-mailing="mailing"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Plain Text')" crm-collapsed='!mailing.body_text'>
+ <div crm-mailing-body-text crm-mailing="mailing"/>
+ </div>
+ <span ng-model="placeholder" crm-ui-validate="mailing.body_html || mailing.body_text"></span>
+ <div crm-ui-accordion crm-title="ts('Header and Footer')" crm-collapsed="true">
+ <div crm-mailing-block-header-footer crm-mailing="mailing"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Attachments')" crm-collapsed="true">
+ <div crm-attachments="attachments"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Preview')">
+ <div crm-mailing-block-preview crm-mailing="mailing" on-preview="previewMailing(mailing, preview.mode)" on-send="sendTest(mailing, attachments, preview.recipient)" />
+ </div>
+ </div>
+
+ <div crm-ui-wizard-step="20" crm-title="ts('Options')" ng-form="optionsForm" ng-if="checkPerm('create mailings')">
+ <div crm-ui-accordion crm-title="ts('Responses')" crm-collapsed="true">
+ <div crm-mailing-block-responses crm-mailing="mailing"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Tracking')" crm-collapsed="true">
+ <div crm-mailing-block-tracking crm-mailing="mailing"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Publication')" crm-collapsed="true">
+ <div crm-mailing-block-publication crm-mailing="mailing"/>
+ </div>
+ </div>
+
+ <div crm-ui-wizard-step="40" crm-title="ts('Review')" ng-form="schedForm" ng-if="checkPerm('schedule mailings')">
+ <div crm-ui-accordion crm-title="ts('Review')">
+ <div crm-mailing-block-review crm-mailing="mailing"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Schedule')">
+ <div crm-mailing-block-schedule crm-mailing="mailing"/>
+ </div>
+ <div crm-ui-accordion crm-title="ts('Approval')" ng-if="checkPerm('approve mailings')">
+ <div crm-mailing-block-approve crm-mailing="mailing"/>
+ </div>
+ <center ng-if="!checkPerm('approve mailings')">
+ <a class="button crmMailing-submit-button" ng-click="submit()" ng-class="{blocking: block.check(), disabled: crmMailing.$invalid}">
+ <div>{{ts('Submit Mailing')}}</div>
+ </a>
+ </center>
+ <center ng-if="checkPerm('approve mailings')">
+ <a class="button crmMailing-submit-button" ng-click="approve('Approved')" ng-class="{blocking: block.check(), disabled: crmMailing.$invalid}">
+ <div>{{ts('Submit and Approve Mailing')}}</div>
+ </a>
+ </center>
+ </div>
+
+ <span crm-ui-wizard-buttons style="float:right;">
+ <button crm-icon="trash" ng-disabled="block.check()" crm-confirm="{title:ts('Delete Draft'), message:ts('Are you sure you want to permanently delete this mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
+ <button crm-icon="disk" ng-disabled="block.check()" ng-click="save().then(leave)">{{ts('Save Draft')}}</button>
+ </span>
+ </div>
+ </div>
+</form>