CRM-16277 - crmMailingMgr - Strictly serialize write operations
authorTim Otten <totten@civicrm.org>
Thu, 16 Apr 2015 21:59:55 +0000 (14:59 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 17 Apr 2015 00:35:57 +0000 (17:35 -0700)
ang/crmMailing/services.js

index fb9d904c245a67ff6199d3d45e976b08e32cfac2..b0503376dad12ec7b93e6888e5b6db18c45dd570 100644 (file)
@@ -97,7 +97,8 @@
   });
 
   // The crmMailingMgr service provides business logic for loading, saving, previewing, etc
-  angular.module('crmMailing').factory('crmMailingMgr', function ($q, crmApi, crmFromAddresses) {
+  angular.module('crmMailing').factory('crmMailingMgr', function ($q, crmApi, crmFromAddresses, crmQueue) {
+    var qApi = crmQueue(crmApi);
     var pickDefaultMailComponent = function pickDefaultMailComponent(type) {
       var mcs = _.where(CRM.crmMailing.headerfooterList, {
         component_type: type,
       get: function get(id) {
         var crmMailingMgr = this;
         var mailing;
-        return crmApi('Mailing', 'getsingle', {id: id})
+        return qApi('Mailing', 'getsingle', {id: id})
           .then(function (getResult) {
             mailing = getResult;
             return $q.all([
       // @return Promise
       'delete': function (mailing) {
         if (mailing.id) {
-          return crmApi('Mailing', 'delete', {id: mailing.id});
+          return qApi('Mailing', 'delete', {id: mailing.id});
         }
         else {
           var d = $q.defer();
       // @return Promise an object with "subject", "body_text", "body_html"
       preview: function preview(mailing) {
         if (CRM.crmMailing.workflowEnabled && !CRM.checkPerm('create mailings') && !CRM.checkPerm('access CiviMail')) {
-          return crmApi('Mailing', 'preview', {id: mailing.id}).then(function(result) {
+          return qApi('Mailing', 'preview', {id: mailing.id}).then(function(result) {
             return result.values;
           });
         }
             }
           });
           delete params.recipients; // the content was merged in
-          return crmApi('Mailing', 'create', params).then(function(result) {
+          return qApi('Mailing', 'create', params).then(function(result) {
             // changes rolled back, so we don't care about updating mailing
             return result.values[result.id]['api.Mailing.preview'].values;
           });
           }
         });
         delete params.recipients; // the content was merged in
-        return crmApi('Mailing', 'create', params).then(function (recipResult) {
+        return qApi('Mailing', 'create', params).then(function (recipResult) {
           // changes rolled back, so we don't care about updating mailing
           return recipResult.values[recipResult.id]['api.MailingRecipients.get'].values;
         });
 
         delete params.recipients; // the content was merged in
 
-        return crmApi('Mailing', 'create', params).then(function(result) {
+        return qApi('Mailing', 'create', params).then(function(result) {
           if (result.id && !mailing.id) {
             mailing.id = result.id;
           }  // no rollback, so update mailing.id
           approval_date: 'now',
           scheduled_date: mailing.scheduled_date ? mailing.scheduled_date : 'now'
         };
-        return crmApi('Mailing', 'submit', params)
+        return qApi('Mailing', 'submit', params)
           .then(function (result) {
             angular.extend(mailing, result.values[result.id]); // Perhaps we should reload mailing based on result?
             return crmMailingMgr._loadJobs(mailing);
 
         delete params.recipients; // the content was merged in
 
-        return crmApi('Mailing', 'create', params).then(function (result) {
+        return qApi('Mailing', 'create', params).then(function (result) {
           if (result.id && !mailing.id) {
             mailing.id = result.id;
           }  // no rollback, so update mailing.id