fix date locale angular scheduler

This commit is contained in:
jlmitch5
2016-08-24 11:39:16 -04:00
committed by GitHub
parent 75f513e591
commit 0baeafa1f1

View File

@@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
* angular-scheruler.js * angular-scheduler.js
* *
* Copyright (c) 2014 Ansible, Inc. * Copyright (c) 2014 Ansible, Inc.
* *
@@ -13,16 +13,32 @@
/* global RRule */ /* global RRule */
'use strict'; (function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
angular.module('underscore',[]) define(['lodash', 'angular', 'jquery', 'jquery-ui', 'moment'], factory);
.factory('_', [ function() { } else if (typeof module === 'object' && module.exports) {
return window._; // Node. Does not work with strict CommonJS, but
}]); // only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('lodash'), require('angular'), require('jquery'), require('jquery-ui'), require('moment'));
angular.module('AngularScheduler', ['underscore']) } else {
// Browser globals (root is window)
root.returnExports = factory(root._, root.angular, root.$, root.$.ui, root.moment);
}
}(this, function(_, angular, $, ui, moment) {
return angular.module('AngularScheduler', ['moment'])
.filter('schedulerDate', function() {
return function(input) {
var date;
if(input === null){
return "";
}else {
date = moment(input);
return date.format('l') + input.slice(input.indexOf(" "));
}
};
})
.constant('AngularScheduler.partials', '/lib/') .constant('AngularScheduler.partials', '/lib/')
.constant('AngularScheduler.useTimezone', false) .constant('AngularScheduler.useTimezone', false)
@@ -30,9 +46,9 @@ angular.module('AngularScheduler', ['underscore'])
// Initialize supporting scope variables and functions. Returns a scheduler object with getString(), // Initialize supporting scope variables and functions. Returns a scheduler object with getString(),
// setString() and inject() methods. // setString() and inject() methods.
.factory('SchedulerInit', ['$log', '$filter', '$timezones', 'LoadLookupValues', 'SetDefaults', 'CreateObject', '_', .factory('SchedulerInit', ['$log', '$filter', '$timezones', 'LoadLookupValues', 'SetDefaults', 'CreateObject',
'AngularScheduler.useTimezone', 'AngularScheduler.showUTCField', 'InRange', 'AngularScheduler.useTimezone', 'AngularScheduler.showUTCField', 'InRange',
function($log, $filter, $timezones, LoadLookupValues, SetDefaults, CreateObject, _, useTimezone, showUTCField, InRange) { function($log, $filter, $timezones, LoadLookupValues, SetDefaults, CreateObject, useTimezone, showUTCField, InRange) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
@@ -63,11 +79,9 @@ angular.module('AngularScheduler', ['underscore'])
if (scope.schedulerStartDt === "" || scope.schedulerStartDt === null || scope.schedulerStartDt === undefined) { if (scope.schedulerStartDt === "" || scope.schedulerStartDt === null || scope.schedulerStartDt === undefined) {
scope.startDateError("Provide a valid start date and time"); scope.startDateError("Provide a valid start date and time");
scope.schedulerUTCTime = ''; scope.schedulerUTCTime = '';
} } else if (!(InRange(scope.schedulerStartHour, 0, 23, 2) && InRange(scope.schedulerStartMinute, 0, 59, 2) && InRange(scope.schedulerStartSecond, 0, 59, 2))) {
else if ( !(InRange(scope.schedulerStartHour, 0, 23, 2) && InRange(scope.schedulerStartMinute, 0, 59, 2) && InRange(scope.schedulerStartSecond, 0, 59, 2)) ) {
scope.scheduler_startTime_error = true; scope.scheduler_startTime_error = true;
} } else {
else {
if (useTimezone) { if (useTimezone) {
scope.resetStartDate(); scope.resetStartDate();
try { try {
@@ -79,19 +93,17 @@ angular.module('AngularScheduler', ['underscore'])
scope.schedulerUTCTime = $filter('schDateStrFix')($timezones.toUTC(dateStr, scope.schedulerTimeZone.name).toISOString()); scope.schedulerUTCTime = $filter('schDateStrFix')($timezones.toUTC(dateStr, scope.schedulerTimeZone.name).toISOString());
scope.scheduler_form_schedulerStartDt_error = false; scope.scheduler_form_schedulerStartDt_error = false;
scope.scheduler_startTime_error = false; scope.scheduler_startTime_error = false;
} } catch (e) {
catch(e) {
scope.startDateError("Provide a valid start date and time"); scope.startDateError("Provide a valid start date and time");
} }
} } else {
else {
scope.scheduler_startTime_error = false; scope.scheduler_startTime_error = false;
scope.scheduler_form_schedulerStartDt_error = false; scope.scheduler_form_schedulerStartDt_error = false;
scope.schedulerUTCTime = $filter('schDateStrFix')(scope.schedulerStartDt + 'T' + scope.schedulerStartHour + ':' + scope.schedulerStartMinute + scope.schedulerUTCTime = $filter('schDateStrFix')(scope.schedulerStartDt + 'T' + scope.schedulerStartHour + ':' + scope.schedulerStartMinute +
':' + scope.schedulerStartSecond + '.000Z'); ':' + scope.schedulerStartSecond + '.000Z');
} }
} }
if (callback){ if (callback) {
callback(); callback();
} }
}; };
@@ -122,8 +134,7 @@ angular.module('AngularScheduler', ['underscore'])
scope.schedulerInterval = 1; scope.schedulerInterval = 1;
scope.schedulerShowInterval = true; scope.schedulerShowInterval = true;
scope.schedulerIntervalLabel = scope.schedulerFrequency.intervalLabel; scope.schedulerIntervalLabel = scope.schedulerFrequency.intervalLabel;
} } else {
else {
scope.schedulerShowInterval = false; scope.schedulerShowInterval = false;
scope.schedulerEnd = scope.endOptions[0]; scope.schedulerEnd = scope.endOptions[0];
} }
@@ -138,8 +149,7 @@ angular.module('AngularScheduler', ['underscore'])
scope.monthlyRepeatChange = function() { scope.monthlyRepeatChange = function() {
if (scope.monthlyRepeatOption !== 'day') { if (scope.monthlyRepeatOption !== 'day') {
$('#monthDay').spinner('disable'); $('#monthDay').spinner('disable');
} } else {
else {
$('#monthDay').spinner('enable'); $('#monthDay').spinner('enable');
} }
}; };
@@ -147,8 +157,7 @@ angular.module('AngularScheduler', ['underscore'])
scope.yearlyRepeatChange = function() { scope.yearlyRepeatChange = function() {
if (scope.yearlyRepeatOption !== 'month') { if (scope.yearlyRepeatOption !== 'month') {
$('#yearlyRepeatDay').spinner('disable'); $('#yearlyRepeatDay').spinner('disable');
} } else {
else {
$('#yearlyRepeatDay').spinner('enable'); $('#yearlyRepeatDay').spinner('enable');
} }
}; };
@@ -157,9 +166,8 @@ angular.module('AngularScheduler', ['underscore'])
// Add or remove day when user clicks checkbox button // Add or remove day when user clicks checkbox button
var i = scope.weekDays.indexOf(day); var i = scope.weekDays.indexOf(day);
if (i >= 0) { if (i >= 0) {
scope.weekDays.splice(i,1); scope.weekDays.splice(i, 1);
} } else {
else {
scope.weekDays.push(day); scope.weekDays.push(day);
} }
$(event.target).blur(); $(event.target).blur();
@@ -204,15 +212,15 @@ angular.module('AngularScheduler', ['underscore'])
if (useTimezone) { if (useTimezone) {
// Build list of timezone <select> element options // Build list of timezone <select> element options
$timezones.getZoneList(scope); $timezones.getZoneList(scope);
} } else {
else {
scope.setDefaults(); scope.setDefaults();
} }
return CreateObject(scope, requireFutureStartTime); return CreateObject(scope, requireFutureStartTime);
}; };
}]) }
])
/** /**
Return an AngularScheduler object we can use to get the RRule result from user input, check if Return an AngularScheduler object we can use to get the RRule result from user input, check if
@@ -241,29 +249,25 @@ angular.module('AngularScheduler', ['underscore'])
options.endDate = scope.schedulerEndDt.replace(/(\d{2})\/(\d{2})\/(\d{4})/, function(match, p1, p2, p3) { options.endDate = scope.schedulerEndDt.replace(/(\d{2})\/(\d{2})\/(\d{4})/, function(match, p1, p2, p3) {
return p3 + '-' + p1 + '-' + p2; return p3 + '-' + p1 + '-' + p2;
}) + 'T' + }) + 'T' +
$filter('schZeroPad')(this.scope.schedulerEndHour,2) + ':' + $filter('schZeroPad')(this.scope.schedulerEndHour, 2) + ':' +
$filter('schZeroPad')(this.scope.schedulerEndMinute,2) + ':' + $filter('schZeroPad')(this.scope.schedulerEndMinute, 2) + ':' +
$filter('schZeroPad')(this.scope.schedulerEndSecond,2)+ 'Z'; $filter('schZeroPad')(this.scope.schedulerEndSecond, 2) + 'Z';
} }
if (this.scope.schedulerFrequency.value === 'weekly') { if (this.scope.schedulerFrequency.value === 'weekly') {
options.weekDays = this.scope.weekDays; options.weekDays = this.scope.weekDays;
} } else if (this.scope.schedulerFrequency.value === 'yearly') {
else if (this.scope.schedulerFrequency.value === 'yearly') {
if (this.scope.yearlyRepeatOption === 'month') { if (this.scope.yearlyRepeatOption === 'month') {
options.month = this.scope.yearlyMonth.value; options.month = this.scope.yearlyMonth.value;
options.monthDay = this.scope.yearlyMonthDay; options.monthDay = this.scope.yearlyMonthDay;
} } else {
else {
options.setOccurrence = this.scope.yearlyOccurrence.value; options.setOccurrence = this.scope.yearlyOccurrence.value;
options.weekDays = this.scope.yearlyWeekDay.value; options.weekDays = this.scope.yearlyWeekDay.value;
options.month = this.scope.yearlyOtherMonth.value; options.month = this.scope.yearlyOtherMonth.value;
} }
} } else if (this.scope.schedulerFrequency.value === 'monthly') {
else if (this.scope.schedulerFrequency.value === 'monthly') {
if (this.scope.monthlyRepeatOption === 'day') { if (this.scope.monthlyRepeatOption === 'day') {
options.monthDay = this.scope.monthDay; options.monthDay = this.scope.monthDay;
} } else {
else {
options.setOccurrence = this.scope.monthlyOccurrence.value; options.setOccurrence = this.scope.monthlyOccurrence.value;
options.weekDays = this.scope.monthlyWeekDay.value; options.weekDays = this.scope.monthlyWeekDay.value;
} }
@@ -297,27 +301,26 @@ angular.module('AngularScheduler', ['underscore'])
scope.rrule_nlp_description = rrule.toText(); scope.rrule_nlp_description = rrule.toText();
scope.dateChoice = 'local'; scope.dateChoice = 'local';
scope.occurrence_list = []; scope.occurrence_list = [];
rrule.all(function(date, i){ rrule.all(function(date, i) {
var local, dt; var local, dt;
if (i < 10) { if (i < 10) {
if (useTimezone) { if (useTimezone) {
dt = $timezones.align(date, scope.schedulerTimeZone.name); dt = $timezones.align(date, scope.schedulerTimeZone.name);
local = $filter('schZeroPad')(dt.getMonth() + 1,2) + '/' + local = $filter('schZeroPad')(dt.getMonth() + 1, 2) + '/' +
$filter('schZeroPad')(dt.getDate(),2) + '/' + dt.getFullYear() + ' ' + $filter('schZeroPad')(dt.getDate(), 2) + '/' + dt.getFullYear() + ' ' +
$filter('schZeroPad')(dt.getHours(),2) + ':' + $filter('schZeroPad')(dt.getHours(), 2) + ':' +
$filter('schZeroPad')(dt.getMinutes(),2) + ':' + $filter('schZeroPad')(dt.getMinutes(), 2) + ':' +
$filter('schZeroPad')(dt.getSeconds(),2) + ' ' + $filter('schZeroPad')(dt.getSeconds(), 2) + ' ' +
dt.getTimezoneAbbreviation(); dt.getTimezoneAbbreviation();
} } else {
else {
local = $filter('date')(date, 'MM/dd/yyyy HH:mm:ss Z'); local = $filter('date')(date, 'MM/dd/yyyy HH:mm:ss Z');
} }
scope.occurrence_list.push({ utc: $filter('schDateStrFix')(date.toISOString()), local: local }); scope.occurrence_list.push({ utc: $filter('schedulerDate')($filter('schDateStrFix')(date.toISOString())), local: $filter('schedulerDate')(local) });
return true; return true;
} }
return false; return false;
}); });
scope.rrule_nlp_description = rrule.toText().replace(/^RRule error.*$/,'Natural language description not available'); scope.rrule_nlp_description = rrule.toText().replace(/^RRule error.*$/, 'Natural language description not available');
scope.rrule = rrule.toString(); scope.rrule = rrule.toString();
} }
}; };
@@ -351,7 +354,7 @@ angular.module('AngularScheduler', ['underscore'])
this.scope.scheduler_yearlyMonthDay_error = true; this.scope.scheduler_yearlyMonthDay_error = true;
validity = false; validity = false;
} }
if ( !(InRange(scope.schedulerStartHour, 0, 23, 2) && InRange(scope.schedulerStartMinute, 0, 59, 2) && InRange(scope.schedulerStartSecond, 0, 59, 2)) ) { if (!(InRange(scope.schedulerStartHour, 0, 23, 2) && InRange(scope.schedulerStartMinute, 0, 59, 2) && InRange(scope.schedulerStartSecond, 0, 59, 2))) {
this.scope.scheduler_startTime_error = true; this.scope.scheduler_startTime_error = true;
validity = false; validity = false;
} }
@@ -379,33 +382,29 @@ angular.module('AngularScheduler', ['underscore'])
now = new Date(); now = new Date();
if (this.useTimezone) { if (this.useTimezone) {
dateStr = now.getFullYear() + '-' + dateStr = now.getFullYear() + '-' +
$filter('schZeroPad')(now.getMonth() + 1, 2)+ '-' + $filter('schZeroPad')(now.getMonth() + 1, 2) + '-' +
$filter('schZeroPad')(now.getDate(),2) + 'T' + $filter('schZeroPad')(now.getDate(), 2) + 'T' +
$filter('schZeroPad')(now.getHours(),2) + ':' + $filter('schZeroPad')(now.getHours(), 2) + ':' +
$filter('schZeroPad')(now.getMinutes(),2) + ':' + $filter('schZeroPad')(now.getMinutes(), 2) + ':' +
$filter('schZeroPad')(now.getSeconds(),2) + '.000Z'; $filter('schZeroPad')(now.getSeconds(), 2) + '.000Z';
adjNow = $timezones.toUTC(dateStr, this.scope.schedulerTimeZone.name); //Adjust to the selected TZ adjNow = $timezones.toUTC(dateStr, this.scope.schedulerTimeZone.name); //Adjust to the selected TZ
timeNow = adjNow.getTime(); timeNow = adjNow.getTime();
} } else {
else {
timeNow = now.getTime(); timeNow = now.getTime();
} }
if (this.requireFutureStartTime && timeNow >= timeFuture) { if (this.requireFutureStartTime && timeNow >= timeFuture) {
this.scope.startDateError("Start time must be in the future"); this.scope.startDateError("Start time must be in the future");
validity = false; validity = false;
} }
} } else {
else {
this.scope.startDateError("Invalid start time"); this.scope.startDateError("Invalid start time");
validity = false; validity = false;
} }
} } catch (e) {
catch(e) {
this.scope.startDateError("Invalid start time"); this.scope.startDateError("Invalid start time");
validity = false; validity = false;
} }
} } else {
else {
this.scope.startDateError("Provide a start time"); this.scope.startDateError("Provide a start time");
validity = false; validity = false;
} }
@@ -491,9 +490,10 @@ angular.module('AngularScheduler', ['underscore'])
}; };
return new fn(); return new fn();
}; };
}]) }
])
.factory('InRange', [ function() { .factory('InRange', [function() {
return function(x, min, max, length) { return function(x, min, max, length) {
var rx = new RegExp("\\d{1," + length + "}"); var rx = new RegExp("\\d{1," + length + "}");
if (!rx.test(x)) { if (!rx.test(x)) {
@@ -526,11 +526,11 @@ angular.module('AngularScheduler', ['underscore'])
}); });
$http({ method: 'GET', url: scheduler_partial + 'angular-scheduler.html' }) $http({ method: 'GET', url: scheduler_partial + 'angular-scheduler.html' })
.success( function(data) { .success(function(data) {
scope.$emit('htmlReady', data); scope.$emit('htmlReady', data);
}) })
.error( function(data, status) { .error(function(data, status) {
throw('Error reading ' + scheduler_partial + 'angular-scheduler.html. ' + status); throw ('Error reading ' + scheduler_partial + 'angular-scheduler.html. ' + status);
//$log.error('Error calling ' + scheduler_partial + '. ' + status); //$log.error('Error calling ' + scheduler_partial + '. ' + status);
}); });
}; };
@@ -555,11 +555,11 @@ angular.module('AngularScheduler', ['underscore'])
}); });
$http({ method: 'GET', url: scheduler_partial + 'angular-scheduler-detail.html' }) $http({ method: 'GET', url: scheduler_partial + 'angular-scheduler-detail.html' })
.success( function(data) { .success(function(data) {
scope.$emit('htmlDetailReady', data); scope.$emit('htmlDetailReady', data);
}) })
.error( function(data, status) { .error(function(data, status) {
throw('Error reading ' + scheduler_partial + 'angular-scheduler-detail.html. ' + status); throw ('Error reading ' + scheduler_partial + 'angular-scheduler-detail.html. ' + status);
//$log.error('Error calling ' + scheduler_partial + '. ' + status); //$log.error('Error calling ' + scheduler_partial + '. ' + status);
}); });
}; };
@@ -580,16 +580,15 @@ angular.module('AngularScheduler', ['underscore'])
monthDay = params.monthDay, // integer, optional, between 1 and 31 monthDay = params.monthDay, // integer, optional, between 1 and 31
weekDays = params.weekDays, // integer, optional, valid value from weekdays weekDays = params.weekDays, // integer, optional, valid value from weekdays
setOccurrence = params.setOccurrence, // integer, optional, valid value from occurrences setOccurrence = params.setOccurrence, // integer, optional, valid value from occurrences
options = {}, i; options = {},
i;
if (angular.isDate(startDate)) { if (angular.isDate(startDate)) {
options.dtstart = startDate; options.dtstart = startDate;
} } else {
else {
try { try {
options.dtstart = new Date(startDate); options.dtstart = new Date(startDate);
} } catch (e) {
catch(e) {
$log.error('Date conversion failed. Attempted to convert ' + startDate + ' to Date. ' + e.message); $log.error('Date conversion failed. Attempted to convert ' + startDate + ' to Date. ' + e.message);
} }
} }
@@ -604,7 +603,7 @@ angular.module('AngularScheduler', ['underscore'])
if (weekDays && angular.isArray(weekDays)) { if (weekDays && angular.isArray(weekDays)) {
options.byweekday = []; options.byweekday = [];
for (i=0; i < weekDays.length; i++) { for (i = 0; i < weekDays.length; i++) {
options.byweekday.push(RRule[weekDays[i].toUpperCase()]); options.byweekday.push(RRule[weekDays[i].toUpperCase()]);
} }
} }
@@ -623,22 +622,18 @@ angular.module('AngularScheduler', ['underscore'])
if (occurrenceCount) { if (occurrenceCount) {
options.count = occurrenceCount; options.count = occurrenceCount;
} } else if (endDate) {
else if (endDate) {
if (angular.isDate(endDate)) { if (angular.isDate(endDate)) {
options.until = endDate; options.until = endDate;
} } else {
else {
try { try {
options.until = new Date(endDate); options.until = new Date(endDate);
} } catch (e) {
catch(e) {
$log.error('Date conversion failed. Attempted to convert ' + endDate + ' to Date. ' + e.message); $log.error('Date conversion failed. Attempted to convert ' + endDate + ' to Date. ' + e.message);
} }
} }
} }
} } else {
else {
// We only want to run 1x // We only want to run 1x
options.freq = RRule.DAILY; options.freq = RRule.DAILY;
options.interval = 1; options.interval = 1;
@@ -648,10 +643,11 @@ angular.module('AngularScheduler', ['underscore'])
}; };
}]) }])
.factory('SetRule', ['AngularScheduler.useTimezone', '_', '$log', '$timezones', '$filter', .factory('SetRule', ['AngularScheduler.useTimezone', '$log', '$timezones', '$filter',
function(useTimezone, _, $log, $timezones, $filter) { function(useTimezone, $log, $timezones, $filter) {
return function(rule, scope) { return function(rule, scope) {
var set, result = '', i, var set, result = '',
i,
setStartDate = false; setStartDate = false;
// Search the set of RRule keys for a particular key, returning its value // Search the set of RRule keys for a particular key, returning its value
@@ -698,11 +694,10 @@ angular.module('AngularScheduler', ['underscore'])
} }
} }
if (key === 'INTERVAL') { if (key === 'INTERVAL') {
if (parseInt(value,10)) { if (parseInt(value, 10)) {
scope.schedulerInterval = parseInt(value,10); scope.schedulerInterval = parseInt(value, 10);
scope.schedulerShowInterval = true; scope.schedulerShowInterval = true;
} } else {
else {
result = 'INTERVAL must contain an integer > 0'; result = 'INTERVAL must contain an integer > 0';
} }
} }
@@ -710,24 +705,21 @@ angular.module('AngularScheduler', ['underscore'])
if (getValue(set, 'FREQ') === 'WEEKLY') { if (getValue(set, 'FREQ') === 'WEEKLY') {
days = value.split(/,/); days = value.split(/,/);
scope.weekDays = []; scope.weekDays = [];
for (j=0; j < days.length; j++) { for (j = 0; j < days.length; j++) {
if (_.contains(['SU','MO','TU','WE','TH','FR','SA'], days[j])) { if (_.contains(['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'], days[j])) {
scope.weekDays.push(days[j].toLowerCase()); scope.weekDays.push(days[j].toLowerCase());
scope['weekDay' + days[j].toUpperCase() + 'Class'] = 'active'; //activate related button scope['weekDay' + days[j].toUpperCase() + 'Class'] = 'active'; //activate related button
} } else {
else {
result = 'BYDAY contains unrecognized day value(s)'; result = 'BYDAY contains unrecognized day value(s)';
} }
} }
} } else if (getValue(set, 'FREQ') === 'MONTHLY') {
else if (getValue(set, 'FREQ') === 'MONTHLY') {
scope.monthlyRepeatOption = 'other'; scope.monthlyRepeatOption = 'other';
scope.monthlyWeekDay = toWeekDays(value); scope.monthlyWeekDay = toWeekDays(value);
if (!scope.monthlyWeekDay) { if (!scope.monthlyWeekDay) {
result = 'BYDAY contains unrecognized day value(s)'; result = 'BYDAY contains unrecognized day value(s)';
} }
} } else {
else {
scope.yearlyRepeatOption = 'other'; scope.yearlyRepeatOption = 'other';
scope.yearlyWeekDay = toWeekDays(value); scope.yearlyWeekDay = toWeekDays(value);
if (!scope.yearlyWeekDay) { if (!scope.yearlyWeekDay) {
@@ -736,11 +728,10 @@ angular.module('AngularScheduler', ['underscore'])
} }
} }
if (key === 'BYMONTHDAY') { if (key === 'BYMONTHDAY') {
if (parseInt(value,10) && parseInt(value,10) > 0 && parseInt(value,10) < 32) { if (parseInt(value, 10) && parseInt(value, 10) > 0 && parseInt(value, 10) < 32) {
scope.monthDay = parseInt(value,10); scope.monthDay = parseInt(value, 10);
scope.monhthlyRepeatOption = 'day'; scope.monhthlyRepeatOption = 'day';
} } else {
else {
result = 'BYMONTHDAY must contain an integer between 1 and 31'; result = 'BYMONTHDAY must contain an integer between 1 and 31';
} }
} }
@@ -750,8 +741,8 @@ angular.module('AngularScheduler', ['underscore'])
if (/\d{8}T\d{6}.*Z/.test(value)) { if (/\d{8}T\d{6}.*Z/.test(value)) {
// date may come in without separators. add them so new Date constructor will work // date may come in without separators. add them so new Date constructor will work
value = value.replace(/(\d{4})(\d{2})(\d{2}T)(\d{2})(\d{2})(\d{2}.*$)/, value = value.replace(/(\d{4})(\d{2})(\d{2}T)(\d{2})(\d{2})(\d{2}.*$)/,
function(match, p1, p2, p3, p4,p5,p6) { function(match, p1, p2, p3, p4, p5, p6) {
return p1 + '-' + p2 + '-' + p3 + p4 + ':' + p5 + ':' + p6.substr(0,2) + 'Z'; return p1 + '-' + p2 + '-' + p3 + p4 + ':' + p5 + ':' + p6.substr(0, 2) + 'Z';
}); });
} }
if (useTimezone) { if (useTimezone) {
@@ -759,20 +750,19 @@ angular.module('AngularScheduler', ['underscore'])
month = $filter('schZeroPad')(dt.getMonth() + 1, 2); month = $filter('schZeroPad')(dt.getMonth() + 1, 2);
day = $filter('schZeroPad')(dt.getDate(), 2); day = $filter('schZeroPad')(dt.getDate(), 2);
scope.schedulerStartDt = month + '/' + day + '/' + dt.getFullYear(); scope.schedulerStartDt = month + '/' + day + '/' + dt.getFullYear();
scope.schedulerStartHour = $filter('schZeroPad')(dt.getHours(),2); scope.schedulerStartHour = $filter('schZeroPad')(dt.getHours(), 2);
scope.schedulerStartMinute = $filter('schZeroPad')(dt.getMinutes(),2); scope.schedulerStartMinute = $filter('schZeroPad')(dt.getMinutes(), 2);
scope.schedulerStartSecond = $filter('schZeroPad')(dt.getSeconds(),2); scope.schedulerStartSecond = $filter('schZeroPad')(dt.getSeconds(), 2);
scope.scheduleTimeChange(); // calc UTC scope.scheduleTimeChange(); // calc UTC
} } else {
else {
// expects inbound dates to be in ISO format: 2014-04-02T00:00:00.000Z // expects inbound dates to be in ISO format: 2014-04-02T00:00:00.000Z
scope.schedulerStartDt = value.replace(/T.*$/,'').replace(/(\d{4})-(\d{2})-(\d{2})/, function(match, p1, p2, p3) { scope.schedulerStartDt = value.replace(/T.*$/, '').replace(/(\d{4})-(\d{2})-(\d{2})/, function(match, p1, p2, p3) {
return p2 + '/' + p3 + '/' + p1; return p2 + '/' + p3 + '/' + p1;
}); });
timeString = value.replace(/^.*T/,''); timeString = value.replace(/^.*T/, '');
scope.schedulerStartHour = $filter('schZeroPad')(timeString.substr(0,2),2); scope.schedulerStartHour = $filter('schZeroPad')(timeString.substr(0, 2), 2);
scope.schedulerStartMinute = $filter('schZeroPad')(timeString.substr(3,2),2); scope.schedulerStartMinute = $filter('schZeroPad')(timeString.substr(3, 2), 2);
scope.schedulerStartSecond = $filter('schZeroPad')(timeString.substr(6,2),2); scope.schedulerStartSecond = $filter('schZeroPad')(timeString.substr(6, 2), 2);
} }
scope.scheduleTimeChange(); scope.scheduleTimeChange();
} }
@@ -780,15 +770,14 @@ angular.module('AngularScheduler', ['underscore'])
if (getValue(set, 'FREQ') === 'YEARLY') { if (getValue(set, 'FREQ') === 'YEARLY') {
scope.yearlRepeatOption = 'other'; scope.yearlRepeatOption = 'other';
scope.yearlyOccurrence = _.find(scope.occurrences, function(x) { scope.yearlyOccurrence = _.find(scope.occurrences, function(x) {
return (x.value === parseInt(value,10)); return (x.value === parseInt(value, 10));
}); });
if (!scope.yearlyOccurrence || !scope.yearlyOccurrence.name) { if (!scope.yearlyOccurrence || !scope.yearlyOccurrence.name) {
result = 'BYSETPOS was not in the set of 1,2,3,4,-1'; result = 'BYSETPOS was not in the set of 1,2,3,4,-1';
} }
} } else {
else {
scope.monthlyOccurrence = _.find(scope.occurrences, function(x) { scope.monthlyOccurrence = _.find(scope.occurrences, function(x) {
return (x.value === parseInt(value,10)); return (x.value === parseInt(value, 10));
}); });
if (!scope.monthlyOccurrence || !scope.monthlyOccurrence.name) { if (!scope.monthlyOccurrence || !scope.monthlyOccurrence.name) {
result = 'BYSETPOS was not in the set of 1,2,3,4,-1'; result = 'BYSETPOS was not in the set of 1,2,3,4,-1';
@@ -797,11 +786,10 @@ angular.module('AngularScheduler', ['underscore'])
} }
if (key === 'COUNT') { if (key === 'COUNT') {
if (parseInt(value,10)) { if (parseInt(value, 10)) {
scope.schedulerEnd = scope.endOptions[1]; scope.schedulerEnd = scope.endOptions[1];
scope.schedulerOccurrenceCount = parseInt(value,10); scope.schedulerOccurrenceCount = parseInt(value, 10);
} } else {
else {
result = "COUNT must be a valid integer > 0"; result = "COUNT must be a valid integer > 0";
} }
} }
@@ -810,34 +798,33 @@ angular.module('AngularScheduler', ['underscore'])
if (/\d{8}T\d{6}.*Z/.test(value)) { if (/\d{8}T\d{6}.*Z/.test(value)) {
// date may come in without separators. add them so new Date constructor will work // date may come in without separators. add them so new Date constructor will work
value = value.replace(/(\d{4})(\d{2})(\d{2}T)(\d{2})(\d{2})(\d{2}.*$)/, value = value.replace(/(\d{4})(\d{2})(\d{2}T)(\d{2})(\d{2})(\d{2}.*$)/,
function(match, p1, p2, p3, p4,p5,p6) { function(match, p1, p2, p3, p4, p5, p6) {
return p1 + '-' + p2 + '-' + p3 + p4 + ':' + p5 + ':' + p6.substr(0,2) + 'Z'; return p1 + '-' + p2 + '-' + p3 + p4 + ':' + p5 + ':' + p6.substr(0, 2) + 'Z';
}); });
} }
scope.schedulerEnd = scope.endOptions[2]; scope.schedulerEnd = scope.endOptions[2];
scope.schedulerEndDt = value.replace(/T.*$/,'').replace(/(\d{4})-(\d{2})-(\d{2})/, function(match, p1, p2, p3) { scope.schedulerEndDt = value.replace(/T.*$/, '').replace(/(\d{4})-(\d{2})-(\d{2})/, function(match, p1, p2, p3) {
return p2 + '/' + p3 + '/' + p1; return p2 + '/' + p3 + '/' + p1;
}); });
timeString = value.replace(/^.*T/,''); timeString = value.replace(/^.*T/, '');
scope.schedulerEndHour = $filter('schZeroPad')(timeString.substr(0,2),2); scope.schedulerEndHour = $filter('schZeroPad')(timeString.substr(0, 2), 2);
scope.schedulerEndMinute = $filter('schZeroPad')(timeString.substr(3,2),2); scope.schedulerEndMinute = $filter('schZeroPad')(timeString.substr(3, 2), 2);
scope.schedulerEndSecond = $filter('schZeroPad')(timeString.substr(6,2),2); scope.schedulerEndSecond = $filter('schZeroPad')(timeString.substr(6, 2), 2);
} }
if (key === 'BYMONTH') { if (key === 'BYMONTH') {
if (getValue(set, 'FREQ') === 'YEARLY' && getValue(set, 'BYDAY')) { if (getValue(set, 'FREQ') === 'YEARLY' && getValue(set, 'BYDAY')) {
scope.yearlRepeatOption = 'other'; scope.yearlRepeatOption = 'other';
scope.yearlyOtherMonth = _.find(scope.months, function(x) { scope.yearlyOtherMonth = _.find(scope.months, function(x) {
return x.value === parseInt(value,10); return x.value === parseInt(value, 10);
}); });
if (!scope.yearlyOtherMonth || !scope.yearlyOtherMonth.name) { if (!scope.yearlyOtherMonth || !scope.yearlyOtherMonth.name) {
result = 'BYMONTH must be an integer between 1 and 12'; result = 'BYMONTH must be an integer between 1 and 12';
} }
} } else {
else {
scope.yearlyOption = 'month'; scope.yearlyOption = 'month';
scope.yearlyMonth = _.find(scope.months, function(x) { scope.yearlyMonth = _.find(scope.months, function(x) {
return x.value === parseInt(value,10); return x.value === parseInt(value, 10);
}); });
if (!scope.yearlyMonth || !scope.yearlyMonth.name) { if (!scope.yearlyMonth || !scope.yearlyMonth.name) {
result = 'BYMONTH must be an integer between 1 and 12'; result = 'BYMONTH must be an integer between 1 and 12';
@@ -846,10 +833,9 @@ angular.module('AngularScheduler', ['underscore'])
} }
if (key === 'BYMONTHDAY') { if (key === 'BYMONTHDAY') {
if (parseInt(value,10)) { if (parseInt(value, 10)) {
scope.yearlyMonthDay = parseInt(value,10); scope.yearlyMonthDay = parseInt(value, 10);
} } else {
else {
result = 'BYMONTHDAY must be an integer between 1 and 31'; result = 'BYMONTHDAY must be an integer between 1 and 31';
} }
} }
@@ -869,7 +855,7 @@ angular.module('AngularScheduler', ['underscore'])
if (rule) { if (rule) {
set = rule.split(/;/); set = rule.split(/;/);
if (angular.isArray(set)) { if (angular.isArray(set)) {
for (i=0; i < set.length; i++) { for (i = 0; i < set.length; i++) {
setValue(set[i], set); setValue(set[i], set);
if (result) { if (result) {
break; break;
@@ -878,12 +864,10 @@ angular.module('AngularScheduler', ['underscore'])
if (!result) { if (!result) {
isValid(); isValid();
} }
} } else {
else {
result = 'No rule entered. Provide a valid RRule string.'; result = 'No rule entered. Provide a valid RRule string.';
} }
} } else {
else {
result = 'No rule entered. Provide a valid RRule string.'; result = 'No rule entered. Provide a valid RRule string.';
} }
if (result) { if (result) {
@@ -891,7 +875,8 @@ angular.module('AngularScheduler', ['underscore'])
} }
return result; return result;
}; };
}]) }
])
.factory('SetDefaults', ['$filter', function($filter) { .factory('SetDefaults', ['$filter', function($filter) {
return function(scope) { return function(scope) {
@@ -938,7 +923,7 @@ angular.module('AngularScheduler', ['underscore'])
}; };
}]) }])
.factory('LoadLookupValues', [ function() { .factory('LoadLookupValues', [function() {
return function(scope) { return function(scope) {
scope.frequencyOptions = [ scope.frequencyOptions = [
@@ -997,15 +982,15 @@ angular.module('AngularScheduler', ['underscore'])
}]) }])
// $filter('schZeroPad')(n, pad) -- or -- {{ n | afZeroPad:pad }} // $filter('schZeroPad')(n, pad) -- or -- {{ n | afZeroPad:pad }}
.filter('schZeroPad', [ function() { .filter('schZeroPad', [function() {
return function (n, pad) { return function(n, pad) {
var str = (Math.pow(10,pad) + '').replace(/^1/,'') + (n + '').trim(); var str = (Math.pow(10, pad) + '').replace(/^1/, '') + (n + '').trim();
return str.substr(str.length - pad); return str.substr(str.length - pad);
}; };
}]) }])
// $filter('schdateStrFix')(s) where s is a date string in ISO format: yyyy-mm-ddTHH:MM:SS.sssZ. Returns string in format: mm/dd/yyyy HH:MM:SS UTC // $filter('schdateStrFix')(s) where s is a date string in ISO format: yyyy-mm-ddTHH:MM:SS.sssZ. Returns string in format: mm/dd/yyyy HH:MM:SS UTC
.filter('schDateStrFix', [ function() { .filter('schDateStrFix', [function() {
return function(dateStr) { return function(dateStr) {
return dateStr.replace(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*Z/, function(match, yy, mm, dd, hh, mi, ss) { return dateStr.replace(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*Z/, function(match, yy, mm, dd, hh, mi, ss) {
return mm + '/' + dd + '/' + yy + ' ' + hh + ':' + mi + ':' + ss + ' UTC'; return mm + '/' + dd + '/' + yy + ' ' + hh + ':' + mi + ':' + ss + ' UTC';
@@ -1013,7 +998,7 @@ angular.module('AngularScheduler', ['underscore'])
}; };
}]) }])
.directive('schTooltip', [ function() { .directive('schTooltip', [function() {
return { return {
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
var placement = (attrs.placement) ? attrs.placement : 'top'; var placement = (attrs.placement) ? attrs.placement : 'top';
@@ -1028,7 +1013,7 @@ angular.module('AngularScheduler', ['underscore'])
}; };
}]) }])
.directive('schDatePicker', [ function() { .directive('schDatePicker', [function() {
return { return {
require: 'ngModel', require: 'ngModel',
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
@@ -1042,7 +1027,7 @@ angular.module('AngularScheduler', ['underscore'])
options.changeMonth = (attrs.changeMonth === "false") ? false : true; options.changeMonth = (attrs.changeMonth === "false") ? false : true;
options.changeYear = (attrs.changeYear === "false") ? false : true; options.changeYear = (attrs.changeYear === "false") ? false : true;
options.beforeShow = function() { options.beforeShow = function() {
setTimeout(function(){ setTimeout(function() {
$('.ui-datepicker').css('z-index', 9999); $('.ui-datepicker').css('z-index', 9999);
}, 100); }, 100);
}; };
@@ -1061,7 +1046,7 @@ angular.module('AngularScheduler', ['underscore'])
zeroPad = attr.zeroPad, zeroPad = attr.zeroPad,
min = attr.min || 1, min = attr.min || 1,
max = attr.max || 999; max = attr.max || 999;
$(element).spinner({ element.spinner({
min: min, min: min,
max: max, max: max,
stop: function() { stop: function() {
@@ -1069,10 +1054,9 @@ angular.module('AngularScheduler', ['underscore'])
setTimeout(function() { setTimeout(function() {
scope.$apply(function() { scope.$apply(function() {
if (zeroPad) { if (zeroPad) {
scope[attr.ngModel] = $filter('schZeroPad')($(element).spinner('value'),zeroPad); scope[attr.ngModel] = $filter('schZeroPad')(element.spinner('value'), zeroPad);
} } else {
else { scope[attr.ngModel] = element.spinner('value');
scope[attr.ngModel] = $(element).spinner('value');
} }
if (attr.ngChange) { if (attr.ngChange) {
scope.$eval(attr.ngChange); scope.$eval(attr.ngChange);
@@ -1090,9 +1074,11 @@ angular.module('AngularScheduler', ['underscore'])
} }
}); });
$(element).on("click", function () { $(element).on("click", function() {
$(element).select(); $(element).select();
}); });
} }
}; };
}]); }]);
}));