calendar2.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2011 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // this is responsible for gluing all the calendar parts together into a complete page
  19. // the only thing on the erb page should be `calendarApp.init(<contexts>, <manageContexts>);`
  20. import $ from 'jquery'
  21. import Calendar from 'compiled/calendar/Calendar'
  22. import ReactDOM from 'react-dom'
  23. import React from 'react'
  24. import MiniCalendar from 'compiled/calendar/MiniCalendar'
  25. import FindAppointment from 'jsx/calendar/scheduler/components/FindAppointment'
  26. import CalendarHeader from 'compiled/views/calendar/CalendarHeader'
  27. import drawSidebar from 'compiled/calendar/sidebar'
  28. import EventDataSource from 'compiled/calendar/EventDataSource'
  29. import UndatedEventsList from 'compiled/calendar/UndatedEventsList'
  30. import configureSchedulerStore from 'jsx/calendar/scheduler/store/configureStore'
  31. import 'compiled/jquery.kylemenu'
  32. const eventDataSource = new EventDataSource(ENV.CALENDAR.CONTEXTS)
  33. const schedulerStore = ENV.CALENDAR.BETTER_SCHEDULER ? configureSchedulerStore() : null
  34. const header = new CalendarHeader({
  35. el: '#calendar_header',
  36. calendar2Only: ENV.CALENDAR.CAL2_ONLY,
  37. showScheduler: ENV.CALENDAR.SHOW_SCHEDULER && !ENV.CALENDAR.BETTER_SCHEDULER
  38. })
  39. const calendar = new Calendar('#calendar-app', ENV.CALENDAR.CONTEXTS, ENV.CALENDAR.MANAGE_CONTEXTS, eventDataSource, {
  40. activateEvent: ENV.CALENDAR.ACTIVE_EVENT,
  41. viewStart: ENV.CALENDAR.VIEW_START,
  42. showScheduler: ENV.CALENDAR.SHOW_SCHEDULER,
  43. header,
  44. userId: ENV.current_user_id,
  45. schedulerStore,
  46. onLoadAppointmentGroups: (agMap) => {
  47. if (ENV.CALENDAR.BETTER_SCHEDULER) {
  48. const courses = eventDataSource.contexts.filter(context => agMap.hasOwnProperty(context.asset_string))
  49. if (courses.length > 0) {
  50. ReactDOM.render(
  51. <FindAppointment courses={courses} store={schedulerStore} />,
  52. $('#select-course-component')[0]
  53. )
  54. }
  55. }
  56. }
  57. })
  58. new MiniCalendar('#minical', calendar)
  59. new UndatedEventsList('#undated-events', eventDataSource, calendar)
  60. drawSidebar(ENV.CALENDAR.CONTEXTS, ENV.CALENDAR.SELECTED_CONTEXTS, eventDataSource)
  61. let keyboardUser = true
  62. $('.calendar-button').on('mousedown', (e) => {
  63. keyboardUser = false
  64. $(e.target).find('.accessibility-warning').addClass('screenreader-only')
  65. })
  66. $(document).on('keydown', (e) => {
  67. if (e.which === 9) { // checking for tab press
  68. keyboardUser = true
  69. }
  70. })
  71. $('.calendar-button').on('focus', (e) => {
  72. if (keyboardUser) {
  73. $(e.target).find('.accessibility-warning').removeClass('screenreader-only')
  74. }
  75. })
  76. $('.calendar-button').on('focusout', e =>
  77. $(e.target).find('.accessibility-warning').addClass('screenreader-only')
  78. )
  79. $('.rs-section .accessibility-warning').on('focus', e =>
  80. $(e.target).removeClass('screenreader-only')
  81. )
  82. $('.rs-section .accessibility-warning').on('focusout', e =>
  83. $(e.target).addClass('screenreader-only')
  84. )