| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- var RecurringEventDef = EventDef.extend({
- startTime: null, // duration
- endTime: null, // duration, or null
- dowHash: null, // object hash, or null
- isAllDay: function() {
- return !this.startTime && !this.endTime;
- },
- buildInstances: function(start, end) {
- var calendar = this.source.calendar;
- var date = start.clone();
- var instanceStart, instanceEnd;
- var instances = [];
- while (date.isBefore(end)) {
- // if everyday, or this particular day-of-week
- if (!this.dowHash || this.dowHash[date.day()]) {
- instanceStart = date.clone();
- instanceEnd = null;
- if (this.startTime) {
- instanceStart.time(this.startTime);
- }
- else {
- instanceStart.stripTime();
- }
- if (this.endTime) {
- instanceEnd = date.clone().time(this.endTime);
- }
- instances.push(
- new EventInstance(
- this, // definition
- new EventDateProfile(instanceStart, instanceEnd, calendar)
- )
- );
- }
- date.add(1, 'days');
- }
- return instances;
- },
- setDow: function(dowNumbers) {
- if (!this.dowHash) {
- this.dowHash = {};
- }
- for (var i = 0; i < dowNumbers.length; i++) {
- this.dowHash[dowNumbers[i]] = true;
- }
- },
- clone: function() {
- var def = EventDef.prototype.clone.call(this);
- if (def.startTime) {
- def.startTime = moment.duration(this.startTime);
- }
- if (def.endTime) {
- def.endTime = moment.duration(this.endTime);
- }
- if (this.dowHash) {
- def.dowHash = $.extend({}, this.dowHash);
- }
- return def;
- },
- /*
- NOTE: if super-method fails, should still attempt to apply
- */
- applyRawProps: function(rawProps) {
- var superSuccess = EventDef.prototype.applyRawProps.apply(this, arguments);
- if (rawProps.start) {
- this.startTime = moment.duration(rawProps.start);
- }
- if (rawProps.end) {
- this.endTime = moment.duration(rawProps.end);
- }
- if (rawProps.dow) {
- this.setDow(rawProps.dow);
- }
- return superSuccess;
- }
- });
- // Parsing
- // ---------------------------------------------------------------------------------------------------------------------
- RecurringEventDef.defineStandardProps({
- start: false,
- end: false,
- dow: false
- });
|