Commit 28964d98 authored by Jen Huang's avatar Jen Huang
Browse files

move method parameter from event object to calendar object

method paramter should be on the calendar object
http://www.kanzaki.com/docs/ical/method.html
parent 35de7133
......@@ -8,10 +8,14 @@
*/
var ICalCalendar = function(_data) {
var data = {},
attributes = ['domain', 'prodId', 'name', 'description', 'timezone', 'ttl', 'url', 'events'],
attributes = ['domain', 'prodId', 'method', 'name', 'description', 'timezone', 'ttl', 'url', 'events'],
vars,
generate,
i;
vars = {
allowedMethods: ['PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER']
};
generate = function(calendar) {
var tools = require('./_tools.js'),
......@@ -28,6 +32,11 @@ var ICalCalendar = function(_data) {
g += 'URL:' + data.url + '\r\n';
}
// METHOD
if(data.method) {
g += 'METHOD:' + data.method + '\r\n';
}
// NAME
if(data.name) {
g += 'NAME:' + data.name + '\r\n';
......@@ -172,6 +181,31 @@ var ICalCalendar = function(_data) {
};
/**
* Set/Get your feed's method
*
* @param {String} method
* @since 0.2.0
* @returns {ICalEvent|String}
*/
this.method = function(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(', ') + '!';
}
data.method = method.toUpperCase();
return this;
};
/**
* Set your feed's name…
*
......@@ -450,6 +484,7 @@ var ICalCalendar = function(_data) {
this.clear = function() {
data.domain = require('os').hostname();
data.prodid = '//sebbo.net//ical-generator//EN';
data.method = null;
data.name = null;
data.timezone = null;
data.ttl = null;
......
......@@ -7,7 +7,7 @@
* @constructor ICalEvent Event
*/
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'],
var attributes = ['id', 'uid', 'sequence', 'start', 'end', 'timezone', 'stamp', 'timestamp', 'allDay', 'floating', 'repeating', 'summary', 'location', 'description', 'organizer', 'attendees', 'alarms', 'status', 'url'],
vars,
i,
data;
......@@ -17,7 +17,6 @@ var ICalEvent = function(_data, calendar) {
}
vars = {
allowedMethods: ['PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER'],
allowedRepeatingFreq: ['SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'],
allowedStatuses: ['CONFIRMED', 'TENATIVE', 'CANCELLED']
};
......@@ -38,7 +37,6 @@ var ICalEvent = function(_data, calendar) {
organizer: null,
attendees: [],
alarms: [],
method: null,
status: null,
url: null
};
......@@ -541,31 +539,6 @@ var ICalEvent = function(_data, calendar) {
};
/**
* Set/Get the event's method
*
* @param {String} method
* @since 0.2.0
* @returns {ICalEvent|String}
*/
this.method = function(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(', ') + '!';
}
data.method = method.toUpperCase();
return this;
};
/**
* Set/Get the event's status
*
......@@ -728,10 +701,7 @@ var ICalEvent = function(_data, calendar) {
g += 'URL;VALUE=URI:' + tools.escape(data.url) + '\r\n';
}
// METHOD & STATUS
if(data.method) {
g += 'METHOD:' + data.method.toUpperCase() + '\r\n';
}
// STATUS
if(data.status) {
g += 'STATUS:' + data.status.toUpperCase() + '\r\n';
}
......
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