From bdd3f7810519cf81e123d0ff3ab20b216f915150 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 23 Jan 2015 19:17:43 -0800 Subject: [PATCH] crmMailing - Block Save/Delete/Submit while saving/deleting/submitting. --- js/angular-crm-util.js | 20 ++++++++++++++++++++ js/angular-crmMailing.js | 17 +++++++++-------- partials/crmMailing/edit-unified.html | 6 +++--- partials/crmMailing/edit-unified2.html | 6 +++--- partials/crmMailing/edit-wizard.html | 6 +++--- partials/crmMailing/edit.html | 6 +++--- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/js/angular-crm-util.js b/js/angular-crm-util.js index 62437f558f..f122c9c8e4 100644 --- a/js/angular-crm-util.js +++ b/js/angular-crm-util.js @@ -34,6 +34,26 @@ }; }); + // usage: + // var block = $scope.block = crmBlocker(); + // $scope.save = function() { return block(crmApi('MyEntity','create',...)); }; + // + angular.module('crmUtil').factory('crmBlocker', function() { + return function() { + var blocks = 0; + var result = function(promise) { + blocks++; + promise.finally(function() { + blocks--; + }); + }; + result.check = function() { + return blocks > 0; + }; + return result; + }; + }); + angular.module('crmUtil').factory('crmLegacy', function() { return CRM; }); diff --git a/js/angular-crmMailing.js b/js/angular-crmMailing.js index bb58cf4d44..d62443a12d 100644 --- a/js/angular-crmMailing.js +++ b/js/angular-crmMailing.js @@ -61,7 +61,7 @@ $location.replace(); }); - angular.module('crmMailing').controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmStatus, CrmAttachments, crmMailingPreviewMgr) { + angular.module('crmMailing').controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmStatus, CrmAttachments, crmMailingPreviewMgr, crmBlocker) { $scope.mailing = selectedMail; $scope.attachments = new CrmAttachments(function () { return {entity_table: 'civicrm_mailing', entity_id: $scope.mailing.id}; @@ -70,6 +70,7 @@ $scope.crmMailingConst = CRM.crmMailing; var ts = $scope.ts = CRM.ts(null); + var block = $scope.block = crmBlocker(); $scope.isSubmitted = function isSubmitted() { return _.size($scope.mailing.jobs) > 0; @@ -86,10 +87,10 @@ .then(function () { return attachments.save(); }); - return crmStatus({start: ts('Saving...'), success: ''}, savePromise) + return block(crmStatus({start: ts('Saving...'), success: ''}, savePromise) .then(function () { crmMailingPreviewMgr.sendTest(mailing, recipient); - }); + })); }; // @return Promise @@ -106,29 +107,29 @@ leave('scheduled'); }) ; - return crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, promise); + return block(crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, promise)); }; // @return Promise $scope.save = function save() { - return crmStatus(null, + return block(crmStatus(null, crmMailingMgr .save($scope.mailing) .then(function () { // pre-condition: the mailing exists *before* saving attachments to it return $scope.attachments.save(); }) - ); + )); }; // @return Promise $scope.delete = function cancel() { - return crmStatus({start: ts('Deleting...'), success: ts('Deleted')}, + return block(crmStatus({start: ts('Deleting...'), success: ts('Deleted')}, crmMailingMgr.delete($scope.mailing) .then(function () { leave('unscheduled'); }) - ); + )); }; // @param string listingScreen 'archive', 'scheduled', 'unscheduled' diff --git a/partials/crmMailing/edit-unified.html b/partials/crmMailing/edit-unified.html index 20611907d6..55e80aaf8f 100644 --- a/partials/crmMailing/edit-unified.html +++ b/partials/crmMailing/edit-unified.html @@ -44,8 +44,8 @@
- - - + + + diff --git a/partials/crmMailing/edit-unified2.html b/partials/crmMailing/edit-unified2.html index 4e06cc7df2..e5ea499445 100644 --- a/partials/crmMailing/edit-unified2.html +++ b/partials/crmMailing/edit-unified2.html @@ -40,8 +40,8 @@
- - - + + + diff --git a/partials/crmMailing/edit-wizard.html b/partials/crmMailing/edit-wizard.html index 124d432dd5..4a8141db09 100644 --- a/partials/crmMailing/edit-wizard.html +++ b/partials/crmMailing/edit-wizard.html @@ -55,15 +55,15 @@
- +
{{ts('Submit Mailing')}}
- - + + diff --git a/partials/crmMailing/edit.html b/partials/crmMailing/edit.html index feb6969f71..9340e37a9f 100644 --- a/partials/crmMailing/edit.html +++ b/partials/crmMailing/edit.html @@ -52,15 +52,15 @@
- +
{{ts('Submit Mailing')}}
- - + + -- 2.25.1