X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fangular-crmMailing.js;h=8881051f6d3111cd57f16396bfc35e6d95b97187;hb=269d44f5ba3e707b77d31956f99b5224961a0069;hp=d62443a12d2efb74a2bca7c6394534f0585377b3;hpb=bdd3f7810519cf81e123d0ff3ab20b216f915150;p=civicrm-core.git diff --git a/js/angular-crmMailing.js b/js/angular-crmMailing.js index d62443a12d..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,12 +67,9 @@ $location.replace(); }); - angular.module('crmMailing').controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmStatus, CrmAttachments, crmMailingPreviewMgr, crmBlocker) { + 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); @@ -95,6 +98,10 @@ // @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 @@ -104,7 +111,7 @@ return crmMailingMgr.submit($scope.mailing); }) .then(function () { - leave('scheduled'); + $scope.leave('scheduled'); }) ; return block(crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, promise)); @@ -127,13 +134,13 @@ 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', { @@ -154,7 +161,7 @@ scheduled: 'false' }); } - } + }; }); // Controller for the edit-recipients fields ( @@ -397,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); }