(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')
+ });
+ }
}
});
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')
- });
- }
});
}
};