boardBody.js 27 KB

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