From 208ca565a885bc098d7a3b1d31bc7b1aeb8d20b1 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 1 Oct 2015 00:49:49 +0000 Subject: [PATCH] Shift validation testing to radioDate from crmUI Minor fixes --- ang/crmMailing/RadioDate.js | 23 ++++++++++++++++++++++- ang/crmUi.js | 14 -------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ang/crmMailing/RadioDate.js b/ang/crmMailing/RadioDate.js index 8be382e3d8..0f0bcdb933 100644 --- a/ang/crmMailing/RadioDate.js +++ b/ang/crmMailing/RadioDate.js @@ -1,7 +1,7 @@ (function(angular, $, _) { // Represent a datetime field as if it were a radio ('schedule.mode') and a datetime ('schedule.datetime'). // example:
...
- angular.module('crmMailing').directive('crmMailingRadioDate', function() { + angular.module('crmMailing').directive('crmMailingRadioDate', function(crmUiAlert) { return { require: 'ngModel', link: function($scope, element, attrs, ngModel) { @@ -48,6 +48,27 @@ 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') + }); + } } }); diff --git a/ang/crmUi.js b/ang/crmUi.js index 2c223886df..448e880919 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -88,20 +88,6 @@ 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') - }); - } }); } }; -- 2.25.1