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 @@ ...@@ -8,10 +8,14 @@
*/ */
var ICalCalendar = function(_data) { var ICalCalendar = function(_data) {
var data = {}, var data = {},
attributes = ['domain', 'prodId', 'name', 'description', 'timezone', 'ttl', 'url', 'events'], attributes = ['domain', 'prodId', 'method', 'name', 'description', 'timezone', 'ttl', 'url', 'events'],
vars,
generate, generate,
i; i;
vars = {
allowedMethods: ['PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER']
};
generate = function(calendar) { generate = function(calendar) {
var tools = require('./_tools.js'), var tools = require('./_tools.js'),
...@@ -28,6 +32,11 @@ var ICalCalendar = function(_data) { ...@@ -28,6 +32,11 @@ var ICalCalendar = function(_data) {
g += 'URL:' + data.url + '\r\n'; g += 'URL:' + data.url + '\r\n';
} }
// METHOD
if(data.method) {
g += 'METHOD:' + data.method + '\r\n';
}
// NAME // NAME
if(data.name) { if(data.name) {
g += 'NAME:' + data.name + '\r\n'; g += 'NAME:' + data.name + '\r\n';
...@@ -172,6 +181,31 @@ var ICalCalendar = function(_data) { ...@@ -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… * Set your feed's name…
* *
...@@ -450,6 +484,7 @@ var ICalCalendar = function(_data) { ...@@ -450,6 +484,7 @@ var ICalCalendar = function(_data) {
this.clear = function() { this.clear = function() {
data.domain = require('os').hostname(); data.domain = require('os').hostname();
data.prodid = '//sebbo.net//ical-generator//EN'; data.prodid = '//sebbo.net//ical-generator//EN';
data.method = null;
data.name = null; data.name = null;
data.timezone = null; data.timezone = null;
data.ttl = null; data.ttl = null;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @constructor ICalEvent Event * @constructor ICalEvent Event
*/ */
var ICalEvent = function(_data, calendar) { 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, vars,
i, i,
data; data;
...@@ -17,7 +17,6 @@ var ICalEvent = function(_data, calendar) { ...@@ -17,7 +17,6 @@ var ICalEvent = function(_data, calendar) {
} }
vars = { vars = {
allowedMethods: ['PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER'],
allowedRepeatingFreq: ['SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'], allowedRepeatingFreq: ['SECONDLY', 'MINUTELY', 'HOURLY', 'DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY'],
allowedStatuses: ['CONFIRMED', 'TENATIVE', 'CANCELLED'] allowedStatuses: ['CONFIRMED', 'TENATIVE', 'CANCELLED']
}; };
...@@ -38,7 +37,6 @@ var ICalEvent = function(_data, calendar) { ...@@ -38,7 +37,6 @@ var ICalEvent = function(_data, calendar) {
organizer: null, organizer: null,
attendees: [], attendees: [],
alarms: [], alarms: [],
method: null,
status: null, status: null,
url: null url: null
}; };
...@@ -541,31 +539,6 @@ var ICalEvent = function(_data, calendar) { ...@@ -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 * Set/Get the event's status
* *
...@@ -728,10 +701,7 @@ var ICalEvent = function(_data, calendar) { ...@@ -728,10 +701,7 @@ var ICalEvent = function(_data, calendar) {
g += 'URL;VALUE=URI:' + tools.escape(data.url) + '\r\n'; g += 'URL;VALUE=URI:' + tools.escape(data.url) + '\r\n';
} }
// METHOD & STATUS // STATUS
if(data.method) {
g += 'METHOD:' + data.method.toUpperCase() + '\r\n';
}
if(data.status) { if(data.status) {
g += 'STATUS:' + data.status.toUpperCase() + '\r\n'; 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