Commit db36ac1c authored by Sebastian's avatar Sebastian
Browse files

enable some setters to set fields to null again

parent 73580bbc
...@@ -38,9 +38,13 @@ var ICalAlarm = function(_data, event) { ...@@ -38,9 +38,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|String} * @returns {ICalAlarm|String}
*/ */
this.type = function(type) { this.type = function(type) {
if(!type) { if(type === undefined) {
return data.type; return data.type;
} }
if(!type) {
data.type = null;
return this;
}
if(vars.types.indexOf(type) === -1) { if(vars.types.indexOf(type) === -1) {
throw '`type` is not correct, must be either `display` or `audio`!'; throw '`type` is not correct, must be either `display` or `audio`!';
...@@ -59,13 +63,21 @@ var ICalAlarm = function(_data, event) { ...@@ -59,13 +63,21 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number|Date} * @returns {ICalAlarm|Number|Date}
*/ */
this.trigger = function(trigger) { this.trigger = function(trigger) {
if(!trigger && data.trigger instanceof Date) { if(trigger === undefined && data.trigger instanceof Date) {
return data.trigger; return data.trigger;
} }
if(!trigger) { if(trigger === undefined && data.trigger) {
return -1 * data.trigger; return -1 * data.trigger;
} }
if(trigger === undefined) {
return null;
}
if(!trigger) {
data.trigger = null;
return this;
}
if(trigger instanceof Date) { if(trigger instanceof Date) {
data.trigger = trigger; data.trigger = trigger;
return this; return this;
...@@ -87,7 +99,7 @@ var ICalAlarm = function(_data, event) { ...@@ -87,7 +99,7 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number|Date} * @returns {ICalAlarm|Number|Date}
*/ */
this.triggerAfter = function(trigger) { this.triggerAfter = function(trigger) {
if(!trigger) { if(trigger === undefined) {
return data.trigger; return data.trigger;
} }
...@@ -113,9 +125,13 @@ var ICalAlarm = function(_data, event) { ...@@ -113,9 +125,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number} * @returns {ICalAlarm|Number}
*/ */
this.repeat = function(repeat) { this.repeat = function(repeat) {
if(!repeat) { if(repeat === undefined) {
return data.repeat; return data.repeat;
} }
if(!repeat) {
data.repeat = null;
return this;
}
if(typeof repeat !== 'number' || !isFinite(repeat)) { if(typeof repeat !== 'number' || !isFinite(repeat)) {
throw '`repeat` is not correct, must be numeric!'; throw '`repeat` is not correct, must be numeric!';
...@@ -134,9 +150,13 @@ var ICalAlarm = function(_data, event) { ...@@ -134,9 +150,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Number|Null} * @returns {ICalAlarm|Number|Null}
*/ */
this.interval = function(interval) { this.interval = function(interval) {
if(!interval) { if(interval === undefined) {
return data.interval; return data.interval;
} }
if(!interval) {
data.interval = null;
return this;
}
if(typeof interval !== 'number' || !isFinite(interval)) { if(typeof interval !== 'number' || !isFinite(interval)) {
throw '`interval` is not correct, must be numeric!'; throw '`interval` is not correct, must be numeric!';
...@@ -155,9 +175,13 @@ var ICalAlarm = function(_data, event) { ...@@ -155,9 +175,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|Object} * @returns {ICalAlarm|Object}
*/ */
this.attach = function(_attach) { this.attach = function(_attach) {
if(!_attach) { if(_attach === undefined) {
return data.attach; return data.attach;
} }
if(!_attach) {
data.attach = null;
return this;
}
var attach = null; var attach = null;
if(typeof _attach === 'string') { if(typeof _attach === 'string') {
...@@ -196,9 +220,13 @@ var ICalAlarm = function(_data, event) { ...@@ -196,9 +220,13 @@ var ICalAlarm = function(_data, event) {
* @returns {ICalAlarm|String} * @returns {ICalAlarm|String}
*/ */
this.description = function(description) { this.description = function(description) {
if(!description) { if(description === undefined) {
return data.description; return data.description;
} }
if(!description) {
data.description = null;
return this;
}
data.description = description; data.description = description;
return this; return this;
......
...@@ -70,11 +70,11 @@ var ICalAttendee = function(_data, event) { ...@@ -70,11 +70,11 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String} * @returns {ICalAttendee|String}
*/ */
this.name = function(name) { this.name = function(name) {
if(!name) { if(name === undefined) {
return data.name; return data.name;
} }
data.name = name; data.name = name || null;
return this; return this;
}; };
...@@ -124,6 +124,10 @@ var ICalAttendee = function(_data, event) { ...@@ -124,6 +124,10 @@ var ICalAttendee = function(_data, event) {
if(status === undefined) { if(status === undefined) {
return data.status; return data.status;
} }
if(!status) {
data.status = null;
return this;
}
data.status = getAllowedStatus(status); data.status = getAllowedStatus(status);
return this; return this;
...@@ -141,6 +145,10 @@ var ICalAttendee = function(_data, event) { ...@@ -141,6 +145,10 @@ var ICalAttendee = function(_data, event) {
if(type === undefined) { if(type === undefined) {
return data.type; return data.type;
} }
if(!type) {
data.type = null;
return this;
}
data.type = getAllowedType(type); data.type = getAllowedType(type);
return this; return this;
}; };
...@@ -154,9 +162,16 @@ var ICalAttendee = function(_data, event) { ...@@ -154,9 +162,16 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String} * @returns {ICalAttendee|String}
*/ */
this.delegatedTo = function(delegatedTo) { this.delegatedTo = function(delegatedTo) {
if(!delegatedTo) { if(delegatedTo === undefined) {
return data.delegatedTo; return data.delegatedTo;
} }
if(!delegatedTo) {
data.delegatedTo = null;
if(data.status === 'DELEGATED') {
data.status = null;
}
return this;
}
data.delegatedTo = delegatedTo; data.delegatedTo = delegatedTo;
data.status = 'DELEGATED'; data.status = 'DELEGATED';
...@@ -172,11 +187,11 @@ var ICalAttendee = function(_data, event) { ...@@ -172,11 +187,11 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String} * @returns {ICalAttendee|String}
*/ */
this.delegatedFrom = function(delegatedFrom) { this.delegatedFrom = function(delegatedFrom) {
if(!delegatedFrom) { if(delegatedFrom === undefined) {
return data.delegatedFrom; return data.delegatedFrom;
} }
data.delegatedFrom = delegatedFrom; data.delegatedFrom = delegatedFrom || null;
return this; return this;
}; };
......
...@@ -193,11 +193,11 @@ var ICalCalendar = function(_data) { ...@@ -193,11 +193,11 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar} * @returns {ICalCalendar}
*/ */
this.name = function(name) { this.name = function(name) {
if(!name) { if(name === undefined) {
return data.name; return data.name;
} }
data.name = name.toString(); data.name = name ? name.toString() : null;
return this; return this;
}; };
...@@ -210,11 +210,11 @@ var ICalCalendar = function(_data) { ...@@ -210,11 +210,11 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar} * @returns {ICalCalendar}
*/ */
this.description = function(description) { this.description = function(description) {
if(!description) { if(description === undefined) {
return data.description; return data.description;
} }
data.description = description.toString(); data.description = description ? description.toString() : null;
return this; return this;
}; };
...@@ -262,7 +262,7 @@ var ICalCalendar = function(_data) { ...@@ -262,7 +262,7 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar} * @returns {ICalCalendar}
*/ */
this.url = function(url) { this.url = function(url) {
if(!url) { if(url === undefined) {
return data.url; return data.url;
} }
...@@ -281,7 +281,7 @@ var ICalCalendar = function(_data) { ...@@ -281,7 +281,7 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar} * @returns {ICalCalendar}
*/ */
this.ttl = function(ttl) { this.ttl = function(ttl) {
if(!ttl) { if(ttl === undefined) {
return data.ttl; return data.ttl;
} }
......
...@@ -6,12 +6,16 @@ ...@@ -6,12 +6,16 @@
* @module event * @module event
* @constructor ICalEvent Event * @constructor ICalEvent Event
*/ */
var ICalEvent = function(_data, cal) { 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', 'method', 'status', 'url'],
vars, vars,
i, i,
data; data;
if(!calendar) {
throw '`calendar` option required!';
}
vars = { vars = {
allowedMethods: ['PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER'], 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'],
...@@ -126,10 +130,14 @@ var ICalEvent = function(_data, cal) { ...@@ -126,10 +130,14 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|Date} * @returns {ICalEvent|Date}
*/ */
this.end = function(end) { this.end = function(end) {
if(!end) { if(end === undefined) {
return data.end; return data.end;
} }
if(!end) {
data.end = null;
return this;
}
if(typeof end === 'string') { if(typeof end === 'string') {
end = new Date(end); end = new Date(end);
} }
...@@ -161,11 +169,13 @@ var ICalEvent = function(_data, cal) { ...@@ -161,11 +169,13 @@ var ICalEvent = function(_data, cal) {
return data.timezone; return data.timezone;
} }
if(timezone === undefined) { if(timezone === undefined) {
return cal.timezone(); return calendar.timezone();
} }
data.timezone = timezone ? timezone.toString() : null; data.timezone = timezone ? timezone.toString() : null;
data.floating = false; if(data.timezone) {
data.floating = false;
}
return this; return this;
}; };
...@@ -212,7 +222,7 @@ var ICalEvent = function(_data, cal) { ...@@ -212,7 +222,7 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|Boolean} * @returns {ICalEvent|Boolean}
*/ */
this.allDay = function(allDay) { this.allDay = function(allDay) {
if(!allDay) { if(allDay === undefined) {
return data.allDay; return data.allDay;
} }
...@@ -230,12 +240,14 @@ var ICalEvent = function(_data, cal) { ...@@ -230,12 +240,14 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|Boolean} * @returns {ICalEvent|Boolean}
*/ */
this.floating = function(floating) { this.floating = function(floating) {
if(!floating) { if(floating === undefined) {
return data.floating; return data.floating;
} }
data.floating = !!floating; data.floating = !!floating;
data.timezone = null; if(data.floating) {
data.timezone = null;
}
return this; return this;
}; };
...@@ -248,9 +260,13 @@ var ICalEvent = function(_data, cal) { ...@@ -248,9 +260,13 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|Object} * @returns {ICalEvent|Object}
*/ */
this.repeating = function(repeating) { this.repeating = function(repeating) {
if(!repeating) { if(repeating === undefined) {
return data.repeating; return data.repeating;
} }
if(!repeating) {
data.repeating = null;
return this;
}
if(!repeating.freq || vars.allowedRepeatingFreq.indexOf(repeating.freq.toUpperCase()) === -1) { 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(', ') + '!'; throw '`repeating.freq` is a mandatory item, and must be one of the following: ' + vars.allowedRepeatingFreq.join(', ') + '!';
...@@ -344,11 +360,11 @@ var ICalEvent = function(_data, cal) { ...@@ -344,11 +360,11 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.summary = function(summary) { this.summary = function(summary) {
if(!summary) { if(summary === undefined) {
return data.summary; return data.summary;
} }
data.summary = summary.toString(); data.summary = summary ? summary.toString() : '';
return this; return this;
}; };
...@@ -361,11 +377,11 @@ var ICalEvent = function(_data, cal) { ...@@ -361,11 +377,11 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.location = function(location) { this.location = function(location) {
if(!location) { if(location === undefined) {
return data.location; return data.location;
} }
data.location = location.toString(); data.location = location ? location.toString() : null;
return this; return this;
}; };
...@@ -378,11 +394,11 @@ var ICalEvent = function(_data, cal) { ...@@ -378,11 +394,11 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.description = function(description) { this.description = function(description) {
if(!description) { if(description === undefined) {
return data.description; return data.description;
} }
data.description = description.toString(); data.description = description ? description.toString() : null;
return this; return this;
}; };
...@@ -395,9 +411,13 @@ var ICalEvent = function(_data, cal) { ...@@ -395,9 +411,13 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.organizer = function(_organizer) { this.organizer = function(_organizer) {
if(!_organizer) { if(_organizer === undefined) {
return data.organizer; return data.organizer;
} }
if(!_organizer) {
data.organizer = null;
return this;
}
var organizer = null, var organizer = null,
organizerRegEx = /^(.+) ?<([^>]+)>$/; organizerRegEx = /^(.+) ?<([^>]+)>$/;
...@@ -529,9 +549,13 @@ var ICalEvent = function(_data, cal) { ...@@ -529,9 +549,13 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.method = function(method) { this.method = function(method) {
if(!method) { if(method === undefined) {
return data.method; return data.method;
} }
if(!method) {
data.method = null;
return this;
}
if(vars.allowedMethods.indexOf(method.toUpperCase()) === -1) { if(vars.allowedMethods.indexOf(method.toUpperCase()) === -1) {
throw '`method` must be one of the following: ' + vars.allowedMethods.join(', ') + '!'; throw '`method` must be one of the following: ' + vars.allowedMethods.join(', ') + '!';
...@@ -550,9 +574,13 @@ var ICalEvent = function(_data, cal) { ...@@ -550,9 +574,13 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.status = function(status) { this.status = function(status) {
if(!status) { if(status === undefined) {
return data.status; return data.status;
} }
if(!status) {
data.status = null;
return this;
}
if(vars.allowedStatuses.indexOf(status.toUpperCase()) === -1) { if(vars.allowedStatuses.indexOf(status.toUpperCase()) === -1) {
throw '`status` must be one of the following: ' + vars.allowedStatuses.join(', ') + '!'; throw '`status` must be one of the following: ' + vars.allowedStatuses.join(', ') + '!';
...@@ -571,11 +599,11 @@ var ICalEvent = function(_data, cal) { ...@@ -571,11 +599,11 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|String} * @returns {ICalEvent|String}
*/ */
this.url = function(url) { this.url = function(url) {
if(!url) { if(url === undefined) {
return data.url; return data.url;
} }
data.url = url.toString(); data.url = url ? url.toString() : null;
return this; return this;
}; };
......
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