CRM-15578 - crmMailing2 - Incorporate crmAttachments
authorTim Otten <totten@civicrm.org>
Tue, 9 Dec 2014 08:16:09 +0000 (00:16 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 10 Dec 2014 01:55:45 +0000 (17:55 -0800)
js/angular-crmMailing2.js
partials/crmMailing2/attachments.html
partials/crmMailing2/edit-unified2.html
partials/crmMailing2/review.html

index d75bfbf9fe3f665d7074a5245d9dde65775073d3..e4992b168abc20d94810631aff2bf22c53fa9413 100644 (file)
@@ -3,7 +3,7 @@
     return CRM.resourceUrls['civicrm'] + '/partials/crmMailing2/' + relPath;
   };
 
-  var crmMailing2 = angular.module('crmMailing2', ['crmUtil', 'ngRoute', 'ui.utils', 'crmUi', 'dialogService']); // TODO ngSanitize, unsavedChanges
+  var crmMailing2 = angular.module('crmMailing2', ['crmUtil', 'crmAttachment', 'ngRoute', 'ui.utils', 'crmUi', 'dialogService']); // TODO ngSanitize, unsavedChanges
 
   // Time to wait before triggering AJAX update to recipients list
   var RECIPIENTS_DEBOUNCE_MS = 100;
     });
   });
 
-  crmMailing2.controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmFromAddresses, crmStatus) {
+  crmMailing2.controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmFromAddresses, crmStatus, CrmAttachments) {
     $scope.mailing = selectedMail;
+    $scope.attachments = new CrmAttachments(function() {
+      return {entity_table: 'civicrm_mailing', entity_id: $scope.mailing.id};
+    });
     $scope.crmMailingConst = CRM.crmMailing;
     $scope.crmFromAddresses = crmFromAddresses;
 
 
     // @return Promise
     $scope.submit = function submit() {
-      return crmStatus({start: ts('Submitting...'), success: ts('Submitted')},
-        crmMailingMgr.submit($scope.mailing)
-      );
+      var promise = crmMailingMgr.save($scope.mailing)
+        .then(function () {
+          // pre-condition: the mailing exists *before* saving attachments to it
+          return $scope.attachments.save();
+        })
+        .then(function () {
+          return crmMailingMgr.submit($scope.mailing);
+        });
+      return crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, promise);
     };
     // @return Promise
     $scope.save = function save() {
       return crmStatus(null,
-        crmMailingMgr.save($scope.mailing)
+        crmMailingMgr
+          .save($scope.mailing)
+          .then(function () {
+            // pre-condition: the mailing exists *before* saving attachments to it
+            return $scope.attachments.save();
+          })
       );
     };
     // @return Promise
   // 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) {
+  //   - attachments: object
+  crmMailing2.controller('PreviewMailingCtrl', function ($scope, dialogService, crmMailingMgr, crmStatus) {
     var ts = $scope.ts = CRM.ts('CiviMail');
 
     $scope.testContact = {email: CRM.crmMailing.defaultTestEmail};
         CRM.status({start: ts('Previewing'), success: ''}, CRM.toJqPromise(p));
     };
     $scope.sendTestToContact = function sendTestToContact() {
-      $scope.sendTest($scope.mailing, $scope.testContact.email, null);
+      $scope.sendTest($scope.mailing, $scope.attachments, $scope.testContact.email, null);
     };
     $scope.sendTestToGroup = function sendTestToGroup() {
-      $scope.sendTest($scope.mailing, null, $scope.testGroup.gid);
+      $scope.sendTest($scope.mailing, $scope.attachments, null, $scope.testGroup.gid);
     };
-    $scope.sendTest = function sendTest(mailing, testEmail, testGroup) {
-      var promise = crmMailingMgr.sendTest(mailing, testEmail, testGroup).then(function(deliveryInfos){
-        var count = Object.keys(deliveryInfos).length;
-        if (count === 0) {
-          CRM.alert(ts('Could not identify any recipients. Perhaps the group is empty?'));
-        }
-      });
-      CRM.status({
-        start: ts('Sending...'),
-        success: ts('Sent')
-      }, CRM.toJqPromise(promise));
+    $scope.sendTest = function sendTest(mailing, attachments, testEmail, testGroup) {
+      var promise = crmMailingMgr.save(mailing)
+          .then(function () {
+            return attachments.save();
+          })
+          .then(function () {
+            return crmMailingMgr.sendTest(mailing, testEmail, testGroup);
+          })
+          .then(function (deliveryInfos) {
+            var count = Object.keys(deliveryInfos).length;
+            if (count === 0) {
+              CRM.alert(ts('Could not identify any recipients. Perhaps the group is empty?'));
+            }
+          })
+        ;
+      return crmStatus({start: ts('Sending...'), success: ts('Sent')}, promise);
     };
   });
 
index 24728b01444d663680092cc461fa3b0d10ae6842..107e6ae3e7629ead72b101a4e74fd6e14fdb7b88 100644 (file)
@@ -1 +1,5 @@
-attachments.html
+<div
+  ng-controller="CrmAttachmentsCtrl"
+  ng-init="init(attachments)"
+  ng-include="partialUrl('../crmAttachment/attachments.html')">
+</div>
index ca45e37db11a509be6e1f6dacb5888304dfec4d0..e9bd32c7482df48018ba37ed0fc7254113ab3549 100644 (file)
@@ -36,4 +36,4 @@
     <button ng-click="save().then(leave);">{{ts('Save Draft')}}</button>
     <button crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete().then(leave)">{{ts('Delete Draft')}}</button>
   </div>
-</form>
\ No newline at end of file
+</form>
index e5fb27bb3f0773d63b546e15c00fa5746d453605..c8d3aa2eac102c407bbf0aa6a27f3ce73c7d3ea7 100644 (file)
@@ -26,6 +26,14 @@ Required vars: mailing
           <!-- TODO: attachments -->
         </div>
       </div>
+      <div crm-ui-field crm-title="ts('Attachments')" ng-show="attachments.files.length > 0 || attachments.uploader.queue.length > 0">
+        <div ng-repeat="file in attachments.files">
+          <a ng-href="{{file.url}}" target="_blank">{{file.name}}</a>
+        </div>
+        <div ng-repeat="item in attachments.uploader.queue">
+          {{item.file.name}}
+        </div>
+      </div>
       <div crm-ui-field crm-title="ts('Tracking')">
         <span crm-mailing-review-bool crm-on="mailing.url_tracking=='1'" crm-title="ts('Click Throughs')"></span>
         <span crm-mailing-review-bool crm-on="mailing.open_tracking=='1'" crm-title="ts('Opens')"></span>