X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fangular-crmMailing.js;h=8881051f6d3111cd57f16396bfc35e6d95b97187;hb=269d44f5ba3e707b77d31956f99b5224961a0069;hp=bb58cf4d443e5bf2140de38659e7c234f9cec30b;hpb=8443385df7647353a18a74aa7e5c51d9cc8afcd3;p=civicrm-core.git diff --git a/js/angular-crmMailing.js b/js/angular-crmMailing.js index bb58cf4d44..8881051f6d 100644 --- a/js/angular-crmMailing.js +++ b/js/angular-crmMailing.js @@ -39,6 +39,12 @@ 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(); } } }); @@ -61,15 +67,13 @@ $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; @@ -86,14 +90,18 @@ .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 @@ -103,36 +111,36 @@ 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', { @@ -153,7 +161,7 @@ scheduled: 'false' }); } - } + }; }); // Controller for the edit-recipients fields ( @@ -396,15 +404,24 @@ // 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); }