};
});
+ // usage:
+ // var block = $scope.block = crmBlocker();
+ // $scope.save = function() { return block(crmApi('MyEntity','create',...)); };
+ // <button ng-click="save()" ng-disabled="block.check()">Do something</button>
+ 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;
});
$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};
$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;
.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
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'
<div crm-mailing-block-schedule crm-mailing="mailing"/>
</div>
- <button ng-click="submit()">{{ts('Submit Mailing')}}</button>
- <button ng-click="save()">{{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()">{{ts('Delete Draft')}}</button>
+ <button ng-disabled="block.check()" ng-click="submit()">{{ts('Submit Mailing')}}</button>
+ <button ng-disabled="block.check()" ng-click="save()">{{ts('Save Draft')}}</button>
+ <button ng-disabled="block.check()" crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
</div>
</form>
<div crm-mailing-block-schedule crm-mailing="mailing"/>
</div>
- <button ng-click="submit()">{{ts('Submit Mailing')}}</button>
- <button ng-click="save()">{{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()">{{ts('Delete Draft')}}</button>
+ <button ng-disabled="block.check()" ng-click="submit()">{{ts('Submit Mailing')}}</button>
+ <button ng-disabled="block.check()" ng-click="save()">{{ts('Save Draft')}}</button>
+ <button ng-disabled="block.check()" crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
</div>
</form>
<div crm-mailing-block-review crm-mailing="mailing"/>
</div>
<center>
- <a class="crmMailing-submit-button" ng-click="submit()">
+ <a class="crmMailing-submit-button" ng-click="submit()" ng-disabled="block.check()">
<div>{{ts('Submit Mailing')}}</div>
</a>
</center>
</div>
<span crm-ui-wizard-buttons style="float:right;">
- <button crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
- <button ng-click="save()">{{ts('Save Draft')}}</button>
+ <button ng-disabled="block.check()" crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
+ <button ng-disabled="block.check()" ng-click="save()">{{ts('Save Draft')}}</button>
</span>
</div>
</div>
<div crm-mailing-block-schedule crm-mailing="mailing"/>
</div>
<center>
- <a class="crmMailing-submit-button" ng-click="submit()">
+ <a class="crmMailing-submit-button" ng-click="submit()" ng-disabled="block.check()">
<div>{{ts('Submit Mailing')}}</div>
</a>
</center>
</div>
<span crm-ui-wizard-buttons style="float:right;">
- <button crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
- <button ng-click="save()">{{ts('Save Draft')}}</button>
+ <button ng-disabled="block.check()" crm-confirm="{title:ts('Delete Draft?'), message:ts('Are you sure you want to delete the draft mailing?')}" on-yes="delete()">{{ts('Delete Draft')}}</button>
+ <button ng-disabled="block.check()" ng-click="save()">{{ts('Save Draft')}}</button>
</span>
</div>
</div>