Merge pull request #11092 from seamuslee001/CRM-20397-popup
authorTim Otten <totten@civicrm.org>
Mon, 9 Oct 2017 19:05:18 +0000 (20:05 +0100)
committerGitHub <noreply@github.com>
Mon, 9 Oct 2017 19:05:18 +0000 (20:05 +0100)
CRM-20397 - crmMailingRadioDate - Make the UI less spammy and close i…

ang/crmMailing/RadioDate.js

index c747f2e275f2673000a3ace185a88aa296b94268..5ed5b204d0b4bcb793e2a2a661a6d801553e2e96 100644 (file)
@@ -5,6 +5,7 @@
     return {
       require: 'ngModel',
       link: function($scope, element, attrs, ngModel) {
+        var lastAlert = null;
 
         var schedule = $scope[attrs.crmMailingRadioDate] = {
           mode: 'now',
               date = [year, month, day].join('-');
               time = [hours, minutes, "00"].join(':');
               currentDate = date + ' ' + time;
-              ngModel.$setValidity('dateTimeInThePast', !($(this).val().length && submittedDate < currentDate));
-              if ($(this).val().length && submittedDate < currentDate) {
-                crmUiAlert({
+              var isInPast = ($(this).val().length && submittedDate < currentDate);
+              ngModel.$setValidity('dateTimeInThePast', !isInPast);
+              if (lastAlert && lastAlert.isOpen) {
+                lastAlert.close();
+              }
+              if (isInPast) {
+                lastAlert = crmUiAlert({
                   text: ts('The scheduled date and time is in the past'),
                   title: ts('Error')
                 });