Permalink
Browse files

parser works now for VCard components. VCalendar is a completely diff…

…erent story.
  • Loading branch information...
mikedeboer committed Jan 31, 2013
1 parent 5bb55bc commit ddc92a5008767ebc87aba7fee23eae877e8d2dd8
@@ -114,7 +114,7 @@ var jsCardDAV_VCFExportPlugin = module.exports = jsDAV_Plugin.extend({
nodeData = node["200"]["{" + jsCardDAV_Plugin.NS_CARDDAV + "}address-data"];
// Parsing this node so VObject can clean up the output.
- output.push(jsVObject_Reader.read(nodeData).serialize());
+ output.push(jsVObject_Reader.new().read(nodeData).serialize());
}
return output.join("");
View
@@ -7,16 +7,8 @@
*/
"use strict";
-var jsVObject_ElementList = require("./elementList");
var jsVObject_Node = require("./node");
var jsVObject_Property = require("./property");
-var jsVObject_VAlarm = require("./component/VAlarm");
-var jsVObject_VCalendar = require("./component/VCalendar");
-var jsVObject_VCard = require("./component/VCard");
-var jsVObject_VEvent = require("./component/VEvent");
-var jsVObject_VJournal = require("./component/VJournal");
-var jsVObject_VTodo = require("./component/VTodo");
-var jsVObject_VFreeBusy = require("./component/VFreeBusy");
var Exc = require("./../shared/exceptions");
var Util = require("./../shared/util");
@@ -41,7 +33,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
*
* @var array
*/
- children: [],
+ children: null,
/**
* If components are added to this map, they will be automatically mapped
@@ -51,13 +43,13 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
* @var array
*/
classMap: {
- "VALARM" : jsVObject_VAlarm,
- "VCALENDAR" : jsVObject_VCalendar,
- "VCARD" : jsVObject_VCard,
- "VEVENT" : jsVObject_VEvent,
- "VJOURNAL" : jsVObject_VJournal,
- "VTODO" : jsVObject_VTodo,
- "VFREEBUSY" : jsVObject_VFreeBusy
+ "VALARM" : "./component/VAlarm",
+ "VCALENDAR" : "./component/VCalendar",
+ "VCARD" : "./component/VCard",
+ "VEVENT" : "./component/VEvent",
+ "VJOURNAL" : "./component/VJournal",
+ "VTODO" : "./component/VTodo",
+ "VFREEBUSY" : "./component/VFreeBusy"
},
/**
@@ -71,7 +63,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
create: function(name, value) {
name = name.toUpperCase();
if (this.classMap[name])
- return this.classMap[name].new(name, value);
+ return require(this.classMap[name]).new(name, value);
else
return jsVObject_Component.new(name, value);
},
@@ -87,6 +79,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
*/
initialize: function(name, iterator) {
this.name = name.toUpperCase();
+ this.children = [];
if (iterator)
this.iterator = iterator;
},
@@ -177,7 +170,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
*/
add: function(item, itemValue, parameters) {
parameters = parameters || {};
- if (item.hasFeature(jsVObject_Node)) {
+ if (item.hasFeature && item.hasFeature(jsVObject_Node)) {
if (itemValue)
throw new Error("The second argument must not be specified, when passing a VObject Node");
item.parent = this;
@@ -199,7 +192,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
* @return ElementList
*/
getChildren: function() {
- return jsVObject_ElementList.new(this.children);
+ return this.children;
},
/**
@@ -233,7 +226,8 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
child.name.toUpperCase() === name &&
(!group || (child.hasFeature(jsVObject_Property) && child.group.toUpperCase() === group))
) {
- result[key] = child;
+ //result[key] = child;
+ result.push(child);
}
});
@@ -293,15 +287,15 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
* @param string name
* @return Property
*/
- __get: function(name) {
+ get: function(name) {
var matches = this.select(name);
if (matches.length === 0) {
return null;
}
else {
var firstMatch = matches[0];
/** @var firstMatch Property */
- firstMatch.setIterator(jsVObject_ElementList.new(matches));
+ //firstMatch.setIterator(matches);
return firstMatch;
}
},
@@ -312,7 +306,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
* @param string name
* @return bool
*/
- __isset: function(name) {
+ isset: function(name) {
var matches = this.select(name);
return matches.length > 0;
},
@@ -330,11 +324,10 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
* @param mixed value
* @return void
*/
- __set: function(name, value) {
+ set: function(name, value) {
var matches = this.select(name);
var overWrite = matches.length ? this.children.indexOf(matches[0]) : null;
-
- if (value.hasFeature(jsVObject_Component) || value.hasFeature(jsVObject_Property)) {
+ if (value.hasFeature && (value.hasFeature(jsVObject_Component) || value.hasFeature(jsVObject_Property))) {
value.parent = this;
if (overWrite !== null)
this.children[overWrite] = value;
@@ -360,7 +353,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
* @param string name
* @return void
*/
- __unset: function(name) {
+ unset: function(name) {
var matches = this.select(name);
for (var i = matches.length - 1; i >= 0; --i) {
this.children.splice(this.children.indexOf(matches[i]), 1);
@@ -376,7 +369,7 @@ var jsVObject_Component = module.exports = jsVObject_Node.extend({
*
* @return void
*/
- __clone: function() {
+ clone: function() {
for (var i = 0, l = this.children.length; i < l; ++i) {
this.children[i] = this.children[i].clone();
this.children[i].parent = this;
@@ -0,0 +1,108 @@
+/*
+ * @package jsDAV
+ * @subpackage VObject
+ * @copyright Copyright(c) 2013 Mike de Boer. <info AT mikedeboer DOT nl>
+ * @author Mike de Boer <info AT mikedeboer DOT nl>
+ * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
+ */
+"use strict";
+
+var jsVObject_Component = require("./../component");
+console.dir(jsVObject_Component);
+var jsVObject_DateTimeParser = require("./../dateTimeParser");
+
+/**
+ * VAlarm component
+ *
+ * This component contains some additional functionality specific for VALARMs.
+ */
+var jsVObject_Component_VAlarm = module.exports = jsVObject_Component.extend({
+ /**
+ * Returns a DateTime object when this alarm is going to trigger.
+ *
+ * This ignores repeated alarm, only the first trigger is returned.
+ *
+ * @return DateTime
+ */
+ getEffectiveTriggerTime: function() {
+ var trigger = this.TRIGGER;
+ var effectiveTrigger;
+ if (!trigger.VALUE || trigger.VALUE.toUpperCase() == "DURATION") {
+ var triggerDuration = jsVObject_DateTimeParser.parseDuration(this.TRIGGER);
+ var related = (trigger.RELATED && trigger.RELATED.toUpperCase() == "END") ? "END" : "START";
+
+ var parentComponent = this.parent;
+ if (related == "START") {
+ var propName = (parentComponent.name == "VTODO")
+ ? "DUE"
+ : "DTSTART";
+
+ effectiveTrigger = parentComponent[propName].getDateTime().clone();
+ effectiveTrigger.add(triggerDuration);
+ }
+ else {
+ var endProp;
+ if (parentComponent.name == "VTODO")
+ endProp = "DUE";
+ else if (parentComponent.name == "VEVENT")
+ endProp = "DTEND";
+ else
+ throw new Error("time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT");
+
+ if (parentComponent.endProp) {
+ effectiveTrigger = parentComponent[endProp].getDateTime().clone();
+ effectiveTrigger.add(triggerDuration);
+ }
+ else if (parentComponent.DURATION) {
+ effectiveTrigger = parentComponent.DTSTART.getDateTime().clone();
+ var duration = jsVObject_DateTimeParser.parseDuration(parentComponent.DURATION);
+ effectiveTrigger.add(duration);
+ effectiveTrigger.add(triggerDuration);
+ }
+ else {
+ effectiveTrigger = parentComponent.DTSTART.getDateTime().clone();
+ effectiveTrigger.add(triggerDuration);
+ }
+ }
+ }
+ else
+ effectiveTrigger = trigger.getDateTime();
+
+ return effectiveTrigger;
+ },
+
+ /**
+ * Returns true or false depending on if the event falls in the specified
+ * time-range. This is used for filtering purposes.
+ *
+ * The rules used to determine if an event falls within the specified
+ * time-range is based on the CalDAV specification.
+ *
+ * @param Date start
+ * @param Date end
+ * @return bool
+ */
+ isInTimeRange: function(start, end) {
+ var effectiveTrigger = this.getEffectiveTriggerTime();
+
+ if (this.DURATION) {
+ var duration = jsVObject_DateTimeParser.parseDuration(this.DURATION);
+ var repeat = this.repeat.toString();
+ if (!repeat)
+ repeat = 1;
+
+ // TODO translate php DateTime traverse to JS
+ var period = [effectiveTrigger, duration, parseInt(repeat, 10)];
+
+ for (period in occurrence) {
+
+ if (start <= occurrence && end > occurrence) {
+ return true;
+ }
+ }
+ return false;
+ }
+ else
+ return (start <= effectiveTrigger && end > effectiveTrigger);
+ }
+});
Oops, something went wrong.

0 comments on commit ddc92a5

Please sign in to comment.