Commit 4b858afa authored by Sebastian Pekarek's avatar Sebastian Pekarek
Browse files

Merge branch 'develop'

parents d9fb80c7 a827f96e
......@@ -427,6 +427,12 @@ Set the attendee's role, defaults to `REQ-PARTICIPANT`. May be one of the follow
Set the attendee's status. May be one of the following: accepted, tentative, declined
#### type([_String_ type])
Set the attendee's type. May be one of the following: `INDIVIDUAL`, `GROUP`, `RESOURCE`, `ROOM`, `UNKNOWN` (See [Section 4.2.3](https://tools.ietf.org/html/rfc2445#section-4.2.3))
#### delegatesTo(**_ICalAttendee_|_Object_ attendee**)
Creates a new Attendee if passed object is not already an attendee. Will set the delegatedTo and delegatedFrom attributes.
......
......@@ -6,7 +6,7 @@ module.exports.formatDate = function formatDate(d, dateonly, floating) {
var s;
function pad(i) {
return (i < 10 ? '0': '') + i;
return (i < 10 ? '0' : '') + i;
}
s = d.getUTCFullYear();
......
......@@ -158,7 +158,7 @@ var ICalAlarm = function(_data, event) {
return data.attach;
}
var attach= null;
var attach = null;
if(typeof _attach === 'string') {
attach = {
uri: _attach,
......@@ -254,7 +254,7 @@ var ICalAlarm = function(_data, event) {
if(data.type === 'audio' && data.attach && data.attach.mime) {
g += 'ATTACH;FMTTYPE=' + data.attach.mime + ':' + data.attach.uri + '\r\n';
}
else if(data.type === 'audio' && data.attach ) {
else if(data.type === 'audio' && data.attach) {
g += 'ATTACH;VALUE=URI:' + data.attach.uri + '\r\n';
}
else if(data.type === 'audio') {
......
......@@ -16,8 +16,11 @@ var ICalAttendee = function(_data, event) {
}
vars = {
allowedRoles: ['REQ-PARTICIPANT', 'NON-PARTICIPANT'],
allowedStatuses: ['ACCEPTED', 'TENTATIVE', 'DECLINED', 'DELEGATED']
allowed: {
role: ['REQ-PARTICIPANT', 'NON-PARTICIPANT'],
status: ['ACCEPTED', 'TENTATIVE', 'DECLINED', 'DELEGATED'],
type: ['INDIVIDUAL', 'GROUP', 'RESOURCE', 'ROOM', 'UNKNOWN'], // ref: https://tools.ietf.org/html/rfc2445#section-4.2.3
}
};
data = {
......@@ -25,10 +28,39 @@ var ICalAttendee = function(_data, event) {
email: null,
status: null,
role: 'REQ-PARTICIPANT',
type: null,
delegatedTo: null,
delegatedFrom: null
};
function getAllowedRole(str) {
return getAllowedStringFor('role', str);
}
function getAllowedStatus(str) {
return getAllowedStringFor('status', str);
}
function getAllowedType(str) {
return getAllowedStringFor('type', str);
}
function getAllowedStringFor(type, str) {
if(!str || typeof(str) !== 'string') {
throw new Error('Input for `' + type + '` must be a non-empty string. You gave ' + str);
}
str = str.toUpperCase();
if(vars.allowed[type].indexOf(str) === -1) {
throw new Error('`' + type + '` must be one of the following: ' + vars.allowed[type].join(', ') + '!');
}
return str;
}
/**
* Set/Get the attendee's name
*
......@@ -71,15 +103,11 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String}
*/
this.role = function(role) {
if(!role) {
if(role === undefined) {
return data.role;
}
if(vars.allowedRoles.indexOf(role.toUpperCase()) === -1) {
throw '`role` must be one of the following: ' + vars.allowedRoles.join(', ') + '!';
}
data.role = role.toUpperCase();
data.role = getAllowedRole(role);
return this;
};
......@@ -92,15 +120,27 @@ var ICalAttendee = function(_data, event) {
* @returns {ICalAttendee|String}
*/
this.status = function(status) {
if(!status) {
if(status === undefined) {
return data.status;
}
if(vars.allowedStatuses.indexOf(status.toUpperCase()) === -1) {
throw '`status` must be one of the following: ' + vars.allowedStatuses.join(', ') + '!';
}
data.status = getAllowedStatus(status);
return this;
};
data.status = status.toUpperCase();
/**
* Set/Get attendee's type (a.k.a. CUTYPE)
*
* @param {String} type
* @since 0.2.3
* @returns {ICalAttendee|String}
*/
this.type = function(type) {
if(type === undefined) {
return data.type;
}
data.type = getAllowedType(type);
return this;
};
......@@ -188,6 +228,11 @@ var ICalAttendee = function(_data, event) {
// ROLE
g += ';ROLE=' + data.role;
// TYPE
if(data.type) {
g += ';CUTYPE=' + data.type;
}
// PARTSTAT
if(data.status) {
g += ';PARTSTAT=' + data.status;
......@@ -214,10 +259,10 @@ var ICalAttendee = function(_data, event) {
for(i in _data) {
if(_data.hasOwnProperty(i) && ['name', 'email', 'role', 'status', 'delegatedTo', 'delegatedFrom', 'delegatesFrom', 'delegatesTo'].indexOf(i) > -1) {
if(_data.hasOwnProperty(i) && ['name', 'email', 'role', 'status', 'type', 'delegatedTo', 'delegatedFrom', 'delegatesFrom', 'delegatesTo'].indexOf(i) > -1) {
this[i](_data[i]);
}
}
};
module.exports = ICalAttendee;
\ No newline at end of file
module.exports = ICalAttendee;
......@@ -243,7 +243,6 @@ var ICalCalendar = function(_data) {
}
var ICalEvent = require('./event.js'),
e;
......
......@@ -18,7 +18,7 @@ var ICalEvent = function(_data) {
};
data = {
id: ('0000' + (Math.random() * Math.pow(36,4) << 0).toString(36)).substr(-4),
id: ('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).substr(-4),
start: null,
end: null,
stamp: new Date(),
......@@ -501,7 +501,7 @@ var ICalEvent = function(_data) {
if(data.allDay) {
g += 'DTSTART;VALUE=DATE:' + tools.formatDate(data.start, true) + '\r\n';
g += 'DTEND;VALUE=DATE:' + tools.formatDate(data.end, true) + '\r\n';
}else{
} else {
g += 'DTSTART:' + tools.formatDate(data.start, false, data.floating) + '\r\n';
g += 'DTEND:' + tools.formatDate(data.end, false, data.floating) + '\r\n';
}
......@@ -535,7 +535,7 @@ var ICalEvent = function(_data) {
// DESCRIPTION
if(data.description) {
g += 'DESCRIPTION:' + tools.escape(data.description ) + '\r\n';
g += 'DESCRIPTION:' + tools.escape(data.description) + '\r\n';
}
// ORGANIZER
......
......@@ -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.2",
"version": "0.2.3",
"bugs": {
"url": "http://github.com/sebbo2002/ical-generator/issues",
"email": "bugs@sebbo.net"
......
......@@ -1177,11 +1177,18 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
assert.equal(a.role(), 'REQ-PARTICIPANT');
});
it('should throw error when method empty', function() {
var a = ical().createEvent().createAttendee();
assert.throws(function() {
a.role('');
}, /`role` must be a non-empty string/);
});
it('should throw error when method not allowed', function() {
var a = ical().createEvent().createAttendee();
assert.throws(function() {
a.role('COOKING');
}, /`role`/);
}, /`role` must be one of the following/);
});
it('should change something', function() {
......@@ -1208,11 +1215,18 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
assert.equal(a.status(), 'ACCEPTED');
});
it('should throw error when method empty', function() {
var a = ical().createEvent().createAttendee();
assert.throws(function() {
a.status('');
}, /`status` must be a non-empty string/);
});
it('should throw error when method not allowed', function() {
var a = ical().createEvent().createAttendee();
assert.throws(function() {
a.status('DRINKING');
}, /`status`/);
}, /`status` must be one of the following/);
});
it('should change something', function() {
......@@ -1228,6 +1242,44 @@ describe('ical-generator 0.2.x / ICalCalendar', function() {
});
});
describe('type()', function() {
it('setter should return this', function() {
var a = ical().createEvent().createAttendee();
assert.deepEqual(a, a.type('individual'));
});
it('getter should return value', function() {
var a = ical().createEvent().createAttendee().type('room');
assert.equal(a.type(), 'ROOM');
});
it('should throw error when method empty', function() {
var a = ical().createEvent().createAttendee();
assert.throws(function() {
a.type('');
}, /`type` must be a non-empty string/);
});
it('should throw error when method not allowed', function() {
var a = ical().createEvent().createAttendee();
assert.throws(function() {
a.type('DRINKING');
}, /`type` must be one of the following/);
});
it('should change something', function() {
var cal = ical(),
event = cal.createEvent({
start: new Date(),
end: new Date(new Date().getTime() + 3600000),
summary: 'Example Event'
});
event.createAttendee({email: 'mailing-list@example.com', type: 'group'});
assert.ok(cal.toString().indexOf('GROUP') > -1);
});
});
describe('delegatedTo()', function() {
it('setter should return this', function() {
var a = ical().createEvent().createAttendee();
......
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