boardBody.js 29 KB

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