From ce245e838bc9e2bc5cf70163c35efff20d3188fa Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 11 Feb 2015 13:03:29 -0800 Subject: [PATCH] CRM-15855 - crmMailingAB * Fix duplicate autosave * Fix "Submit Mailing" button --- js/angular-crmAutosave.js | 1 + js/angular-crmMailingAB.js | 17 ++++++++--------- js/angular-crmMailingAB/services.js | 4 +++- partials/crmMailingAB/edit.html | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/js/angular-crmAutosave.js b/js/angular-crmAutosave.js index ab80bf799d..8b5a24c56a 100644 --- a/js/angular-crmAutosave.js +++ b/js/angular-crmAutosave.js @@ -62,6 +62,7 @@ } saving = true; + lastSeenModel = angular.copy(scope.$eval(attrs.crmAutosaveModel)); // Set to pristine before saving -- not after saving. // If an eager user continues editing concurrent with the diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index da502bd094..279fb12100 100644 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -63,7 +63,7 @@ $location.replace(); }); - angular.module('crmMailingAB').controller('CrmMailingABEditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr, crmMailingPreviewMgr, crmStatus, $q, $location, crmBlocker) { + angular.module('crmMailingAB').controller('CrmMailingABEditCtrl', function ($scope, abtest, crmMailingABCriteria, crmMailingMgr, crmMailingPreviewMgr, crmStatus, $q, $location, crmBlocker, $interval) { $scope.abtest = abtest; var ts = $scope.ts = CRM.ts(null); var block = $scope.block = crmBlocker(); @@ -117,24 +117,21 @@ } } crmMailingMgr.mergeInto(abtest.mailings.c, abtest.mailings.a, ['name']); - return $q.when(true); + return true; }; // @return Promise $scope.save = function save() { - $scope.sync(); return block(crmStatus({start: ts('Saving...'), success: ts('Saved')}, abtest.save().then(updateUrl))); }; // @return Promise $scope.previewMailing = function previewMailing(mailingName, mode) { - $scope.sync(); return crmMailingPreviewMgr.preview(abtest.mailings[mailingName], mode); }; // @return Promise $scope.sendTest = function sendTest(mailingName, recipient) { - $scope.sync(); return block(crmStatus({start: ts('Saving...'), success: ''}, abtest.save().then(updateUrl)) .then(function () { crmMailingPreviewMgr.sendTest(abtest.mailings[mailingName], recipient); @@ -148,8 +145,7 @@ // @return Promise $scope.submit = function submit() { - $scope.sync(); - if (block.check() || $scope.crmMailing.$invalid) { + if (block.check() || $scope.crmMailingAB.$invalid) { return; } return block(crmStatus({start: ts('Saving...'), success: ''}, abtest.save()) @@ -158,7 +154,7 @@ // 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()...) }) - .then($scope.leave)); + ).then($scope.leave); }; $scope.leave = function leave() { @@ -186,8 +182,11 @@ // initialize updateCriteriaName(); - $scope.sync(); $scope.$watch('abtest.ab.testing_criteria_id', updateCriteriaName); + var syncJob = $interval($scope.sync, 333); + $scope.$on('$destroy', function(){ + $interval.cancel(syncJob); + }); }); angular.module('crmMailingAB').controller('CrmMailingABReportCtrl', function ($scope, abtest, crmApi, crmMailingPreviewMgr, dialogService) { diff --git a/js/angular-crmMailingAB/services.js b/js/angular-crmMailingAB/services.js index e525e97551..08b5362653 100644 --- a/js/angular-crmMailingAB/services.js +++ b/js/angular-crmMailingAB/services.js @@ -117,7 +117,9 @@ .then(function () { return crmApi('MailingAB', 'create', crmMailingAB.ab) .then(function (abResult) { - crmMailingAB.id = crmMailingAB.ab.id = abResult.id; + if (!crmMailingAB.id) { + crmMailingAB.id = crmMailingAB.ab.id = abResult.id; + } }); }) .then(function () { diff --git a/partials/crmMailingAB/edit.html b/partials/crmMailingAB/edit.html index ecc405bac2..ed6d21518f 100644 --- a/partials/crmMailingAB/edit.html +++ b/partials/crmMailingAB/edit.html @@ -13,7 +13,7 @@ {{ts('This mailing has been submitted.')}} -
+
-- 2.25.1