boardBody.js 28 KB

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