Skip to content

Commit

Permalink
Merge pull request civicrm#11 from seamuslee001/CRM-17303-Fuzion
Browse files Browse the repository at this point in the history
Crm 17303 for Fuzion 4.6 repo
  • Loading branch information
eileenmcnaughton committed Oct 18, 2015
2 parents 4bcf889 + e749ee3 commit 6cbbf2f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
22 changes: 21 additions & 1 deletion ang/crmMailing/RadioDate.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -48,6 +48,26 @@
if (context === 'userInput' && $(this).val() === '' && $(this).siblings('.crm-form-date').val().length) {
schedule.mode = 'at';
schedule.datetime = '?';
} else {
var d = new Date(),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear(),
hours = '' + d.getHours(),
minutes = '' + d.getMinutes();
var submittedDate = $(this).val();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
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({
text: ts('The scheduled date and time is in the past'),
title: ts('Error')
});
}
}
});

Expand Down
24 changes: 22 additions & 2 deletions tests/karma/unit/crmMailingRadioDateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,31 @@ describe('crmMailingRadioDate', function() {

model.the_date = '2014-01-02 02:03:00';
$rootScope.$digest();
expect($rootScope.myForm.$valid).toBe(true);
expect($rootScope.myForm.$valid).toBe(false);
expect(element.find('.radio-now').prop('checked')).toBe(false);
expect(element.find('.radio-at').prop('checked')).toBe(true);
expect(element.find('.crm-form-date').datepicker('getDate').toDateString()).toEqual('Thu Jan 02 2014');
expect(element.find('.crm-form-time').timeEntry('getTime').getMinutes()).toBe(3);

var now = new Date();
now.setDate(now.getDate() + 1);
var month = '' + (now.getMonth() + 1);
var day = '' + now.getDate();
var year = now.getFullYear();
var hours = '' + now.getHours();
var minutes = '' + now.getMinutes();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
var datenow = [year, month, day].join('-');
var time = [hours, minutes, "00"].join(':');
var currentDate = datenow + ' ' + time;
var n = now.toDateString();
model.the_date = currentDate;
$rootScope.$digest();
expect($rootScope.myForm.$valid).toBe(true);
expect(element.find('.radio-now').prop('checked')).toBe(false);
expect(element.find('.radio-at').prop('checked')).toBe(true);
expect(element.find('.crm-form-date').datepicker('getDate').toDateString()).toEqual(n);
});

it('should update the model after changing the date and time', function() {
Expand All @@ -107,7 +127,7 @@ describe('crmMailingRadioDate', function() {
element.find('.crm-form-time').timeEntry('setTime', '04:05').trigger('change');
$rootScope.$digest();
expect(model.the_date).toBe('2014-01-03 04:05:00');
expect($rootScope.myForm.$valid).toBe(true);
expect($rootScope.myForm.$valid).toBe(false);
expect(element.find('.radio-now').prop('checked')).toBe(false);
expect(element.find('.radio-at').prop('checked')).toBe(true);

Expand Down

0 comments on commit 6cbbf2f

Please sign in to comment.