Commit 3f0d0117 authored by Sebastian's avatar Sebastian
Browse files

Merge branch 'develop'

parents f69806a1 525c1eeb
......@@ -30,8 +30,8 @@ module.exports.formatDate = function formatDate(d, dateonly, floating) {
// For information about this format, see RFC 5545, section 3.3.5
// https://tools.ietf.org/html/rfc5545#section-3.3.5
module.exports.formatDateTZ = function formatDateTZ(property, date, eventData) {
var tzParam = '';
var floating = eventData.floating;
var tzParam = '',
floating = eventData.floating;
if(eventData.timezone) {
tzParam = ';TZID=' + eventData.timezone;
......@@ -106,7 +106,9 @@ module.exports.toJSON = function(object, attributes, options) {
return;
}
var value = object[attribute]();
var value = object[attribute](),
newObj;
if(options.hooks[attribute]) {
value = options.hooks[attribute](value);
}
......@@ -117,7 +119,7 @@ module.exports.toJSON = function(object, attributes, options) {
result[attribute] = value;
if(Array.isArray(result[attribute])) {
var newObj = [];
newObj = [];
result[attribute].forEach(function(object) {
newObj.push(object.toJSON());
});
......
......@@ -38,9 +38,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|String}
*/
this.type = function(type) {
if(!type) {
if(type === undefined) {
return data.type;
}
if(!type) {
data.type = null;
return this;
}
if(vars.types.indexOf(type) === -1) {
throw '`type` is not correct, must be either `display` or `audio`!';
......@@ -59,13 +63,21 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number|Date}
*/
this.trigger = function(trigger) {
if(!trigger && data.trigger instanceof Date) {
if(trigger === undefined && data.trigger instanceof Date) {
return data.trigger;
}
if(!trigger) {
if(trigger === undefined && data.trigger) {
return -1 * data.trigger;
}
if(trigger === undefined) {
return null;
}
if(!trigger) {
data.trigger = null;
return this;
}
if(trigger instanceof Date) {
data.trigger = trigger;
return this;
......@@ -87,7 +99,7 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number|Date}
*/
this.triggerAfter = function(trigger) {
if(!trigger) {
if(trigger === undefined) {
return data.trigger;
}
......@@ -113,9 +125,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number}
*/
this.repeat = function(repeat) {
if(!repeat) {
if(repeat === undefined) {
return data.repeat;
}
if(!repeat) {
data.repeat = null;
return this;
}
if(typeof repeat !== 'number' || !isFinite(repeat)) {
throw '`repeat` is not correct, must be numeric!';
......@@ -134,9 +150,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number|Null}
*/
this.interval = function(interval) {
if(!interval) {
if(interval === undefined) {
return data.interval;
}
if(!interval) {
data.interval = null;
return this;
}
if(typeof interval !== 'number' || !isFinite(interval)) {
throw '`interval` is not correct, must be numeric!';
......@@ -155,9 +175,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Object}
*/
this.attach = function(_attach) {
if(!_attach) {
if(_attach === undefined) {
return data.attach;
}
if(!_attach) {
data.attach = null;
return this;
}
var attach = null;
if(typeof _attach === 'string') {
......@@ -196,9 +220,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|String}
*/
this.description = function(description) {
if(!description) {
if(description === undefined) {
return data.description;
}
if(!description) {
data.description = null;
return this;
}
data.description = description;
return this;
......
......@@ -70,11 +70,11 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String}
*/
this.name = function(name) {
if(!name) {
if(name === undefined) {
return data.name;
}
data.name = name;
data.name = name || null;
return this;
};
......@@ -124,6 +124,10 @@ var ICalAttendee = function(_data, event) {
if(status === undefined) {
return data.status;
}
if(!status) {
data.status = null;
return this;
}
data.status = getAllowedStatus(status);
return this;
......@@ -141,6 +145,10 @@ var ICalAttendee = function(_data, event) {
if(type === undefined) {
return data.type;
}
if(!type) {
data.type = null;
return this;
}
data.type = getAllowedType(type);
return this;
};
......@@ -154,9 +162,16 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String}
*/
this.delegatedTo = function(delegatedTo) {
if(!delegatedTo) {
if(delegatedTo === undefined) {
return data.delegatedTo;
}
if(!delegatedTo) {
data.delegatedTo = null;
if(data.status === 'DELEGATED') {
data.status = null;
}
return this;
}
data.delegatedTo = delegatedTo;
data.status = 'DELEGATED';
......@@ -172,11 +187,11 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String}
*/
this.delegatedFrom = function(delegatedFrom) {
if(!delegatedFrom) {
if(delegatedFrom === undefined) {
return data.delegatedFrom;
}
data.delegatedFrom = delegatedFrom;
data.delegatedFrom = delegatedFrom || null;
return this;
};
......
......@@ -8,7 +8,7 @@
*/
var ICalCalendar = function(_data) {
var data = {},
attributes = ['domain', 'prodId', 'name', 'timezone', 'ttl', 'url', 'events'],
attributes = ['domain', 'prodId', 'name', 'description', 'timezone', 'ttl', 'url', 'events'],
generate,
i;
......@@ -34,6 +34,11 @@ var ICalCalendar = function(_data) {
g += 'X-WR-CALNAME:' + data.name + '\r\n';
}
// Description
if(data.description) {
g += 'X-WR-CALDESC:' + data.description + '\r\n';
}
// Timezone
if(data.timezone) {
g += 'TIMEZONE-ID:' + data.timezone + '\r\n';
......@@ -188,11 +193,28 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.name = function(name) {
if(!name) {
if(name === undefined) {
return data.name;
}
data.name = name.toString();
data.name = name ? name.toString() : null;
return this;
};
/**
* Set/Get your feed's description…
*
* @param [description] Description
* @since 0.2.7
* @returns {ICalCalendar}
*/
this.description = function(description) {
if(description === undefined) {
return data.description;
}
data.description = description ? description.toString() : null;
return this;
};
......@@ -222,11 +244,11 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.timezone = function(timezone) {
if(!timezone) {
if(timezone === undefined) {
return data.timezone;
}
data.timezone = timezone.toString();
data.timezone = timezone ? timezone.toString() : null;
return this;
};
......@@ -240,7 +262,7 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.url = function(url) {
if(!url) {
if(url === undefined) {
return data.url;
}
......@@ -259,7 +281,7 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.ttl = function(ttl) {
if(!ttl) {
if(ttl === undefined) {
return data.ttl;
}
......@@ -296,7 +318,7 @@ var ICalCalendar = function(_data) {
// update errors to 0.1.x version
try {
e = new ICalEvent(event);
e = new ICalEvent(event, this);
}
catch(err) {
throw err.replace(/`([\w.]+)`/i, 'event.$1');
......@@ -316,7 +338,7 @@ var ICalCalendar = function(_data) {
*/
this.createEvent = function(eventData) {
var ICalEvent = require('./event.js'),
event = new ICalEvent(eventData);
event = new ICalEvent(eventData, this);
data.events.push(event);
return event;
......
......@@ -6,12 +6,16 @@
* @module event
* @constructor ICalEvent Event
*/
var ICalEvent = function(_data) {
var ICalEvent = function(_data, calendar) {
var attributes = ['id', 'uid', 'sequence', 'start', 'end', 'timezone', 'stamp', 'timestamp', 'allDay', 'floating', 'repeating', 'summary', 'location', 'description', 'organizer', 'attendees', 'alarms', 'method', 'status', 'url'],
vars,
i,
data;
if(!calendar) {
throw '`calendar` option required!';
}
vars = {
allowedMethods: ['PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER'],
allowedRepeatingFreq: ['SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'],
......@@ -23,7 +27,7 @@ var ICalEvent = function(_data) {
sequence: 0,
start: null,
end: null,
timezone: null,
timezone: undefined,
stamp: new Date(),
allDay: false,
floating: false,
......@@ -126,10 +130,14 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|Date}
*/
this.end = function(end) {
if(!end) {
if(end === undefined) {
return data.end;
}
if(!end) {
data.end = null;
return this;
}
if(typeof end === 'string') {
end = new Date(end);
}
......@@ -157,12 +165,17 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.timezone = function(timezone) {
if(!timezone) {
if(timezone === undefined && data.timezone !== undefined) {
return data.timezone;
}
if(timezone === undefined) {
return calendar.timezone();
}
data.timezone = timezone.toString();
data.floating = false;
data.timezone = timezone ? timezone.toString() : null;
if(data.timezone) {
data.floating = false;
}
return this;
};
......@@ -209,7 +222,7 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|Boolean}
*/
this.allDay = function(allDay) {
if(!allDay) {
if(allDay === undefined) {
return data.allDay;
}
......@@ -227,12 +240,14 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|Boolean}
*/
this.floating = function(floating) {
if(!floating) {
if(floating === undefined) {
return data.floating;
}
data.floating = !!floating;
data.timezone = null;
if(data.floating) {
data.timezone = null;
}
return this;
};
......@@ -245,9 +260,13 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|Object}
*/
this.repeating = function(repeating) {
if(!repeating) {
if(repeating === undefined) {
return data.repeating;
}
if(!repeating) {
data.repeating = null;
return this;
}
if(!repeating.freq || vars.allowedRepeatingFreq.indexOf(repeating.freq.toUpperCase()) === -1) {
throw '`repeating.freq` is a mandatory item, and must be one of the following: ' + vars.allowedRepeatingFreq.join(', ') + '!';
......@@ -341,11 +360,11 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.summary = function(summary) {
if(!summary) {
if(summary === undefined) {
return data.summary;
}
data.summary = summary.toString();
data.summary = summary ? summary.toString() : '';
return this;
};
......@@ -358,11 +377,11 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.location = function(location) {
if(!location) {
if(location === undefined) {
return data.location;
}
data.location = location.toString();
data.location = location ? location.toString() : null;
return this;
};
......@@ -375,11 +394,11 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.description = function(description) {
if(!description) {
if(description === undefined) {
return data.description;
}
data.description = description.toString();
data.description = description ? description.toString() : null;
return this;
};
......@@ -392,9 +411,13 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.organizer = function(_organizer) {
if(!_organizer) {
if(_organizer === undefined) {
return data.organizer;
}
if(!_organizer) {
data.organizer = null;
return this;
}
var organizer = null,
organizerRegEx = /^(.+) ?<([^>]+)>$/;
......@@ -526,9 +549,13 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.method = function(method) {
if(!method) {
if(method === undefined) {
return data.method;
}
if(!method) {
data.method = null;
return this;
}
if(vars.allowedMethods.indexOf(method.toUpperCase()) === -1) {
throw '`method` must be one of the following: ' + vars.allowedMethods.join(', ') + '!';
......@@ -547,9 +574,13 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.status = function(status) {
if(!status) {
if(status === undefined) {
return data.status;
}
if(!status) {
data.status = null;
return this;
}
if(vars.allowedStatuses.indexOf(status.toUpperCase()) === -1) {
throw '`status` must be one of the following: ' + vars.allowedStatuses.join(', ') + '!';
......@@ -568,11 +599,11 @@ var ICalEvent = function(_data) {
* @returns {ICalEvent|String}
*/
this.url = function(url) {
if(!url) {
if(url === undefined) {
return data.url;
}
data.url = url.toString();
data.url = url ? url.toString() : null;
return this;
};
......@@ -606,6 +637,9 @@ var ICalEvent = function(_data) {
if(!data.start) {
throw 'No value for `start` in ICalEvent #' + data.id + ' given!';
}
if(data.timezone) {
data.floating = false;
}
// DATE & TIME
g += 'BEGIN:VEVENT\r\n';
......@@ -620,6 +654,9 @@ var ICalEvent = function(_data) {
if(data.end) {
g += 'DTEND;VALUE=DATE:' + tools.formatDate(data.end, true) + '\r\n';
}
g += 'X-MICROSOFT-CDO-ALLDAYEVENT:TRUE\r\n';
g += 'X-MICROSOFT-MSNCALENDAR-ALLDAYEVENT:TRUE\r\n';
} else {
g += tools.formatDateTZ('DTSTART', data.start, data) + '\r\n';
if(data.end) {
......
......@@ -2,7 +2,7 @@
"name": "ical-generator",
"description": "ical-generator is a small piece of code which generates ical calendar files",
"author": "Sebastian Pekarek <mail@sebbo.net>",
"version": "0.2.5",
"version": "0.2.7",
"bugs": {
"url": "http://github.com/sebbo2002/ical-generator/issues",
"email": "bugs@sebbo.net"
......
......@@ -7,6 +7,8 @@ SEQUENCE:0
DTSTAMP:20131004T233453Z
DTSTART;VALUE=DATE:20131004
DTEND;VALUE=DATE:20131006
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
X-MICROSOFT-MSNCALENDAR-ALLDAYEVENT:TRUE
SUMMARY:Sample Event
ORGANIZER;CN="Sebastian Pekarek":mailto:mail@sebbo.net
URL;VALUE=URI:http://sebbo.net/
......
......@@ -7,6 +7,8 @@ SEQUENCE:0
DTSTAMP:20131004T233453Z
DTSTART;VALUE=DATE:20131004
DTEND;VALUE=DATE:20131006
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
X-MICROSOFT-MSNCALENDAR-ALLDAYEVENT:TRUE
SUMMARY:Sample Event
ORGANIZER;CN="Sebastian Pekarek":mailto:mail@sebbo.net
ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;DELEGATED-FROM="matt@example.com";CN="John":MAILTO:john@example.com
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment