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) {
* @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;
};
......
......@@ -193,11 +193,11 @@ 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;
};
......@@ -210,11 +210,11 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.description = function(description) {
if(!description) {
if(description === undefined) {
return data.description;
}
data.description = description.toString();
data.description = description ? description.toString() : null;
return this;
};
......@@ -262,7 +262,7 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.url = function(url) {
if(!url) {
if(url === undefined) {
return data.url;
}
......@@ -281,7 +281,7 @@ var ICalCalendar = function(_data) {
* @returns {ICalCalendar}
*/
this.ttl = function(ttl) {
if(!ttl) {
if(ttl === undefined) {
return data.ttl;
}
......
......@@ -6,12 +6,16 @@
* @module 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'],
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'],
......@@ -126,10 +130,14 @@ var ICalEvent = function(_data, cal) {
* @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);
}
......@@ -161,11 +169,13 @@ var ICalEvent = function(_data, cal) {
return data.timezone;
}
if(timezone === undefined) {
return cal.timezone();
return calendar.timezone();
}
data.timezone = timezone ? timezone.toString() : null;
if(data.timezone) {
data.floating = false;
}
return this;
};
......@@ -212,7 +222,7 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|Boolean}
*/
this.allDay = function(allDay) {
if(!allDay) {
if(allDay === undefined) {
return data.allDay;
}
......@@ -230,12 +240,14 @@ var ICalEvent = function(_data, cal) {
* @returns {ICalEvent|Boolean}
*/
this.floating = function(floating) {
if(!floating) {
if(floating === undefined) {
return data.floating;
}
data.floating = !!floating;
if(data.floating) {
data.timezone = null;
}
return this;
};
......@@ -248,9 +260,13 @@ var ICalEvent = function(_data, cal) {
* @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(', ') + '!';
......@@ -344,11 +360,11 @@ var ICalEvent = function(_data, cal) {
* @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;
};
......@@ -361,11 +377,11 @@ var ICalEvent = function(_data, cal) {
* @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;
};
......@@ -378,11 +394,11 @@ var ICalEvent = function(_data, cal) {
* @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;
};
......@@ -395,9 +411,13 @@ var ICalEvent = function(_data, cal) {
* @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 = /^(.+) ?<([^>]+)>$/;
......@@ -529,9 +549,13 @@ var ICalEvent = function(_data, cal) {
* @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(', ') + '!';
......@@ -550,9 +574,13 @@ var ICalEvent = function(_data, cal) {
* @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(', ') + '!';
......@@ -571,11 +599,11 @@ var ICalEvent = function(_data, cal) {
* @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;
};
......
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