boardBody.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import dragscroll from '@wekanteam/dragscroll';
  4. const subManager = new SubsManager();
  5. const { calculateIndex } = Utils;
  6. const swimlaneWhileSortingHeight = 150;
  7. BlazeComponent.extendComponent({
  8. onCreated() {
  9. this.isBoardReady = new ReactiveVar(false);
  10. // The pattern we use to manually handle data loading is described here:
  11. // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
  12. // XXX The boardId should be readed from some sort the component "props",
  13. // unfortunatly, Blaze doesn't have this notion.
  14. this.autorun(() => {
  15. const currentBoardId = Session.get('currentBoard');
  16. if (!currentBoardId) return;
  17. const handle = subManager.subscribe('board', currentBoardId, false);
  18. Tracker.nonreactive(() => {
  19. Tracker.autorun(() => {
  20. this.isBoardReady.set(handle.ready());
  21. });
  22. });
  23. });
  24. },
  25. onlyShowCurrentCard() {
  26. return Utils.isMiniScreen() && Utils.getCurrentCardId(true);
  27. },
  28. goHome() {
  29. FlowRouter.go('home');
  30. },
  31. }).register('board');
  32. BlazeComponent.extendComponent({
  33. onCreated() {
  34. Meteor.subscribe('tableVisibilityModeSettings');
  35. this.showOverlay = new ReactiveVar(false);
  36. this.draggingActive = new ReactiveVar(false);
  37. this._isDragging = false;
  38. // Used to set the overlay
  39. this.mouseHasEnterCardDetails = false;
  40. // fix swimlanes sort field if there are null values
  41. const currentBoardData = Utils.getCurrentBoard();
  42. const nullSortSwimlanes = currentBoardData.nullSortSwimlanes();
  43. if (nullSortSwimlanes.length > 0) {
  44. const swimlanes = currentBoardData.swimlanes();
  45. let count = 0;
  46. swimlanes.forEach(s => {
  47. Swimlanes.update(s._id, {
  48. $set: {
  49. sort: count,
  50. },
  51. });
  52. count += 1;
  53. });
  54. }
  55. // fix lists sort field if there are null values
  56. const nullSortLists = currentBoardData.nullSortLists();
  57. if (nullSortLists.length > 0) {
  58. const lists = currentBoardData.lists();
  59. let count = 0;
  60. lists.forEach(l => {
  61. Lists.update(l._id, {
  62. $set: {
  63. sort: count,
  64. },
  65. });
  66. count += 1;
  67. });
  68. }
  69. },
  70. onRendered() {
  71. // Accessibility: Focus management for popups and menus
  72. function focusFirstInteractive(container) {
  73. if (!container) return;
  74. // Find first focusable element
  75. const focusable = container.querySelectorAll('button, [role="button"], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
  76. for (let i = 0; i < focusable.length; i++) {
  77. if (!focusable[i].disabled && focusable[i].offsetParent !== null) {
  78. focusable[i].focus();
  79. break;
  80. }
  81. }
  82. }
  83. // Observe for new popups/menus and set focus
  84. const popupObserver = new MutationObserver(function(mutations) {
  85. mutations.forEach(function(mutation) {
  86. mutation.addedNodes.forEach(function(node) {
  87. if (node.nodeType === 1 && (node.classList.contains('popup') || node.classList.contains('modal') || node.classList.contains('menu'))) {
  88. setTimeout(function() { focusFirstInteractive(node); }, 10);
  89. }
  90. });
  91. });
  92. });
  93. popupObserver.observe(document.body, { childList: true, subtree: true });
  94. // Remove tabindex from non-interactive elements (e.g., user abbreviations, labels)
  95. document.querySelectorAll('.user-abbreviation, .user-label, .card-header-label, .edit-label, .private-label').forEach(function(el) {
  96. if (el.hasAttribute('tabindex')) {
  97. el.removeAttribute('tabindex');
  98. }
  99. });
  100. // Add a toggle button for keyboard shortcuts accessibility
  101. if (!document.getElementById('wekan-shortcuts-toggle')) {
  102. const toggleContainer = document.createElement('div');
  103. toggleContainer.id = 'wekan-shortcuts-toggle';
  104. toggleContainer.style.position = 'fixed';
  105. toggleContainer.style.top = '10px';
  106. toggleContainer.style.right = '10px';
  107. toggleContainer.style.zIndex = '1000';
  108. toggleContainer.style.background = '#fff';
  109. toggleContainer.style.border = '2px solid #005fcc';
  110. toggleContainer.style.borderRadius = '6px';
  111. toggleContainer.style.padding = '8px 12px';
  112. toggleContainer.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)';
  113. toggleContainer.style.fontSize = '16px';
  114. toggleContainer.style.color = '#005fcc';
  115. toggleContainer.setAttribute('role', 'region');
  116. toggleContainer.setAttribute('aria-label', 'Keyboard Shortcuts Settings');
  117. toggleContainer.innerHTML = `
  118. <label for="shortcuts-toggle-checkbox" style="cursor:pointer;">
  119. <input type="checkbox" id="shortcuts-toggle-checkbox" ${window.wekanShortcutsEnabled ? 'checked' : ''} style="margin-right:8px;" />
  120. Enable keyboard shortcuts
  121. </label>
  122. `;
  123. document.body.appendChild(toggleContainer);
  124. const checkbox = document.getElementById('shortcuts-toggle-checkbox');
  125. checkbox.addEventListener('change', function(e) {
  126. window.toggleWekanShortcuts(e.target.checked);
  127. });
  128. }
  129. // Ensure toggle-buttons, color choices, reactions, renaming, and calendar controls are focusable and have ARIA roles
  130. document.querySelectorAll('.js-toggle').forEach(function(el) {
  131. el.setAttribute('tabindex', '0');
  132. el.setAttribute('role', 'button');
  133. el.setAttribute('aria-label', 'Toggle');
  134. });
  135. document.querySelectorAll('.js-color-choice').forEach(function(el) {
  136. el.setAttribute('tabindex', '0');
  137. el.setAttribute('role', 'button');
  138. el.setAttribute('aria-label', 'Choose color');
  139. });
  140. document.querySelectorAll('.js-reaction').forEach(function(el) {
  141. el.setAttribute('tabindex', '0');
  142. el.setAttribute('role', 'button');
  143. el.setAttribute('aria-label', 'React');
  144. });
  145. document.querySelectorAll('.js-rename-swimlane').forEach(function(el) {
  146. el.setAttribute('tabindex', '0');
  147. el.setAttribute('role', 'button');
  148. el.setAttribute('aria-label', 'Rename swimlane');
  149. });
  150. document.querySelectorAll('.js-rename-list').forEach(function(el) {
  151. el.setAttribute('tabindex', '0');
  152. el.setAttribute('role', 'button');
  153. el.setAttribute('aria-label', 'Rename list');
  154. });
  155. document.querySelectorAll('.fc-button').forEach(function(el) {
  156. el.setAttribute('tabindex', '0');
  157. el.setAttribute('role', 'button');
  158. });
  159. // Set the language attribute on the <html> element for accessibility
  160. document.documentElement.lang = TAPi18n.getLanguage();
  161. // Ensure the accessible name for the board view switcher matches the visible label "Swimlanes"
  162. // This fixes WCAG 2.5.3: Label in Name
  163. const swimlanesSwitcher = this.$('.js-board-view-swimlanes');
  164. if (swimlanesSwitcher.length) {
  165. swimlanesSwitcher.attr('aria-label', swimlanesSwitcher.text().trim() || 'Swimlanes');
  166. }
  167. // Add a highly visible focus indicator and improve contrast for interactive elements
  168. if (!document.getElementById('wekan-accessible-focus-style')) {
  169. const style = document.createElement('style');
  170. style.id = 'wekan-accessible-focus-style';
  171. style.innerHTML = `
  172. /* Focus indicator */
  173. button:focus, [role="button"]:focus, a:focus, input:focus, select:focus, textarea:focus, .dropdown-menu:focus, .js-board-view-swimlanes:focus, .js-add-card:focus {
  174. outline: 3px solid #005fcc !important;
  175. outline-offset: 2px !important;
  176. background-color: #e6f0ff !important;
  177. }
  178. /* Input borders */
  179. input, textarea, select {
  180. border: 2px solid #222 !important;
  181. }
  182. /* Plus icon for adding a new card */
  183. .js-add-card {
  184. color: #005fcc !important; /* dark blue for contrast */
  185. cursor: pointer;
  186. outline: none;
  187. }
  188. .js-add-card[tabindex] {
  189. outline: none;
  190. }
  191. /* Hamburger menu */
  192. .fa-bars, .icon-hamburger {
  193. color: #222 !important;
  194. }
  195. /* Grey icons in card detail header */
  196. .card-detail-header .fa, .card-detail-header .icon {
  197. color: #444 !important;
  198. }
  199. /* Grey operating elements in card detail */
  200. .card-detail .fa, .card-detail .icon {
  201. color: #444 !important;
  202. }
  203. /* Blue bar in checklists */
  204. .checklist-progress-bar {
  205. background-color: #005fcc !important;
  206. }
  207. /* Green checkmark in checklists */
  208. .checklist .fa-check {
  209. color: #007a33 !important;
  210. }
  211. /* X-Button and arrow button in menus */
  212. .close, .fa-arrow-left, .icon-arrow-left {
  213. color: #005fcc !important;
  214. }
  215. /* Cross icon to move boards */
  216. .js-move-board {
  217. color: #005fcc !important;
  218. }
  219. /* Current date background */
  220. .current-date {
  221. background-color: #005fcc !important;
  222. color: #fff !important;
  223. }
  224. `;
  225. document.head.appendChild(style);
  226. }
  227. // Ensure plus/add elements are focusable and have ARIA roles
  228. document.querySelectorAll('.js-add-card').forEach(function(el) {
  229. el.setAttribute('tabindex', '0');
  230. el.setAttribute('role', 'button');
  231. el.setAttribute('aria-label', 'Add new card');
  232. });
  233. const boardComponent = this;
  234. const $swimlanesDom = boardComponent.$('.js-swimlanes');
  235. $swimlanesDom.sortable({
  236. tolerance: 'pointer',
  237. appendTo: '.board-canvas',
  238. helper(evt, item) {
  239. const helper = $(`<div class="swimlane"
  240. style="flex-direction: column;
  241. height: ${swimlaneWhileSortingHeight}px;
  242. width: $(boardComponent.width)px;
  243. overflow: hidden;"/>`);
  244. helper.append(item.clone());
  245. // Also grab the list of lists of cards
  246. const list = item.next();
  247. helper.append(list.clone());
  248. return helper;
  249. },
  250. items: '.swimlane:not(.placeholder)',
  251. placeholder: 'swimlane placeholder',
  252. distance: 7,
  253. start(evt, ui) {
  254. const listDom = ui.placeholder.next('.js-swimlane');
  255. const parentOffset = ui.item.parent().offset();
  256. ui.placeholder.height(ui.helper.height());
  257. EscapeActions.executeUpTo('popup-close');
  258. listDom.addClass('moving-swimlane');
  259. boardComponent.setIsDragging(true);
  260. ui.placeholder.insertAfter(ui.placeholder.next());
  261. boardComponent.origPlaceholderIndex = ui.placeholder.index();
  262. // resize all swimlanes + headers to be a total of 150 px per row
  263. // this could be achieved by setIsDragging(true) but we want immediate
  264. // result
  265. ui.item
  266. .siblings('.js-swimlane')
  267. .css('height', `${swimlaneWhileSortingHeight - 26}px`);
  268. // set the new scroll height after the resize and insertion of
  269. // the placeholder. We want the element under the cursor to stay
  270. // at the same place on the screen
  271. ui.item.parent().get(0).scrollTop =
  272. ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
  273. },
  274. beforeStop(evt, ui) {
  275. const parentOffset = ui.item.parent().offset();
  276. const siblings = ui.item.siblings('.js-swimlane');
  277. siblings.css('height', '');
  278. // compute the new scroll height after the resize and removal of
  279. // the placeholder
  280. const scrollTop =
  281. ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
  282. // then reset the original view of the swimlane
  283. siblings.removeClass('moving-swimlane');
  284. // and apply the computed scrollheight
  285. ui.item.parent().get(0).scrollTop = scrollTop;
  286. },
  287. stop(evt, ui) {
  288. // To attribute the new index number, we need to get the DOM element
  289. // of the previous and the following card -- if any.
  290. const prevSwimlaneDom = ui.item.prevAll('.js-swimlane').get(0);
  291. const nextSwimlaneDom = ui.item.nextAll('.js-swimlane').get(0);
  292. const sortIndex = calculateIndex(prevSwimlaneDom, nextSwimlaneDom, 1);
  293. $swimlanesDom.sortable('cancel');
  294. const swimlaneDomElement = ui.item.get(0);
  295. const swimlane = Blaze.getData(swimlaneDomElement);
  296. Swimlanes.update(swimlane._id, {
  297. $set: {
  298. sort: sortIndex.base,
  299. },
  300. });
  301. boardComponent.setIsDragging(false);
  302. },
  303. sort(evt, ui) {
  304. // get the mouse position in the sortable
  305. const parentOffset = ui.item.parent().offset();
  306. const cursorY =
  307. evt.pageY - parentOffset.top + ui.item.parent().scrollTop();
  308. // compute the intended index of the placeholder (we need to skip the
  309. // slots between the headers and the list of cards)
  310. const newplaceholderIndex = Math.floor(
  311. cursorY / swimlaneWhileSortingHeight,
  312. );
  313. let destPlaceholderIndex = (newplaceholderIndex + 1) * 2;
  314. // if we are scrolling far away from the bottom of the list
  315. if (destPlaceholderIndex >= ui.item.parent().get(0).childElementCount) {
  316. destPlaceholderIndex = ui.item.parent().get(0).childElementCount - 1;
  317. }
  318. // update the placeholder position in the DOM tree
  319. if (destPlaceholderIndex !== ui.placeholder.index()) {
  320. if (destPlaceholderIndex < boardComponent.origPlaceholderIndex) {
  321. ui.placeholder.insertBefore(
  322. ui.placeholder
  323. .siblings()
  324. .slice(destPlaceholderIndex - 2, destPlaceholderIndex - 1),
  325. );
  326. } else {
  327. ui.placeholder.insertAfter(
  328. ui.placeholder
  329. .siblings()
  330. .slice(destPlaceholderIndex - 1, destPlaceholderIndex),
  331. );
  332. }
  333. }
  334. },
  335. });
  336. this.autorun(() => {
  337. // Always reset dragscroll on view switch
  338. dragscroll.reset();
  339. if (Utils.isTouchScreenOrShowDesktopDragHandles()) {
  340. $swimlanesDom.sortable({
  341. handle: '.js-swimlane-header-handle',
  342. });
  343. } else {
  344. $swimlanesDom.sortable({
  345. handle: '.swimlane-header',
  346. });
  347. }
  348. // Disable drag-dropping if the current user is not a board member
  349. $swimlanesDom.sortable(
  350. 'option',
  351. 'disabled',
  352. !ReactiveCache.getCurrentUser()?.isBoardAdmin(),
  353. );
  354. });
  355. // If there is no data in the board (ie, no lists) we autofocus the list
  356. // creation form by clicking on the corresponding element.
  357. const currentBoard = Utils.getCurrentBoard();
  358. if (Utils.canModifyBoard() && currentBoard.lists().length === 0) {
  359. boardComponent.openNewListForm();
  360. }
  361. dragscroll.reset();
  362. Utils.setBackgroundImage();
  363. },
  364. notDisplayThisBoard() {
  365. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  366. let currentBoard = Utils.getCurrentBoard();
  367. if (allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue && currentBoard.permission == 'public') {
  368. return true;
  369. }
  370. return false;
  371. },
  372. isViewSwimlanes() {
  373. const currentUser = ReactiveCache.getCurrentUser();
  374. if (currentUser) {
  375. return (currentUser.profile || {}).boardView === 'board-view-swimlanes';
  376. } else {
  377. return (
  378. window.localStorage.getItem('boardView') === 'board-view-swimlanes'
  379. );
  380. }
  381. },
  382. hasSwimlanes() {
  383. return Utils.getCurrentBoard().swimlanes().length > 0;
  384. },
  385. isViewLists() {
  386. const currentUser = ReactiveCache.getCurrentUser();
  387. if (currentUser) {
  388. return (currentUser.profile || {}).boardView === 'board-view-lists';
  389. } else {
  390. return window.localStorage.getItem('boardView') === 'board-view-lists';
  391. }
  392. },
  393. isViewCalendar() {
  394. const currentUser = ReactiveCache.getCurrentUser();
  395. if (currentUser) {
  396. return (currentUser.profile || {}).boardView === 'board-view-cal';
  397. } else {
  398. return window.localStorage.getItem('boardView') === 'board-view-cal';
  399. }
  400. },
  401. isVerticalScrollbars() {
  402. const user = ReactiveCache.getCurrentUser();
  403. return user && user.isVerticalScrollbars();
  404. },
  405. openNewListForm() {
  406. if (this.isViewSwimlanes()) {
  407. // The form had been removed in 416b17062e57f215206e93a85b02ef9eb1ab4902
  408. // this.childComponents('swimlane')[0]
  409. // .childComponents('addListAndSwimlaneForm')[0]
  410. // .open();
  411. } else if (this.isViewLists()) {
  412. this.childComponents('listsGroup')[0]
  413. .childComponents('addListForm')[0]
  414. .open();
  415. }
  416. },
  417. events() {
  418. return [
  419. {
  420. // XXX The board-overlay div should probably be moved to the parent
  421. // component.
  422. mouseup() {
  423. if (this._isDragging) {
  424. this._isDragging = false;
  425. }
  426. },
  427. 'click .js-empty-board-add-swimlane': Popup.open('swimlaneAdd'),
  428. },
  429. ];
  430. },
  431. // XXX Flow components allow us to avoid creating these two setter methods by
  432. // exposing a public API to modify the component state. We need to investigate
  433. // best practices here.
  434. setIsDragging(bool) {
  435. this.draggingActive.set(bool);
  436. },
  437. scrollLeft(position = 0) {
  438. const swimlanes = this.$('.js-swimlanes');
  439. swimlanes &&
  440. swimlanes.animate({
  441. scrollLeft: position,
  442. });
  443. },
  444. scrollTop(position = 0) {
  445. const swimlanes = this.$('.js-swimlanes');
  446. swimlanes &&
  447. swimlanes.animate({
  448. scrollTop: position,
  449. });
  450. },
  451. }).register('boardBody');
  452. // Accessibility: Allow users to enable/disable keyboard shortcuts
  453. window.wekanShortcutsEnabled = true;
  454. window.toggleWekanShortcuts = function(enabled) {
  455. window.wekanShortcutsEnabled = !!enabled;
  456. };
  457. // Example: Wrap your character key shortcut handler like this
  458. document.addEventListener('keydown', function(e) {
  459. // Example: "W" key shortcut (replace with your actual shortcut logic)
  460. if (!window.wekanShortcutsEnabled) return;
  461. if (e.key === 'w' || e.key === 'W') {
  462. // ...existing shortcut logic...
  463. // e.g. open swimlanes view, etc.
  464. }
  465. });
  466. // Keyboard accessibility for card actions (favorite, archive, duplicate, etc.)
  467. document.addEventListener('keydown', function(e) {
  468. if (!window.wekanShortcutsEnabled) return;
  469. // Only proceed if focus is on a card action element
  470. const active = document.activeElement;
  471. if (active && active.classList.contains('js-card-action')) {
  472. if (e.key === 'Enter' || e.key === ' ') {
  473. e.preventDefault();
  474. active.click();
  475. }
  476. // Move card up/down with arrow keys
  477. if (e.key === 'ArrowUp') {
  478. e.preventDefault();
  479. if (active.dataset.cardId) {
  480. Meteor.call('moveCardUp', active.dataset.cardId);
  481. }
  482. }
  483. if (e.key === 'ArrowDown') {
  484. e.preventDefault();
  485. if (active.dataset.cardId) {
  486. Meteor.call('moveCardDown', active.dataset.cardId);
  487. }
  488. }
  489. }
  490. // Make plus/add elements keyboard accessible
  491. if (active && active.classList.contains('js-add-card')) {
  492. if (e.key === 'Enter' || e.key === ' ') {
  493. e.preventDefault();
  494. active.click();
  495. }
  496. }
  497. // Keyboard move for cards (alternative to drag & drop)
  498. if (active && active.classList.contains('js-move-card')) {
  499. if (e.key === 'ArrowUp') {
  500. e.preventDefault();
  501. if (active.dataset.cardId) {
  502. Meteor.call('moveCardUp', active.dataset.cardId);
  503. }
  504. }
  505. if (e.key === 'ArrowDown') {
  506. e.preventDefault();
  507. if (active.dataset.cardId) {
  508. Meteor.call('moveCardDown', active.dataset.cardId);
  509. }
  510. }
  511. }
  512. // Ensure move card buttons are focusable and have ARIA roles
  513. document.querySelectorAll('.js-move-card').forEach(function(el) {
  514. el.setAttribute('tabindex', '0');
  515. el.setAttribute('role', 'button');
  516. el.setAttribute('aria-label', 'Move card');
  517. });
  518. // Make toggle-buttons, color choices, reactions, and X-buttons keyboard accessible
  519. if (active && (active.classList.contains('js-toggle') || active.classList.contains('js-color-choice') || active.classList.contains('js-reaction') || active.classList.contains('close'))) {
  520. if (e.key === 'Enter' || e.key === ' ') {
  521. e.preventDefault();
  522. active.click();
  523. }
  524. }
  525. // Prevent scripts from removing focus when received
  526. if (active) {
  527. active.addEventListener('focus', function(e) {
  528. // Do not remove focus
  529. // No-op: This prevents F55 failure
  530. }, { once: true });
  531. }
  532. // Make swimlane/list renaming keyboard accessible
  533. if (active && (active.classList.contains('js-rename-swimlane') || active.classList.contains('js-rename-list'))) {
  534. if (e.key === 'Enter') {
  535. e.preventDefault();
  536. active.click();
  537. }
  538. }
  539. // Calendar navigation buttons
  540. if (active && active.classList.contains('fc-button')) {
  541. if (e.key === 'Enter' || e.key === ' ') {
  542. e.preventDefault();
  543. active.click();
  544. }
  545. }
  546. });
  547. BlazeComponent.extendComponent({
  548. onRendered() {
  549. // Set the language attribute on the <html> element for accessibility
  550. document.documentElement.lang = TAPi18n.getLanguage();
  551. this.autorun(function () {
  552. $('#calendar-view').fullCalendar('refetchEvents');
  553. });
  554. },
  555. calendarOptions() {
  556. return {
  557. id: 'calendar-view',
  558. defaultView: 'month',
  559. editable: true,
  560. selectable: true,
  561. timezone: 'local',
  562. weekNumbers: true,
  563. header: {
  564. left: 'title today prev,next',
  565. center:
  566. 'agendaDay,listDay,timelineDay agendaWeek,listWeek,timelineWeek month,listMonth',
  567. right: '',
  568. },
  569. buttonText: {
  570. prev: TAPi18n.__('calendar-previous-month'),
  571. next: TAPi18n.__('calendar-next-month'),
  572. },
  573. ariaLabel: {
  574. prev: TAPi18n.__('calendar-previous-month'),
  575. next: TAPi18n.__('calendar-next-month'),
  576. },
  577. // height: 'parent', nope, doesn't work as the parent might be small
  578. height: 'auto',
  579. /* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */
  580. navLinks: true,
  581. nowIndicator: true,
  582. businessHours: {
  583. // days of week. an array of zero-based day of week integers (0=Sunday)
  584. dow: [1, 2, 3, 4, 5], // Monday - Friday
  585. start: '8:00',
  586. end: '18:00',
  587. },
  588. locale: TAPi18n.getLanguage(),
  589. events(start, end, timezone, callback) {
  590. const currentBoard = Utils.getCurrentBoard();
  591. const events = [];
  592. const pushEvent = function (card, title, start, end, extraCls) {
  593. start = start || card.startAt;
  594. end = end || card.endAt;
  595. title = title || card.title;
  596. const className =
  597. (extraCls ? `${extraCls} ` : '') +
  598. (card.color ? `calendar-event-${card.color}` : '');
  599. events.push({
  600. id: card._id,
  601. title,
  602. start,
  603. end: end || card.endAt,
  604. allDay:
  605. Math.abs(end.getTime() - start.getTime()) / 1000 === 24 * 3600,
  606. url: FlowRouter.path('card', {
  607. boardId: currentBoard._id,
  608. slug: currentBoard.slug,
  609. cardId: card._id,
  610. }),
  611. className,
  612. });
  613. };
  614. currentBoard
  615. .cardsInInterval(start.toDate(), end.toDate())
  616. .forEach(function (card) {
  617. pushEvent(card);
  618. });
  619. currentBoard
  620. .cardsDueInBetween(start.toDate(), end.toDate())
  621. .forEach(function (card) {
  622. pushEvent(
  623. card,
  624. `${card.title} ${TAPi18n.__('card-due')}`,
  625. card.dueAt,
  626. new Date(card.dueAt.getTime() + 36e5),
  627. );
  628. });
  629. events.sort(function (first, second) {
  630. return first.id > second.id ? 1 : -1;
  631. });
  632. callback(events);
  633. },
  634. eventResize(event, delta, revertFunc) {
  635. let isOk = false;
  636. const card = ReactiveCache.getCard(event.id);
  637. if (card) {
  638. card.setEnd(event.end.toDate());
  639. isOk = true;
  640. }
  641. if (!isOk) {
  642. revertFunc();
  643. }
  644. },
  645. eventDrop(event, delta, revertFunc) {
  646. let isOk = false;
  647. const card = ReactiveCache.getCard(event.id);
  648. if (card) {
  649. // TODO: add a flag for allDay events
  650. if (!event.allDay) {
  651. // https://github.com/wekan/wekan/issues/2917#issuecomment-1236753962
  652. //card.setStart(event.start.toDate());
  653. //card.setEnd(event.end.toDate());
  654. card.setDue(event.start.toDate());
  655. isOk = true;
  656. }
  657. }
  658. if (!isOk) {
  659. revertFunc();
  660. }
  661. },
  662. select: function (startDate) {
  663. const currentBoard = Utils.getCurrentBoard();
  664. const currentUser = ReactiveCache.getCurrentUser();
  665. const modalElement = document.createElement('div');
  666. modalElement.classList.add('modal', 'fade');
  667. modalElement.setAttribute('tabindex', '-1');
  668. modalElement.setAttribute('role', 'dialog');
  669. modalElement.innerHTML = `
  670. <div class="modal-dialog justify-content-center align-items-center" role="document">
  671. <div class="modal-content">
  672. <div class="modal-header">
  673. <h5 class="modal-title">${TAPi18n.__('r-create-card')}</h5>
  674. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  675. <span aria-hidden="true">&times;</span>
  676. </button>
  677. </div>
  678. <div class="modal-body text-center">
  679. <input type="text" class="form-control" id="card-title-input" placeholder="">
  680. </div>
  681. <div class="modal-footer">
  682. <button type="button" class="btn btn-primary" id="create-card-button">${TAPi18n.__('add-card')}</button>
  683. </div>
  684. </div>
  685. </div>
  686. `;
  687. const createCardButton = modalElement.querySelector('#create-card-button');
  688. createCardButton.addEventListener('click', function () {
  689. const myTitle = modalElement.querySelector('#card-title-input').value;
  690. if (myTitle) {
  691. const firstList = currentBoard.draggableLists()[0];
  692. const firstSwimlane = currentBoard.swimlanes()[0];
  693. Meteor.call('createCardWithDueDate', currentBoard._id, firstList._id, myTitle, startDate.toDate(), firstSwimlane._id, function(error, result) {
  694. if (error) {
  695. console.log(error);
  696. } else {
  697. console.log("Card Created", result);
  698. }
  699. });
  700. closeModal();
  701. }
  702. });
  703. document.body.appendChild(modalElement);
  704. const openModal = function() {
  705. modalElement.style.display = 'flex';
  706. // Set focus to the input field for better keyboard accessibility
  707. const input = modalElement.querySelector('#card-title-input');
  708. if (input) input.focus();
  709. };
  710. const closeModal = function() {
  711. modalElement.style.display = 'none';
  712. };
  713. const closeButton = modalElement.querySelector('[data-dismiss="modal"]');
  714. closeButton.addEventListener('click', closeModal);
  715. openModal();
  716. }
  717. };
  718. },
  719. isViewCalendar() {
  720. const currentUser = ReactiveCache.getCurrentUser();
  721. if (currentUser) {
  722. return (currentUser.profile || {}).boardView === 'board-view-cal';
  723. } else {
  724. return window.localStorage.getItem('boardView') === 'board-view-cal';
  725. }
  726. },
  727. }).register('calendarView');