boardBody.js 28 KB

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