Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VCalendar.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. // Styles
  3. // import '../../stylus/components/_calendar-daily.styl'
  4. // Mixins
  5. import CalendarBase from './mixins/calendar-base';
  6. // Util
  7. import props from './util/props';
  8. import { DAYS_IN_MONTH_MAX, DAY_MIN, DAYS_IN_WEEK, parseTimestamp, relativeDays, nextDay, prevDay, copyTimestamp, updateFormatted, updateWeekday, updateRelative, getStartOfMonth, getEndOfMonth } from './util/timestamp';
  9. // Calendars
  10. import VCalendarMonthly from './VCalendarMonthly';
  11. import VCalendarDaily from './VCalendarDaily';
  12. import VCalendarWeekly from './VCalendarWeekly';
  13. /* @vue/component */
  14. export default CalendarBase.extend({
  15. name: 'v-calendar',
  16. props: _extends({}, props.calendar, props.weeks, props.intervals),
  17. data: function data() {
  18. return {
  19. lastStart: null,
  20. lastEnd: null
  21. };
  22. },
  23. computed: {
  24. parsedValue: function parsedValue() {
  25. return parseTimestamp(this.value) || this.parsedStart || this.times.today;
  26. },
  27. renderProps: function renderProps() {
  28. var around = this.parsedValue;
  29. var component = 'div';
  30. var maxDays = this.maxDays;
  31. var start = around;
  32. var end = around;
  33. switch (this.type) {
  34. case 'month':
  35. component = VCalendarMonthly;
  36. start = getStartOfMonth(around);
  37. end = getEndOfMonth(around);
  38. break;
  39. case 'week':
  40. component = VCalendarDaily;
  41. start = this.getStartOfWeek(around);
  42. end = this.getEndOfWeek(around);
  43. maxDays = 7;
  44. break;
  45. case 'day':
  46. component = VCalendarDaily;
  47. maxDays = 1;
  48. break;
  49. case '4day':
  50. component = VCalendarDaily;
  51. end = relativeDays(copyTimestamp(end), nextDay, 4);
  52. updateFormatted(end);
  53. maxDays = 4;
  54. break;
  55. case 'custom-weekly':
  56. component = VCalendarWeekly;
  57. start = this.parsedStart || around;
  58. end = this.parsedEnd;
  59. break;
  60. case 'custom-daily':
  61. component = VCalendarDaily;
  62. start = this.parsedStart || around;
  63. end = this.parsedEnd;
  64. break;
  65. }
  66. return { component: component, start: start, end: end, maxDays: maxDays };
  67. }
  68. },
  69. watch: {
  70. renderProps: 'checkChange'
  71. },
  72. methods: {
  73. checkChange: function checkChange() {
  74. var _renderProps = this.renderProps,
  75. start = _renderProps.start,
  76. end = _renderProps.end;
  77. if (start !== this.lastStart || end !== this.lastEnd) {
  78. this.lastStart = start;
  79. this.lastEnd = end;
  80. this.$emit('change', { start: start, end: end });
  81. }
  82. },
  83. move: function move() {
  84. var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  85. var moved = copyTimestamp(this.parsedValue);
  86. var forward = amount > 0;
  87. var mover = forward ? nextDay : prevDay;
  88. var limit = forward ? DAYS_IN_MONTH_MAX : DAY_MIN;
  89. var times = forward ? amount : -amount;
  90. while (--times >= 0) {
  91. switch (this.type) {
  92. case 'month':
  93. moved.day = limit;
  94. mover(moved);
  95. break;
  96. case 'week':
  97. relativeDays(moved, mover, DAYS_IN_WEEK);
  98. break;
  99. case 'day':
  100. mover(moved);
  101. break;
  102. case '4day':
  103. relativeDays(moved, mover, 4);
  104. break;
  105. }
  106. }
  107. updateWeekday(moved);
  108. updateFormatted(moved);
  109. updateRelative(moved, this.times.now);
  110. this.$emit('input', moved.date);
  111. this.$emit('moved', moved);
  112. },
  113. next: function next() {
  114. var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  115. this.move(amount);
  116. },
  117. prev: function prev() {
  118. var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  119. this.move(-amount);
  120. },
  121. timeToY: function timeToY(time) {
  122. var clamp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  123. var c = this.$children[0];
  124. if (c && c.timeToY) {
  125. return c.timeToY(time, clamp);
  126. } else {
  127. return false;
  128. }
  129. },
  130. minutesToPixels: function minutesToPixels(minutes) {
  131. var c = this.$children[0];
  132. if (c && c.minutesToPixels) {
  133. return c.minutesToPixels(minutes);
  134. } else {
  135. return -1;
  136. }
  137. },
  138. scrollToTime: function scrollToTime(time) {
  139. var c = this.$children[0];
  140. if (c && c.scrollToTime) {
  141. return c.scrollToTime(time);
  142. } else {
  143. return false;
  144. }
  145. }
  146. },
  147. render: function render(h) {
  148. var _this = this;
  149. var _renderProps2 = this.renderProps,
  150. start = _renderProps2.start,
  151. end = _renderProps2.end,
  152. maxDays = _renderProps2.maxDays,
  153. component = _renderProps2.component;
  154. return h(component, {
  155. staticClass: 'v-calendar',
  156. props: _extends({}, this.$props, {
  157. start: start.date,
  158. end: end.date,
  159. maxDays: maxDays
  160. }),
  161. on: _extends({}, this.$listeners, {
  162. 'click:date': function clickDate(day) {
  163. if (_this.$listeners['input']) {
  164. _this.$emit('input', day.date);
  165. }
  166. if (_this.$listeners['click:date']) {
  167. _this.$emit('click:date', day);
  168. }
  169. }
  170. }),
  171. scopedSlots: this.$scopedSlots
  172. });
  173. }
  174. });
  175. //# sourceMappingURL=VCalendar.js.map