boardBody.js 28 KB

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