From: Tim Otten Date: Fri, 27 Feb 2015 00:19:57 +0000 (-0700) Subject: CRM-15854 - crmMailing - Adapt layout (w/conditionals) if workflow enabled X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c0e893190e5d303e483a1f60d0658f7ba34523e4;p=civicrm-core.git CRM-15854 - crmMailing - Adapt layout (w/conditionals) if workflow enabled --- diff --git a/js/angular-crmMailing.js b/js/angular-crmMailing.js index 8c4cf8b4f7..256cda54e8 100644 --- a/js/angular-crmMailing.js +++ b/js/angular-crmMailing.js @@ -8,6 +8,8 @@ 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) { @@ -23,6 +25,9 @@ '/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: '

' + ts('Initializing...') + '

', controller: 'CreateMailingCtrl', @@ -71,14 +76,22 @@ $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); @@ -97,7 +110,8 @@ }; // @return Promise - $scope.submit = function submit() { + $scope.submit = function submit(options) { + options = options || {}; if (block.check() || $scope.crmMailing.$invalid) { return; } @@ -111,7 +125,9 @@ 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)); @@ -163,7 +179,7 @@ } }; - var myAutosave = new CrmAutosaveCtrl({ + myAutosave = new CrmAutosaveCtrl({ save: $scope.save, saveIf: function() { return true; @@ -260,6 +276,7 @@ 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; }); diff --git a/js/angular-crmMailing/directives.js b/js/angular-crmMailing/directives.js index f217a93253..7ae1cad7e4 100644 --- a/js/angular-crmMailing/directives.js +++ b/js/angular-crmMailing/directives.js @@ -3,6 +3,7 @@ // 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', @@ -15,7 +16,7 @@ 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: '@' @@ -28,6 +29,9 @@ 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; + }); } }; }); diff --git a/partials/crmMailing/approve.html b/partials/crmMailing/approve.html new file mode 100644 index 0000000000..ce50e71852 --- /dev/null +++ b/partials/crmMailing/approve.html @@ -0,0 +1,14 @@ +
+
+
+ {{mailingFields.approval_status_id.optionsMap[mailing.approval_status_id] || ts('Unreviewed')}} +
+
+ +
+
+
diff --git a/partials/crmMailing/edit-workflow.html b/partials/crmMailing/edit-workflow.html new file mode 100644 index 0000000000..c0f1d6f921 --- /dev/null +++ b/partials/crmMailing/edit-workflow.html @@ -0,0 +1,75 @@ +
+
{{mailing|json}}
+
+ +
+ {{ts('This mailing has been submitted.')}} +
+ +
+
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + + + + + +
+
+