resource-add-remove.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <link href='../packages-premium/bundle/main.css' rel='stylesheet' />
  6. <script src='../packages-premium/bundle/main.js'></script>
  7. <script>
  8. document.addEventListener('DOMContentLoaded', function() {
  9. var calendarEl = document.getElementById('calendar');
  10. var calendar = new FullCalendar.Calendar(calendarEl, {
  11. now: '2020-09-07',
  12. editable: true,
  13. aspectRatio: 1.8,
  14. scrollTime: '00:00',
  15. headerToolbar: {
  16. left: 'promptResource today prev,next',
  17. center: 'title',
  18. right: 'resourceTimelineDay,resourceTimelineThreeDays,timeGridWeek,dayGridMonth'
  19. },
  20. customButtons: {
  21. promptResource: {
  22. text: '+ room',
  23. click: function() {
  24. var title = prompt('Room name');
  25. if (title) {
  26. calendar.addResource({ title: title });
  27. }
  28. }
  29. }
  30. },
  31. initialView: 'resourceTimelineDay',
  32. views: {
  33. resourceTimelineThreeDays: {
  34. type: 'resourceTimeline',
  35. duration: { days: 3 },
  36. buttonText: '3 days'
  37. }
  38. },
  39. resourceAreaHeaderContent: 'Rooms',
  40. resourceLabelDidMount: function(arg) {
  41. var resource = arg.resource;
  42. arg.el.addEventListener('click', function() {
  43. if (confirm('Are you sure you want to delete ' + resource.title + '?')) {
  44. resource.remove();
  45. }
  46. });
  47. },
  48. resources: [
  49. { id: 'a', title: 'Auditorium A' },
  50. { id: 'b', title: 'Auditorium B', eventColor: 'green' },
  51. { id: 'c', title: 'Auditorium C', eventColor: 'orange' },
  52. { id: 'd', title: 'Auditorium D', children: [
  53. { id: 'd1', title: 'Room D1' },
  54. { id: 'd2', title: 'Room D2' }
  55. ] },
  56. { id: 'e', title: 'Auditorium E' },
  57. { id: 'f', title: 'Auditorium F', eventColor: 'red' },
  58. { id: 'g', title: 'Auditorium G' },
  59. { id: 'h', title: 'Auditorium H' },
  60. { id: 'i', title: 'Auditorium I' },
  61. { id: 'j', title: 'Auditorium J' },
  62. { id: 'k', title: 'Auditorium K' },
  63. { id: 'l', title: 'Auditorium L' },
  64. { id: 'm', title: 'Auditorium M' },
  65. { id: 'n', title: 'Auditorium N' },
  66. { id: 'o', title: 'Auditorium O' },
  67. { id: 'p', title: 'Auditorium P' },
  68. { id: 'q', title: 'Auditorium Q' },
  69. { id: 'r', title: 'Auditorium R' },
  70. { id: 's', title: 'Auditorium S' },
  71. { id: 't', title: 'Auditorium T' },
  72. { id: 'u', title: 'Auditorium U' },
  73. { id: 'v', title: 'Auditorium V' },
  74. { id: 'w', title: 'Auditorium W' },
  75. { id: 'x', title: 'Auditorium X' },
  76. { id: 'y', title: 'Auditorium Y' },
  77. { id: 'z', title: 'Auditorium Z' }
  78. ],
  79. events: [
  80. { id: '1', resourceId: 'b', start: '2020-09-07T02:00:00', end: '2020-09-07T07:00:00', title: 'event 1' },
  81. { id: '2', resourceId: 'c', start: '2020-09-07T05:00:00', end: '2020-09-07T22:00:00', title: 'event 2' },
  82. { id: '3', resourceId: 'd', start: '2020-09-06', end: '2020-09-08', title: 'event 3' },
  83. { id: '4', resourceId: 'e', start: '2020-09-07T03:00:00', end: '2020-09-07T08:00:00', title: 'event 4' },
  84. { id: '5', resourceId: 'f', start: '2020-09-07T00:30:00', end: '2020-09-07T02:30:00', title: 'event 5' }
  85. ]
  86. });
  87. calendar.render();
  88. });
  89. </script>
  90. <style>
  91. body {
  92. margin: 0;
  93. padding: 0;
  94. font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
  95. font-size: 14px;
  96. }
  97. p {
  98. text-align: center;
  99. }
  100. #calendar {
  101. max-width: 1100px;
  102. margin: 50px auto;
  103. }
  104. .fc-datagrid-body td {
  105. cursor: pointer;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <p>
  111. HINT: click on a resource to delete it.
  112. </p>
  113. <div id='calendar'></div>
  114. </body>
  115. </html>