CRM-15855 - crmMailingAB
authorTim Otten <totten@civicrm.org>
Wed, 11 Feb 2015 21:03:29 +0000 (13:03 -0800)
committerTim Otten <totten@civicrm.org>
Thu, 12 Feb 2015 19:59:17 +0000 (11:59 -0800)
 * Fix duplicate autosave
 * Fix "Submit Mailing" button

js/angular-crmAutosave.js
js/angular-crmMailingAB.js
js/angular-crmMailingAB/services.js
partials/crmMailingAB/edit.html

index ab80bf799d1c0db227a026fd18e93cbf096266d0..8b5a24c56a859748f656f0f53911398a05435787 100644 (file)
@@ -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
index da502bd094ca8e239d0ac369380ec0192978b005..279fb1210036599c780af6849e33cca7f93b55fb 100644 (file)
@@ -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();
         }
       }
       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);
 
     // @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())
             // 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() {
 
     // 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) {
index e525e975519a3750180f804d51bcc5f44876ba8a..08b53626535206c578e1bfbd3dd224e57f02c1ae 100644 (file)
           .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 () {
index ecc405bac2f546ed4a0ad43ed7b03c349e7eee14..ed6d21518fbfb6e3002f4d623605076318f7c1b8 100644 (file)
@@ -13,7 +13,7 @@
   {{ts('This mailing has been submitted.')}}
 </div>
 
-<form name="crmMailingAB" novalidate ng-hide="isSubmitted()" crm-autosave="save()" crm-autosave-model="abtest.getAutosaveSignature()" crm-autosave-if="true">
+<form name="crmMailingAB" novalidate ng-hide="isSubmitted()" crm-autosave="save()" crm-autosave-model="abtest.getAutosaveSignature()" crm-autosave-if="sync()">
   <div class="crm-block crm-form-block crmMailing">
     <div crm-ui-wizard>
       <div crm-ui-wizard-step="10" crm-title="ts('Setup')" ng-form="setupForm">