CRM-20397 - crmMailingRadioDate - Make the UI less spammy and close it when a good...
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 9 Oct 2017 14:33:12 +0000 (01:33 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 9 Oct 2017 14:33:50 +0000 (01:33 +1100)
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')
                 });