Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added UID control #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion ics.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var ics = function(uidDomain, prodId) {
].join(SEPARATOR);
var calendarEnd = SEPARATOR + 'END:VCALENDAR';
var BYDAY_VALUES = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
var uid = ''; // a holder for the UID parameter for each event
var uid_from_title_and_dates = false; // should we create a new UID from the title arg?

return {
/**
Expand All @@ -38,6 +40,43 @@ var ics = function(uidDomain, prodId) {
'calendar': function() {
return calendarStart + SEPARATOR + calendarEvents.join(SEPARATOR) + calendarEnd;
},

/**
* Sets this.uid to be a passed argument
* @param {string} newUID The UID to store
*/
'setUID': function(newUID) {
this.uid = newUID;

// if we have both the autoUID and setUID, we need to allow the more specific to have higher precedence
this.uid_from_title_and_dates = false;
},

/**
* Retrieves this.uid if it's set, otherwise it grabs the title and dates or the default uid depending on the this.uid_from_title flag
* @param {string} [title_and_dates=]
* @param {string} [default_uid=]
*/
'getUID': function(title_and_dates = '', default_uid = '') {

if (this.uid_from_title_and_dates) {
return title_and_dates;
}

if (this.uid != undefined && this.uid != '') {
return this.uid;
}

return default_uid;
},

/**
* Sets the this.uid_from_title_and_dates flag which allows a new UID for each event generated from the title of the event
* @param {boolean}
*/
'autoUID': function(bool) {
this.uid_from_title_and_dates = bool;
},

/**
* Add event to the calendar
Expand Down Expand Up @@ -176,7 +215,7 @@ var ics = function(uidDomain, prodId) {

var calendarEvent = [
'BEGIN:VEVENT',
'UID:' + calendarEvents.length + "@" + uidDomain,
'UID:' + this.getUID(subject+now+start+end, calendarEvents.length + "@" + uidDomain),
'CLASS:PUBLIC',
'DESCRIPTION:' + description,
'DTSTAMP;VALUE=DATE-TIME:' + now,
Expand Down