| 1 | (function(angular, $, _) { |
| 2 | |
| 3 | angular.module('crmMailingAB').controller('CrmMailingABWinnerDialogCtrl', function($scope, $timeout, dialogService, crmMailingMgr, crmStatus) { |
| 4 | var ts = $scope.ts = CRM.ts(null); |
| 5 | var abtest = $scope.abtest = $scope.model.abtest; |
| 6 | var mailingName = $scope.model.mailingName; |
| 7 | |
| 8 | var titles = {a: ts('Mailing A'), b: ts('Mailing B')}; |
| 9 | $scope.mailingTitle = titles[mailingName]; |
| 10 | |
| 11 | function init() { |
| 12 | // When using dialogService with a button bar, the major button actions |
| 13 | // need to be registered with the dialog widget (and not embedded in |
| 14 | // the body of the dialog). |
| 15 | var buttons = [ |
| 16 | { |
| 17 | text: ts('Submit final mailing'), |
| 18 | icons: {primary: 'fa-paper-plane'}, |
| 19 | click: function() { |
| 20 | crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, |
| 21 | abtest.submitFinal(abtest.mailings[mailingName].id).then(function (r) { |
| 22 | delete abtest.$CrmMailingABReportCnt; |
| 23 | })) |
| 24 | .then(function () { |
| 25 | dialogService.close('selectWinnerDialog', abtest); |
| 26 | }); |
| 27 | } |
| 28 | }, |
| 29 | { |
| 30 | text: ts('Cancel'), |
| 31 | icons: {primary: 'fa-times'}, |
| 32 | click: function() { |
| 33 | dialogService.cancel('selectWinnerDialog'); |
| 34 | } |
| 35 | } |
| 36 | ]; |
| 37 | dialogService.setButtons('selectWinnerDialog', buttons); |
| 38 | } |
| 39 | |
| 40 | $timeout(init); |
| 41 | }); |
| 42 | |
| 43 | })(angular, CRM.$, CRM._); |