Adding additional stuff

This commit is contained in:
Travis Krause
2017-09-14 11:19:37 -05:00
parent 1425bdfad3
commit ce02e5d8a9
+34 -34
View File
@@ -47,7 +47,7 @@ var ics = function( uidDomain, prodId ) {
* @param {string} begin Beginning date of event * @param {string} begin Beginning date of event
* @param {string} stop Ending date of event * @param {string} stop Ending date of event
*/ */
'addEvent': function(subject, description, location, begin, stop, rrule) { 'addEvent': function(subject, description, location, begin, stop, rule) {
// I'm not in the mood to make these optional... So they are all required // I'm not in the mood to make these optional... So they are all required
if (typeof subject === 'undefined' || if (typeof subject === 'undefined' ||
typeof description === 'undefined' || typeof description === 'undefined' ||
@@ -58,47 +58,47 @@ var ics = function( uidDomain, prodId ) {
return false; return false;
} }
// validate rrule // validate rule
if (rrule) { if (rule) {
if (!rrule.rule) { if (!rule.rule) {
if (rrule.freq !== 'YEARLY' && rrule.freq !== 'MONTHLY' && rrule.freq !== 'WEEKLY' && rrule.freq !== 'DAILY') { if (rule.freq !== 'YEARLY' && rule.freq !== 'MONTHLY' && rule.freq !== 'WEEKLY' && rule.freq !== 'DAILY') {
throw "Recurrence rule frequency must be provided and be one of the following: 'YEARLY', 'MONTHLY', 'WEEKLY', or 'DAILY'"; throw "Recurrence rule frequency must be provided and be one of the following: 'YEARLY', 'MONTHLY', 'WEEKLY', or 'DAILY'";
} }
if (rrule.until) { if (rule.until) {
if (isNaN(Date.parse(rrule.until))) { if (isNaN(Date.parse(rule.until))) {
throw "Recurrence rule 'until' must be a valid date string"; throw "Recurrence rule 'until' must be a valid date string";
} }
} }
if (rrule.interval) { if (rule.interval) {
if (isNaN(parseInt(rrule.interval))) { if (isNaN(parseInt(rule.interval))) {
throw "Recurrence rule 'interval' must be an integer"; throw "Recurrence rule 'interval' must be an integer";
} }
} }
if (rrule.count) { if (rule.count) {
if (isNaN(parseInt(rrule.count))) { if (isNaN(parseInt(rule.count))) {
throw "Recurrence rule 'count' must be an integer"; throw "Recurrence rule 'count' must be an integer";
} }
} }
if (typeof rrule.byday !== 'undefined') { if (typeof rule.byday !== 'undefined') {
if ( (Object.prototype.toString.call(rrule.byday) !== '[object Array]') ) { if ((Object.prototype.toString.call(rule.byday) !== '[object Array]')) {
throw "Recurrence rule 'byday' must be an array"; throw "Recurrence rule 'byday' must be an array";
} }
if (rrule.byday.length > 7) { if (rule.byday.length > 7) {
throw "Recurrence rule 'byday' array must not be longer than the 7 days in a week"; throw "Recurrence rule 'byday' array must not be longer than the 7 days in a week";
} }
// Filter any possible repeats // Filter any possible repeats
rrule.byday = rrule.byday.filter(function(elem, pos) { rule.byday = rule.byday.filter(function(elem, pos) {
return rrule.byday.indexOf(elem) == pos; return rule.byday.indexOf(elem) == pos;
}); });
for (var d in rrule.byday) { for (var d in rule.byday) {
if (BYDAY_VALUES.indexOf(rrule.byday[d]) < 0) { if (BYDAY_VALUES.indexOf(rule.byday[d]) < 0) {
throw "Recurrence rule 'byday' values must include only the following: 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'"; throw "Recurrence rule 'byday' values must include only the following: 'SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'";
} }
} }
@@ -146,28 +146,28 @@ var ics = function( uidDomain, prodId ) {
var now = now_year + now_month + now_day + now_time; var now = now_year + now_month + now_day + now_time;
// recurrence rule vars // recurrence rule vars
var rruleString; var ruleString;
if (rrule) { if (rule) {
if (rrule.rule) { if (rule.rule) {
rruleString = rrule.rule; ruleString = rule.rule;
} else { } else {
rruleString = 'RRULE:FREQ=' + rrule.freq; ruleString = 'rule:FREQ=' + rule.freq;
if (rrule.until) { if (rule.until) {
var uDate = new Date(Date.parse(rrule.until)).toISOString(); var uDate = new Date(Date.parse(rule.until)).toISOString();
rruleString += ';UNTIL=' + uDate.substring(0, uDate.length - 13).replace(/[-]/g, '') + '000000Z'; ruleString += ';UNTIL=' + uDate.substring(0, uDate.length - 13).replace(/[-]/g, '') + '000000Z';
} }
if (rrule.interval) { if (rule.interval) {
rruleString += ';INTERVAL=' + rrule.interval; ruleString += ';INTERVAL=' + rule.interval;
} }
if (rrule.count) { if (rule.count) {
rruleString += ';COUNT=' + rrule.count; ruleString += ';COUNT=' + rule.count;
} }
if (rrule.byday && rrule.byday.length > 0) { if (rule.byday && rule.byday.length > 0) {
rruleString += ';BYDAY=' + rrule.byday.join(','); ruleString += ';BYDAY=' + rule.byday.join(',');
} }
} }
} }
@@ -188,8 +188,8 @@ var ics = function( uidDomain, prodId ) {
'END:VEVENT' 'END:VEVENT'
]; ];
if (rruleString) { if (ruleString) {
calendarEvent.splice(4, 0, rruleString); calendarEvent.splice(4, 0, ruleString);
} }
calendarEvent = calendarEvent.join(SEPARATOR); calendarEvent = calendarEvent.join(SEPARATOR);