Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-09-05-18-12-52
[civicrm-core.git] / ang / crmMailingAB / WinnerDialogCtrl.js
CommitLineData
679996bb
TO
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: 'ui-icon-check'},
19 click: function() {
20 crmMailingMgr.mergeInto(abtest.mailings.c, abtest.mailings[mailingName], [
21 'name',
22 'recipients',
23 'scheduled_date'
24 ]);
25 crmStatus({start: ts('Saving...'), success: ''}, abtest.save())
26 .then(function() {
27 return crmStatus({start: ts('Submitting...'), success: ts('Submitted')},
28 abtest.submitFinal().then(function(r) {
29 delete abtest.$CrmMailingABReportCnt;
30 return r;
31 }));
32 })
33 .then(function() {
34 dialogService.close('selectWinnerDialog', abtest);
35 });
36 }
37 },
38 {
39 text: ts('Cancel'),
40 icons: {primary: 'ui-icon-close'},
41 click: function() {
42 dialogService.cancel('selectWinnerDialog');
43 }
44 }
45 ];
46 dialogService.setButtons('selectWinnerDialog', buttons);
47 }
48
49 $timeout(init);
50 });
51
52})(angular, CRM.$, CRM._);