RecurringEventDef.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var RecurringEventDef = EventDef.extend({
  2. startTime: null, // duration
  3. endTime: null, // duration, or null
  4. dowHash: null, // object hash, or null
  5. isAllDay: function() {
  6. return !this.startTime && !this.endTime;
  7. },
  8. buildInstances: function(start, end) {
  9. var calendar = this.source.calendar;
  10. var date = start.clone();
  11. var instanceStart, instanceEnd;
  12. var instances = [];
  13. while (date.isBefore(end)) {
  14. // if everyday, or this particular day-of-week
  15. if (!this.dowHash || this.dowHash[date.day()]) {
  16. instanceStart = date.clone();
  17. instanceEnd = null;
  18. if (this.startTime) {
  19. instanceStart.time(this.startTime);
  20. }
  21. else {
  22. instanceStart.stripTime();
  23. }
  24. if (this.endTime) {
  25. instanceEnd = date.clone().time(this.endTime);
  26. }
  27. instances.push(
  28. new EventInstance(
  29. this, // definition
  30. new EventDateProfile(instanceStart, instanceEnd, calendar)
  31. )
  32. );
  33. }
  34. date.add(1, 'days');
  35. }
  36. return instances;
  37. },
  38. setDow: function(dowNumbers) {
  39. if (!this.dowHash) {
  40. this.dowHash = {};
  41. }
  42. for (var i = 0; i < dowNumbers.length; i++) {
  43. this.dowHash[dowNumbers[i]] = true;
  44. }
  45. },
  46. clone: function() {
  47. var def = EventDef.prototype.clone.call(this);
  48. if (def.startTime) {
  49. def.startTime = moment.duration(this.startTime);
  50. }
  51. if (def.endTime) {
  52. def.endTime = moment.duration(this.endTime);
  53. }
  54. if (this.dowHash) {
  55. def.dowHash = $.extend({}, this.dowHash);
  56. }
  57. return def;
  58. },
  59. /*
  60. NOTE: if super-method fails, should still attempt to apply
  61. */
  62. applyRawProps: function(rawProps) {
  63. var superSuccess = EventDef.prototype.applyRawProps.apply(this, arguments);
  64. if (rawProps.start) {
  65. this.startTime = moment.duration(rawProps.start);
  66. }
  67. if (rawProps.end) {
  68. this.endTime = moment.duration(rawProps.end);
  69. }
  70. if (rawProps.dow) {
  71. this.setDow(rawProps.dow);
  72. }
  73. return superSuccess;
  74. }
  75. });
  76. // Parsing
  77. // ---------------------------------------------------------------------------------------------------------------------
  78. RecurringEventDef.defineStandardProps({
  79. start: false,
  80. end: false,
  81. dow: false
  82. });