Show:
  1. /**
  2. * The Scheduler Component
  3. *
  4. * @module aui-scheduler
  5. * @submodule aui-scheduler-view-week
  6. */
  7. var Lang = A.Lang,
  8. isFunction = Lang.isFunction,
  9. DateMath = A.DataType.DateMath,
  10. WEEK_LENGTH = DateMath.WEEK_LENGTH;
  11. /**
  12. * A base class for `SchedulerWeekView`.
  13. *
  14. * @class A.SchedulerWeekView
  15. * @extends A.SchedulerDayView
  16. * @param {Object} config Object literal specifying widget configuration
  17. * properties.
  18. * @constructor
  19. */
  20. var SchedulerWeekView = A.Component.create({
  21. /**
  22. * Static property provides a string to identify the class.
  23. *
  24. * @property NAME
  25. * @type {String}
  26. * @static
  27. */
  28. NAME: 'scheduler-view-week',
  29. /**
  30. * Static property used to define the default attribute
  31. * configuration for the `SchedulerWeekView`.
  32. *
  33. * @property ATTRS
  34. * @type {Object}
  35. * @static
  36. */
  37. ATTRS: {
  38. /**
  39. * Determines the content of Scheduler week view's body section.
  40. *
  41. * @attribute bodyContent
  42. * @default ''
  43. * @type {String}
  44. */
  45. bodyContent: {
  46. value: ''
  47. },
  48. /**
  49. * Contains the number of days in a week.
  50. *
  51. * @attribute days
  52. * @default 7
  53. * @type {Number}
  54. */
  55. days: {
  56. value: 7
  57. },
  58. /**
  59. * Configures the header week view.
  60. *
  61. * @attribute headerViewConfig
  62. */
  63. headerViewConfig: {
  64. value: {
  65. displayDaysInterval: WEEK_LENGTH
  66. }
  67. },
  68. /**
  69. * Determines the name for this week view.
  70. *
  71. * @attribute name
  72. * @default 'week'
  73. * @type {String}
  74. */
  75. name: {
  76. value: 'week'
  77. },
  78. /**
  79. * Contains the formatted navigation date formatter for this week view.
  80. *
  81. * @attribute navigationDateFormatter
  82. * @type {Function}
  83. */
  84. navigationDateFormatter: {
  85. valueFn: function() {
  86. return this._valueNavigationDateFormatter;
  87. },
  88. validator: isFunction
  89. }
  90. },
  91. /**
  92. * Static property used to define which component it extends.
  93. *
  94. * @property EXTENDS
  95. * @type {Object}
  96. * @static
  97. */
  98. EXTENDS: A.SchedulerDayView,
  99. prototype: {
  100. /**
  101. * Returns a date value of the first day of the week with its time
  102. * adjusted to midnight.
  103. *
  104. * @method getAdjustedViewDate
  105. * @param {Date} date
  106. * @return {Date}
  107. */
  108. getAdjustedViewDate: function(date) {
  109. var instance = this;
  110. var scheduler = instance.get('scheduler');
  111. var firstDayOfWeek = scheduler.get('firstDayOfWeek');
  112. return DateMath.toMidnight(DateMath.getFirstDayOfWeek(date, firstDayOfWeek));
  113. },
  114. /**
  115. * Returns the value of the date that follows the week view's current
  116. * date.
  117. *
  118. * @method getNextDate
  119. * @return {Date}
  120. */
  121. getNextDate: function() {
  122. var instance = this;
  123. var scheduler = instance.get('scheduler');
  124. var viewDate = DateMath.safeClearTime(scheduler.get('viewDate'));
  125. return DateMath.toLastHour(DateMath.add(viewDate, DateMath.WEEK, 1));
  126. },
  127. /**
  128. * Returns the value of the date that preceeds the week view's current
  129. * date.
  130. *
  131. * @method getPrevDate
  132. * @return {Date}
  133. */
  134. getPrevDate: function() {
  135. var instance = this;
  136. var scheduler = instance.get('scheduler');
  137. var viewDate = scheduler.get('viewDate');
  138. return DateMath.toMidnight(DateMath.subtract(viewDate, DateMath.WEEK, 1));
  139. },
  140. /**
  141. * Returns the value of the week view's current date.
  142. *
  143. * @method getToday
  144. * @return {Date}
  145. */
  146. getToday: function() {
  147. var instance = this;
  148. var todayDate = SchedulerWeekView.superclass.getToday.apply(this, arguments);
  149. return instance._firstDayOfWeek(todayDate);
  150. },
  151. /**
  152. * Returns the value of the first day of week in this view.
  153. *
  154. * @method _firstDayOfWeek
  155. * @param {Date} date
  156. * @return {Date}
  157. * @protected
  158. */
  159. _firstDayOfWeek: function(date) {
  160. var instance = this;
  161. var scheduler = instance.get('scheduler');
  162. var firstDayOfWeek = scheduler.get('firstDayOfWeek');
  163. return DateMath.getFirstDayOfWeek(date, firstDayOfWeek);
  164. },
  165. /**
  166. * Returns a formatted navigation date formatter for this week view.
  167. *
  168. * @method _valueNavigationDateFormatter
  169. * @param {Date} date
  170. * @return {Date}
  171. * @protected
  172. */
  173. _valueNavigationDateFormatter: function(date) {
  174. var instance = this;
  175. var scheduler = instance.get('scheduler');
  176. var locale = scheduler.get('locale');
  177. var startDate = instance._firstDayOfWeek(date);
  178. var startDateLabel = A.DataType.Date.format(
  179. startDate, {
  180. format: '%B %d',
  181. locale: locale
  182. }
  183. );
  184. var endDate = DateMath.add(startDate, DateMath.DAY, instance.get('days') - 1);
  185. var endDateLabel = A.DataType.Date.format(
  186. endDate, {
  187. format: (DateMath.isMonthOverlapWeek(startDate) ? '%B %d' : '%d') + ', %Y',
  188. locale: locale
  189. }
  190. );
  191. return [startDateLabel, '—', endDateLabel].join(' ');
  192. }
  193. }
  194. });
  195. A.SchedulerWeekView = SchedulerWeekView;