(function (angular, $, _) {
angular.module('crmUtil', []);
+ // Adapter for CRM.status which supports Angular promises (instead of jQuery promises)
+ // example: crmStatus('Saving', crmApi(...)).then(function(result){...})
+ angular.module('crmUtil').factory('crmStatus', function($q){
+ return function(options, aPromise){
+ return CRM.toAPromise($q, CRM.status(options, CRM.toJqPromise(aPromise)));
+ };
+ });
+
// crmWatcher allows one to setup event listeners and temporarily suspend
// them en masse.
//
return CRM.resourceUrls['civicrm'] + '/partials/crmMailing2/' + relPath;
};
- var crmMailing2 = angular.module('crmMailing2', ['ngRoute', 'ui.utils', 'crmUi', 'dialogService']); // TODO ngSanitize, unsavedChanges
+ var crmMailing2 = angular.module('crmMailing2', ['crmUtil', '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, $q) {
+ crmMailing2.controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmFromAddresses, crmStatus) {
$scope.mailing = selectedMail;
$scope.crmMailingConst = CRM.crmMailing;
$scope.crmFromAddresses = crmFromAddresses;
// @return Promise
$scope.submit = function submit() {
- // CRM.status doesn't work with Angular promises, so do backflips
- var p = crmMailingMgr.submit($scope.mailing);
- var p2 = CRM.status(null, CRM.toJqPromise(p));
- return CRM.toAPromise($q, p2);
+ return crmStatus({start: ts('Submitting...'), success: ts('Submitted')},
+ crmMailingMgr.submit($scope.mailing)
+ );
};
// @return Promise
$scope.save = function save() {
- // CRM.status doesn't work with Angular promises, so do backflips
- var p = crmMailingMgr.save($scope.mailing);
- var p2 = CRM.status(null, CRM.toJqPromise(p));
- return CRM.toAPromise($q, p2);
+ return crmStatus(null,
+ crmMailingMgr.save($scope.mailing)
+ );
};
// @return Promise
$scope.delete = function cancel() {
- // CRM.status doesn't work with Angular promises, so do backflips
- var p = crmMailingMgr.delete($scope.mailing);
- var p2 = CRM.status({start: ts('Deleting...'), success: ts('Deleted')}, CRM.toJqPromise(p));
- return CRM.toAPromise($q, p2);
+ return crmStatus({start: ts('Deleting...'), success: ts('Deleted')},
+ crmMailingMgr.delete($scope.mailing)
+ );
};
$scope.leave = function leave() {
window.location = CRM.url('civicrm/mailing/browse/unscheduled', {