Shift validation testing to radioDate from crmUI
authorSeamus Lee <seamuslee001@gmail.com>
Thu, 1 Oct 2015 00:49:49 +0000 (00:49 +0000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 16 Oct 2015 23:05:03 +0000 (23:05 +0000)
Minor fixes

ang/crmMailing/RadioDate.js
ang/crmUi.js

index 8be382e3d87a27e749b4d8340fc7c48ff4c536bb..0f0bcdb933423e0bd21b4c042ae2ab5bb66a48be 100644 (file)
@@ -1,7 +1,7 @@
 (function(angular, $, _) {
   // Represent a datetime field as if it were a radio ('schedule.mode') and a datetime ('schedule.datetime').
   // example: <div crm-mailing-radio-date="mySchedule" ng-model="mailing.scheduled_date">...</div>
-  angular.module('crmMailing').directive('crmMailingRadioDate', function() {
+  angular.module('crmMailing').directive('crmMailingRadioDate', function(crmUiAlert) {
     return {
       require: 'ngModel',
       link: function($scope, element, attrs, ngModel) {
             if (context === 'userInput' && $(this).val() === '' && $(this).siblings('.crm-form-date').val().length) {
               schedule.mode = 'at';
               schedule.datetime = '?';
+            } else { 
+              var d = new Date()
+              var submittedDate = $(this).val();
+              console.log(submittedDate);
+              month = '' + (d.getMonth() + 1),
+              day = '' + d.getDate(),
+              year = d.getFullYear();
+              if (month.length < 2) month = '0' + month;
+              if (day.length < 2) day = '0' + day;
+              date = [year, month, day].join('-');
+              hours = '' + (d.getHours()),
+              minutes = '' + (d.getMinutes());
+              time = [hours, minutes, "00"].join(':');
+              currentDate = date + ' ' + time;
+              ngModel.$setValidity('dateTimeInThePast', !($(this).val().length && submittedDate < currentDate));
+              if ($(this).val().length && submittedDate < currentDate) {
+                crmUiAlert({
+                  text: ts('The Scheulded date and time is in the past'),
+                  title: ts('Error')
+                });
+              }
             }
           });
 
index 2c223886df2c54d7a4cbd470dae4aabd2c052e07..448e8809195eb9a387d0bc94debbf13e9e8a0b5e 100644 (file)
                 requiredLength = 8;
               }
               ngModel.$setValidity('incompleteDateTime', !($(this).val().length && $(this).val().length !== requiredLength));
-              var d = new Date(),
-                month = '' + (d.getMonth() + 1),
-                day = '' + d.getDate(),
-                year = d.getFullYear();
-              if (month.length < 2) month = '0' + month;
-              if (day.length < 2) day = '0' + day;
-              currentDate = [year, month, day].join('-');
-              ngModel.$setValidity('dateTimeInThePast', !($(this).val().length && $(this).val() < currentDate));
-              if ($(this).val().length && $(this).val() < currentDate){
-               crmUiAlert({
-                 text: ts('The Scheulded date and time is in the past'),
-                 title: ts('Error')
-               });
-              }
             });
         }
       };