copy_course.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. import I18n from 'i18n!content_migrations'
  19. import $ from 'jquery'
  20. import DateShiftView from 'compiled/views/content_migrations/subviews/DateShiftView'
  21. import DaySubstitutionView from 'compiled/views/content_migrations/subviews/DaySubstitutionView'
  22. import DaySubstitutionCollection from 'compiled/collections/DaySubstitutionCollection'
  23. import CollectionView from 'compiled/views/CollectionView'
  24. import template from 'jst/content_migrations/subviews/DaySubstitutionCollection'
  25. import ContentMigration from 'compiled/models/ContentMigration'
  26. import 'jquery.instructure_date_and_time'
  27. $(document).ready(() => $('.datetime_field').datetime_field({addHiddenInput: true}))
  28. const daySubCollection = new DaySubstitutionCollection()
  29. const daySubCollectionView = new CollectionView({
  30. collection: daySubCollection,
  31. emptyMessage: () => I18n.t('no_day_substitutions', 'No Day Substitutions Added'),
  32. itemView: DaySubstitutionView,
  33. template
  34. })
  35. const dateShiftView = new DateShiftView({
  36. model: new ContentMigration(),
  37. collection: daySubCollection,
  38. daySubstitution: daySubCollectionView,
  39. oldStartDate: ENV.OLD_START_DATE,
  40. oldEndDate: ENV.OLD_END_DATE,
  41. addHiddenInput: true
  42. })
  43. $('#date_shift').html(dateShiftView.render().el)
  44. dateShiftView.$oldStartDate.val(ENV.OLD_START_DATE).trigger('change')
  45. dateShiftView.$oldEndDate.val(ENV.OLD_END_DATE).trigger('change')
  46. const $start = $('#course_start_at')
  47. const $end = $('#course_conclude_at')
  48. function validateDates () {
  49. const startAt = $start.data('unfudged-date')
  50. const endAt = $end.data('unfudged-date')
  51. if (startAt && endAt && (endAt < startAt)) {
  52. $('button[type=submit]').attr('disabled', true)
  53. return $end.errorBox(I18n.t('End date cannot be before start date'))
  54. }
  55. $('button[type=submit]').attr('disabled', false)
  56. return $('#copy_course_form').hideErrors()
  57. }
  58. $start.on('change', function () {
  59. validateDates()
  60. dateShiftView.$newStartDate.val($(this).val()).trigger('change')
  61. })
  62. $end.on('change', function () {
  63. validateDates()
  64. dateShiftView.$newEndDate.val($(this).val()).trigger('change')
  65. })