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