From: Tim Otten Date: Tue, 9 Dec 2014 08:16:09 +0000 (-0800) Subject: CRM-15578 - crmMailing2 - Incorporate crmAttachments X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=db083bf01a35bb19a653232622da997c4bdabd9a;p=civicrm-core.git CRM-15578 - crmMailing2 - Incorporate crmAttachments --- diff --git a/js/angular-crmMailing2.js b/js/angular-crmMailing2.js index d75bfbf9fe..e4992b168a 100644 --- a/js/angular-crmMailing2.js +++ b/js/angular-crmMailing2.js @@ -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; @@ -55,8 +55,11 @@ }); }); - 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; @@ -65,14 +68,25 @@ // @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 @@ -204,7 +218,8 @@ // 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}; @@ -237,22 +252,27 @@ 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); }; }); diff --git a/partials/crmMailing2/attachments.html b/partials/crmMailing2/attachments.html index 24728b0144..107e6ae3e7 100644 --- a/partials/crmMailing2/attachments.html +++ b/partials/crmMailing2/attachments.html @@ -1 +1,5 @@ -attachments.html +
+
diff --git a/partials/crmMailing2/edit-unified2.html b/partials/crmMailing2/edit-unified2.html index ca45e37db1..e9bd32c748 100644 --- a/partials/crmMailing2/edit-unified2.html +++ b/partials/crmMailing2/edit-unified2.html @@ -36,4 +36,4 @@ - \ No newline at end of file + diff --git a/partials/crmMailing2/review.html b/partials/crmMailing2/review.html index e5fb27bb3f..c8d3aa2eac 100644 --- a/partials/crmMailing2/review.html +++ b/partials/crmMailing2/review.html @@ -26,6 +26,14 @@ Required vars: mailing +
+
+ {{file.name}} +
+
+ {{item.file.name}} +
+