CRM-15854 - crmMailing - Adapt layout (w/conditionals) if workflow enabled
authorTim Otten <totten@civicrm.org>
Fri, 27 Feb 2015 00:19:57 +0000 (17:19 -0700)
committerTim Otten <totten@civicrm.org>
Mon, 2 Mar 2015 23:59:43 +0000 (15:59 -0800)
js/angular-crmMailing.js
js/angular-crmMailing/directives.js
partials/crmMailing/approve.html [new file with mode: 0644]
partials/crmMailing/edit-workflow.html [new file with mode: 0644]

index 8c4cf8b4f779b3caa2b91a5054bbe917876b6dc5..256cda54e88f641b2466e9b74288066ae7a35065 100644 (file)
@@ -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: '<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;
         });
index f217a93253e268d2dc671a53f5e590bbbe6af490..7ae1cad7e4b5ff0307c7058da7ece4148c4c6cc8 100644 (file)
@@ -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 (file)
index 0000000..ce50e71
--- /dev/null
@@ -0,0 +1,14 @@
+<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>
diff --git a/partials/crmMailing/edit-workflow.html b/partials/crmMailing/edit-workflow.html
new file mode 100644 (file)
index 0000000..c0f1d6f
--- /dev/null
@@ -0,0 +1,75 @@
+<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>