From: Tim Otten Date: Thu, 19 Feb 2015 02:49:01 +0000 (-0800) Subject: crmMailingAB - Suspend autosave while submitting. Reload after submission. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6877567a2309e9183e5bc5522ee0e5d6547f3971;p=civicrm-core.git crmMailingAB - Suspend autosave while submitting. Reload after submission. --- diff --git a/js/angular-crmAutosave.js b/js/angular-crmAutosave.js index f492cb9739..a697880b8f 100644 --- a/js/angular-crmAutosave.js +++ b/js/angular-crmAutosave.js @@ -18,7 +18,7 @@ // autosave.start(); // $scope.$on('$destroy', autosave.stop); // Note: if the save operation itself - angular.module('crmAutosave').service('CrmAutosaveCtrl', function($interval, $timeout) { + angular.module('crmAutosave').service('CrmAutosaveCtrl', function($interval, $timeout, $q) { function CrmAutosaveCtrl(options) { var intervals = angular.extend({poll: 250, save: 5000}, options.interval); var jobs = {poll: null, save: null}; // job handles used ot cancel/reschedule timeouts/intervals @@ -86,6 +86,8 @@ } } + var self = this; + this.start = function() { if (!jobs.poll) { lastSeenModel = angular.copy(_.isFunction(options.model) ? options.model() : options.model); @@ -103,6 +105,11 @@ jobs.save = null; } }; + + this.suspend = function(p) { + self.stop(); + return p.finally(self.start); + }; } return CrmAutosaveCtrl; diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index 73fc5ae904..91bb7ace4e 100644 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -68,10 +68,12 @@ $location.replace(); }); - angular.module('crmMailingAB').controller('CrmMailingABEditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr, crmMailingPreviewMgr, crmStatus, $q, $location, crmBlocker, $interval, $timeout, CrmAutosaveCtrl) { + angular.module('crmMailingAB').controller('CrmMailingABEditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr, crmMailingPreviewMgr, crmStatus, $q, $location, crmBlocker, $interval, $timeout, CrmAutosaveCtrl, dialogService) { $scope.abtest = abtest; var ts = $scope.ts = CRM.ts(null); var block = $scope.block = crmBlocker(); + $scope.crmUrl = CRM.url; + var myAutosave = null; $scope.crmMailingABCriteria = crmMailingABCriteria; $scope.crmMailingConst = CRM.crmMailing; @@ -153,7 +155,7 @@ } return block(crmStatus({start: ts('Saving...'), success: ''}, abtest.save()) .then(function() { - return crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, abtest.submitTest()); + return crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, myAutosave.suspend(abtest.submitTest())); // Note: We're going to leave, so we don't care that submit() modifies several server-side records. // If we stayed on this page, then we'd care about updating and call: abtest.submitTest().then(...abtest.load()...) }) @@ -165,15 +167,31 @@ $location.replace(); }; + $scope.selectWinner = function selectWinner(mailingName) { + var model = { + abtest: $scope.abtest, + mailingName: mailingName + }; + var options = CRM.utils.adjustDialogDefaults({ + autoOpen: false, + title: ts('Select Winner (%1)', { + 1: mailingName.toUpperCase() + }) + }); + return myAutosave.suspend(dialogService.open('selectWinnerDialog', '~/crmMailingAB/selectWinner.html', model, options)); + }; + // initialize var syncJob = $interval($scope.sync, 333); $scope.$on('$destroy', function(){ $interval.cancel(syncJob); }); - var myAutosave = new CrmAutosaveCtrl({ + myAutosave = new CrmAutosaveCtrl({ save: $scope.save, - saveIf: $scope.sync, + saveIf: function(){ + return abtest.ab.status == 'Draft' && $scope.sync(); + }, model: function(){ return abtest.getAutosaveSignature(); }, @@ -185,7 +203,7 @@ $scope.$on('$destroy', myAutosave.stop); }); - angular.module('crmMailingAB').controller('CrmMailingABReportCtrl', function ($scope, crmApi, crmMailingPreviewMgr, dialogService) { + angular.module('crmMailingAB').controller('CrmMailingABReportCtrl', function ($scope, crmApi, crmMailingStats, crmLegacy) { var ts = $scope.ts = CRM.ts(null); $scope.stats = {}; @@ -198,26 +216,8 @@ crmApi('Mailing', 'stats', {mailing_id: $scope.abtest.ab.mailing_id_c}).then(function(data){ $scope.stats.c = data.values[$scope.abtest.ab.mailing_id_c]; }); - - $scope.previewMailing = function previewMailing(mailingName, mode) { - return crmMailingPreviewMgr.preview(abtest.mailings[mailingName], mode); - }; - $scope.selectWinner = function selectWinner(mailingName) { - var model = { - abtest: $scope.abtest, - mailingName: mailingName - }; - var options = CRM.utils.adjustDialogDefaults({ - autoOpen: false, - title: ts('Select Winner (%1)', { - 1: mailingName.toUpperCase() - }) - }); - return dialogService.open('selectWinnerDialog', '~/crmMailingAB/selectWinner.html', model, options); - }; }); - angular.module('crmMailingAB').controller('CrmMailingABWinnerDialogCtrl', function ($scope, $timeout, dialogService, crmMailingMgr, crmStatus) { var ts = $scope.ts = CRM.ts(null); var abtest = $scope.abtest = $scope.model.abtest; diff --git a/js/angular-crmMailingAB/services.js b/js/angular-crmMailingAB/services.js index 955ba954ce..3b6123fa8a 100644 --- a/js/angular-crmMailingAB/services.js +++ b/js/angular-crmMailingAB/services.js @@ -139,7 +139,7 @@ }; return crmApi('MailingAB', 'submit', params) .then(function () { - return crmMailingAB; + return crmMailingAB.load(); }); }, // Schedule the final mailing