resolve: {
selectedMail: function($route, crmMailingMgr) {
return crmMailingMgr.get($route.current.params.id);
+ },
+ attachments: function($route, CrmAttachments) {
+ var attachments = new CrmAttachments(function () {
+ return {entity_table: 'civicrm_mailing', entity_id: $route.current.params.id};
+ });
+ return attachments.load();
}
}
});
$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, attachments, crmMailingPreviewMgr, crmBlocker) {
$scope.mailing = selectedMail;
- $scope.attachments = new CrmAttachments(function () {
- return {entity_table: 'civicrm_mailing', entity_id: $scope.mailing.id};
- });
- $scope.attachments.load();
+ $scope.attachments = attachments;
$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
$scope.submit = function submit() {
+ if (block.check() || $scope.crmMailing.$invalid) {
+ return;
+ }
+
var promise = crmMailingMgr.save($scope.mailing)
.then(function () {
// pre-condition: the mailing exists *before* saving attachments to it
return crmMailingMgr.submit($scope.mailing);
})
.then(function () {
- leave('scheduled');
+ $scope.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');
+ $scope.leave('unscheduled');
})
- );
+ ));
};
// @param string listingScreen 'archive', 'scheduled', 'unscheduled'
- function leave(listingScreen) {
+ $scope.leave = function leave(listingScreen) {
switch (listingScreen) {
case 'archive':
window.location = CRM.url('civicrm/mailing/browse/archived', {
scheduled: 'false'
});
}
- }
+ };
});
// Controller for the edit-recipients fields (
// When using dialogService with a button bar, the major button actions
// need to be registered with the dialog widget (and not embedded in
// the body of the dialog).
- var buttons = {};
- buttons[ts('Save')] = function () {
- $scope.save().then(function (item) {
- dialogService.close('saveTemplateDialog', item);
- });
- };
- buttons[ts('Cancel')] = function () {
- dialogService.cancel('saveTemplateDialog');
- };
+ var buttons = [
+ {
+ text: ts('Save'),
+ icons: {primary: 'ui-icon-check'},
+ click: function () {
+ $scope.save().then(function (item) {
+ dialogService.close('saveTemplateDialog', item);
+ });
+ }
+ },
+ {
+ text: ts('Cancel'),
+ icons: {primary: 'ui-icon-close'},
+ click: function () {
+ dialogService.cancel('saveTemplateDialog');
+ }
+ }
+ ];
dialogService.setButtons('saveTemplateDialog', buttons);
}