boardBody.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import dragscroll from '@wekanteam/dragscroll';
  4. import { boardConverter } from '/client/lib/boardConverter';
  5. import { migrationManager } from '/client/lib/migrationManager';
  6. import { attachmentMigrationManager } from '/client/lib/attachmentMigrationManager';
  7. import Swimlanes from '/models/swimlanes';
  8. import Lists from '/models/lists';
  9. const subManager = new SubsManager();
  10. const { calculateIndex } = Utils;
  11. const swimlaneWhileSortingHeight = 150;
  12. BlazeComponent.extendComponent({
  13. onCreated() {
  14. this.isBoardReady = new ReactiveVar(false);
  15. this.isConverting = new ReactiveVar(false);
  16. this.isMigrating = new ReactiveVar(false);
  17. this._swimlaneCreated = new Set(); // Track boards where we've created swimlanes
  18. this._boardProcessed = false; // Track if board has been processed
  19. this._lastProcessedBoardId = null; // Track last processed board ID
  20. // The pattern we use to manually handle data loading is described here:
  21. // https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
  22. // XXX The boardId should be readed from some sort the component "props",
  23. // unfortunatly, Blaze doesn't have this notion.
  24. this.autorun(() => {
  25. const currentBoardId = Session.get('currentBoard');
  26. if (!currentBoardId) return;
  27. const handle = subManager.subscribe('board', currentBoardId, false);
  28. // Use a separate autorun for subscription ready state to avoid reactive loops
  29. this.subscriptionReadyAutorun = Tracker.autorun(() => {
  30. if (handle.ready()) {
  31. // Only run conversion/migration logic once per board
  32. if (!this._boardProcessed || this._lastProcessedBoardId !== currentBoardId) {
  33. this._boardProcessed = true;
  34. this._lastProcessedBoardId = currentBoardId;
  35. // Ensure default swimlane exists (only once per board)
  36. this.ensureDefaultSwimlane(currentBoardId);
  37. // Check if board needs conversion
  38. this.checkAndConvertBoard(currentBoardId);
  39. }
  40. } else {
  41. this.isBoardReady.set(false);
  42. }
  43. });
  44. });
  45. },
  46. onDestroyed() {
  47. // Clean up the subscription ready autorun to prevent memory leaks
  48. if (this.subscriptionReadyAutorun) {
  49. this.subscriptionReadyAutorun.stop();
  50. }
  51. },
  52. ensureDefaultSwimlane(boardId) {
  53. // Only create swimlane once per board
  54. if (this._swimlaneCreated.has(boardId)) {
  55. return;
  56. }
  57. try {
  58. const board = ReactiveCache.getBoard(boardId);
  59. if (!board) return;
  60. const swimlanes = board.swimlanes();
  61. if (swimlanes.length === 0) {
  62. // Check if any swimlane exists in the database to avoid race conditions
  63. const existingSwimlanes = ReactiveCache.getSwimlanes({ boardId });
  64. if (existingSwimlanes.length === 0) {
  65. const swimlaneId = Swimlanes.insert({
  66. title: 'Default',
  67. boardId: boardId,
  68. });
  69. if (process.env.DEBUG === 'true') {
  70. console.log(`Created default swimlane ${swimlaneId} for board ${boardId}`);
  71. }
  72. }
  73. this._swimlaneCreated.add(boardId);
  74. } else {
  75. this._swimlaneCreated.add(boardId);
  76. }
  77. } catch (error) {
  78. console.error('Error creating default swimlane:', error);
  79. }
  80. },
  81. async checkAndConvertBoard(boardId) {
  82. try {
  83. const board = ReactiveCache.getBoard(boardId);
  84. if (!board) {
  85. this.isBoardReady.set(true);
  86. return;
  87. }
  88. // Check if board needs migration based on migration version
  89. // DISABLED: Migration check and execution
  90. // const needsMigration = !board.migrationVersion || board.migrationVersion < 1;
  91. // if (needsMigration) {
  92. // // Start background migration for old boards
  93. // this.isMigrating.set(true);
  94. // await this.startBackgroundMigration(boardId);
  95. // this.isMigrating.set(false);
  96. // }
  97. // Check if board needs conversion (for old structure)
  98. // DISABLED: Board conversion logic
  99. // if (boardConverter.isBoardConverted(boardId)) {
  100. // if (process.env.DEBUG === 'true') {
  101. // console.log(`Board ${boardId} has already been converted, skipping conversion`);
  102. // }
  103. // this.isBoardReady.set(true);
  104. // } else {
  105. // const needsConversion = boardConverter.needsConversion(boardId);
  106. //
  107. // if (needsConversion) {
  108. // this.isConverting.set(true);
  109. // const success = await boardConverter.convertBoard(boardId);
  110. // this.isConverting.set(false);
  111. //
  112. // if (success) {
  113. // this.isBoardReady.set(true);
  114. // } else {
  115. // console.error('Board conversion failed, setting ready to true anyway');
  116. // this.isBoardReady.set(true); // Still show board even if conversion failed
  117. // }
  118. // } else {
  119. // this.isBoardReady.set(true);
  120. // }
  121. // }
  122. // Set board ready immediately since conversions are disabled
  123. this.isBoardReady.set(true);
  124. // Convert shared lists to per-swimlane lists if needed
  125. // DISABLED: Shared lists conversion
  126. // await this.convertSharedListsToPerSwimlane(boardId);
  127. // Fix missing lists migration (for cards with wrong listId references)
  128. // DISABLED: Missing lists fix
  129. // await this.fixMissingLists(boardId);
  130. // Fix duplicate lists created by WeKan 8.10
  131. // DISABLED: Duplicate lists fix
  132. // await this.fixDuplicateLists(boardId);
  133. // Start attachment migration in background if needed
  134. // DISABLED: Attachment migration
  135. // this.startAttachmentMigrationIfNeeded(boardId);
  136. } catch (error) {
  137. console.error('Error during board conversion check:', error);
  138. this.isConverting.set(false);
  139. this.isMigrating.set(false);
  140. this.isBoardReady.set(true); // Show board even if conversion check failed
  141. }
  142. },
  143. async startBackgroundMigration(boardId) {
  144. try {
  145. // Start background migration using the cron system
  146. Meteor.call('boardMigration.startBoardMigration', boardId, (error, result) => {
  147. if (error) {
  148. console.error('Failed to start background migration:', error);
  149. } else {
  150. if (process.env.DEBUG === 'true') {
  151. console.log('Background migration started for board:', boardId);
  152. }
  153. }
  154. });
  155. } catch (error) {
  156. console.error('Error starting background migration:', error);
  157. }
  158. },
  159. async convertSharedListsToPerSwimlane(boardId) {
  160. try {
  161. const board = ReactiveCache.getBoard(boardId);
  162. if (!board) return;
  163. // Check if board has already been processed for shared lists conversion
  164. if (board.hasSharedListsConverted) {
  165. if (process.env.DEBUG === 'true') {
  166. console.log(`Board ${boardId} has already been processed for shared lists conversion`);
  167. }
  168. return;
  169. }
  170. // Get all lists for this board
  171. const allLists = board.lists();
  172. const swimlanes = board.swimlanes();
  173. if (swimlanes.length === 0) {
  174. if (process.env.DEBUG === 'true') {
  175. console.log(`Board ${boardId} has no swimlanes, skipping shared lists conversion`);
  176. }
  177. return;
  178. }
  179. // Find shared lists (lists with empty swimlaneId or null swimlaneId)
  180. const sharedLists = allLists.filter(list => !list.swimlaneId || list.swimlaneId === '');
  181. if (sharedLists.length === 0) {
  182. if (process.env.DEBUG === 'true') {
  183. console.log(`Board ${boardId} has no shared lists to convert`);
  184. }
  185. // Mark as processed even if no shared lists
  186. Boards.update(boardId, { $set: { hasSharedListsConverted: true } });
  187. return;
  188. }
  189. if (process.env.DEBUG === 'true') {
  190. console.log(`Converting ${sharedLists.length} shared lists to per-swimlane lists for board ${boardId}`);
  191. }
  192. // Convert each shared list to per-swimlane lists
  193. for (const sharedList of sharedLists) {
  194. // Create a copy of the list for each swimlane
  195. for (const swimlane of swimlanes) {
  196. // Check if this list already exists in this swimlane
  197. const existingList = Lists.findOne({
  198. boardId: boardId,
  199. swimlaneId: swimlane._id,
  200. title: sharedList.title
  201. });
  202. if (!existingList) {
  203. // Double-check to avoid race conditions
  204. const doubleCheckList = ReactiveCache.getList({
  205. boardId: boardId,
  206. swimlaneId: swimlane._id,
  207. title: sharedList.title
  208. });
  209. if (!doubleCheckList) {
  210. // Create a new list in this swimlane
  211. const newListData = {
  212. title: sharedList.title,
  213. boardId: boardId,
  214. swimlaneId: swimlane._id,
  215. sort: sharedList.sort || 0,
  216. archived: sharedList.archived || false, // Preserve archived state from original list
  217. createdAt: new Date(),
  218. modifiedAt: new Date()
  219. };
  220. // Copy other properties if they exist
  221. if (sharedList.color) newListData.color = sharedList.color;
  222. if (sharedList.wipLimit) newListData.wipLimit = sharedList.wipLimit;
  223. if (sharedList.wipLimitEnabled) newListData.wipLimitEnabled = sharedList.wipLimitEnabled;
  224. if (sharedList.wipLimitSoft) newListData.wipLimitSoft = sharedList.wipLimitSoft;
  225. Lists.insert(newListData);
  226. if (process.env.DEBUG === 'true') {
  227. const archivedStatus = sharedList.archived ? ' (archived)' : ' (active)';
  228. console.log(`Created list "${sharedList.title}"${archivedStatus} for swimlane ${swimlane.title || swimlane._id}`);
  229. }
  230. } else {
  231. if (process.env.DEBUG === 'true') {
  232. console.log(`List "${sharedList.title}" already exists in swimlane ${swimlane.title || swimlane._id} (double-check), skipping`);
  233. }
  234. }
  235. } else {
  236. if (process.env.DEBUG === 'true') {
  237. console.log(`List "${sharedList.title}" already exists in swimlane ${swimlane.title || swimlane._id}, skipping`);
  238. }
  239. }
  240. }
  241. // Remove the original shared list completely
  242. Lists.remove(sharedList._id);
  243. if (process.env.DEBUG === 'true') {
  244. console.log(`Removed shared list "${sharedList.title}"`);
  245. }
  246. }
  247. // Mark board as processed
  248. Boards.update(boardId, { $set: { hasSharedListsConverted: true } });
  249. if (process.env.DEBUG === 'true') {
  250. console.log(`Successfully converted ${sharedLists.length} shared lists to per-swimlane lists for board ${boardId}`);
  251. }
  252. } catch (error) {
  253. console.error('Error converting shared lists to per-swimlane:', error);
  254. }
  255. },
  256. async fixMissingLists(boardId) {
  257. try {
  258. const board = ReactiveCache.getBoard(boardId);
  259. if (!board) return;
  260. // Check if board has already been processed for missing lists fix
  261. if (board.fixMissingListsCompleted) {
  262. if (process.env.DEBUG === 'true') {
  263. console.log(`Board ${boardId} has already been processed for missing lists fix`);
  264. }
  265. return;
  266. }
  267. // Check if migration is needed
  268. const needsMigration = await new Promise((resolve, reject) => {
  269. Meteor.call('fixMissingListsMigration.needsMigration', boardId, (error, result) => {
  270. if (error) {
  271. reject(error);
  272. } else {
  273. resolve(result);
  274. }
  275. });
  276. });
  277. if (!needsMigration) {
  278. if (process.env.DEBUG === 'true') {
  279. console.log(`Board ${boardId} does not need missing lists fix`);
  280. }
  281. return;
  282. }
  283. if (process.env.DEBUG === 'true') {
  284. console.log(`Starting fix missing lists migration for board ${boardId}`);
  285. }
  286. // Execute the migration
  287. const result = await new Promise((resolve, reject) => {
  288. Meteor.call('fixMissingListsMigration.execute', boardId, (error, result) => {
  289. if (error) {
  290. reject(error);
  291. } else {
  292. resolve(result);
  293. }
  294. });
  295. });
  296. if (result && result.success) {
  297. if (process.env.DEBUG === 'true') {
  298. console.log(`Successfully fixed missing lists for board ${boardId}: created ${result.createdLists} lists, updated ${result.updatedCards} cards`);
  299. }
  300. }
  301. } catch (error) {
  302. console.error('Error fixing missing lists:', error);
  303. }
  304. },
  305. async fixDuplicateLists(boardId) {
  306. try {
  307. const board = ReactiveCache.getBoard(boardId);
  308. if (!board) return;
  309. // Check if board has already been processed for duplicate lists fix
  310. if (board.fixDuplicateListsCompleted) {
  311. if (process.env.DEBUG === 'true') {
  312. console.log(`Board ${boardId} has already been processed for duplicate lists fix`);
  313. }
  314. return;
  315. }
  316. if (process.env.DEBUG === 'true') {
  317. console.log(`Starting duplicate lists fix for board ${boardId}`);
  318. }
  319. // Execute the duplicate lists fix
  320. const result = await new Promise((resolve, reject) => {
  321. Meteor.call('fixDuplicateLists.fixBoard', boardId, (error, result) => {
  322. if (error) {
  323. reject(error);
  324. } else {
  325. resolve(result);
  326. }
  327. });
  328. });
  329. if (result && result.fixed > 0) {
  330. if (process.env.DEBUG === 'true') {
  331. console.log(`Successfully fixed ${result.fixed} duplicate lists for board ${boardId}: ${result.fixedSwimlanes} swimlanes, ${result.fixedLists} lists`);
  332. }
  333. // Mark board as processed
  334. Boards.update(boardId, { $set: { fixDuplicateListsCompleted: true } });
  335. } else if (process.env.DEBUG === 'true') {
  336. console.log(`No duplicate lists found for board ${boardId}`);
  337. // Still mark as processed to avoid repeated checks
  338. Boards.update(boardId, { $set: { fixDuplicateListsCompleted: true } });
  339. } else {
  340. // Still mark as processed to avoid repeated checks
  341. Boards.update(boardId, { $set: { fixDuplicateListsCompleted: true } });
  342. }
  343. } catch (error) {
  344. console.error('Error fixing duplicate lists:', error);
  345. }
  346. },
  347. async startAttachmentMigrationIfNeeded(boardId) {
  348. try {
  349. // Check if board has already been migrated
  350. if (attachmentMigrationManager.isBoardMigrated(boardId)) {
  351. if (process.env.DEBUG === 'true') {
  352. console.log(`Board ${boardId} has already been migrated, skipping`);
  353. }
  354. return;
  355. }
  356. // Check if there are unconverted attachments
  357. const unconvertedAttachments = attachmentMigrationManager.getUnconvertedAttachments(boardId);
  358. if (unconvertedAttachments.length > 0) {
  359. if (process.env.DEBUG === 'true') {
  360. console.log(`Starting attachment migration for ${unconvertedAttachments.length} attachments in board ${boardId}`);
  361. }
  362. await attachmentMigrationManager.startAttachmentMigration(boardId);
  363. } else {
  364. // No attachments to migrate, mark board as migrated
  365. // This will be handled by the migration manager itself
  366. if (process.env.DEBUG === 'true') {
  367. console.log(`Board ${boardId} has no attachments to migrate`);
  368. }
  369. }
  370. } catch (error) {
  371. console.error('Error starting attachment migration:', error);
  372. }
  373. },
  374. onlyShowCurrentCard() {
  375. const isMiniScreen = Utils.isMiniScreen();
  376. const currentCardId = Utils.getCurrentCardId(true);
  377. return isMiniScreen && currentCardId;
  378. },
  379. goHome() {
  380. FlowRouter.go('home');
  381. },
  382. isConverting() {
  383. return this.isConverting.get();
  384. },
  385. isMigrating() {
  386. return this.isMigrating.get();
  387. },
  388. isBoardReady() {
  389. return this.isBoardReady.get();
  390. },
  391. currentBoard() {
  392. return Utils.getCurrentBoard();
  393. },
  394. }).register('board');
  395. BlazeComponent.extendComponent({
  396. onCreated() {
  397. Meteor.subscribe('tableVisibilityModeSettings');
  398. this.showOverlay = new ReactiveVar(false);
  399. this.draggingActive = new ReactiveVar(false);
  400. this._isDragging = false;
  401. // Used to set the overlay
  402. this.mouseHasEnterCardDetails = false;
  403. this._sortFieldsFixed = new Set(); // Track which boards have had sort fields fixed
  404. // fix swimlanes sort field if there are null values
  405. const currentBoardData = Utils.getCurrentBoard();
  406. if (currentBoardData && Swimlanes) {
  407. const boardId = currentBoardData._id;
  408. // Only fix sort fields once per board to prevent reactive loops
  409. if (!this._sortFieldsFixed.has(`swimlanes-${boardId}`)) {
  410. const nullSortSwimlanes = currentBoardData.nullSortSwimlanes();
  411. if (nullSortSwimlanes.length > 0) {
  412. const swimlanes = currentBoardData.swimlanes();
  413. let count = 0;
  414. swimlanes.forEach(s => {
  415. Swimlanes.update(s._id, {
  416. $set: {
  417. sort: count,
  418. },
  419. });
  420. count += 1;
  421. });
  422. }
  423. this._sortFieldsFixed.add(`swimlanes-${boardId}`);
  424. }
  425. }
  426. // fix lists sort field if there are null values
  427. if (currentBoardData && Lists) {
  428. const boardId = currentBoardData._id;
  429. // Only fix sort fields once per board to prevent reactive loops
  430. if (!this._sortFieldsFixed.has(`lists-${boardId}`)) {
  431. const nullSortLists = currentBoardData.nullSortLists();
  432. if (nullSortLists.length > 0) {
  433. const lists = currentBoardData.lists();
  434. let count = 0;
  435. lists.forEach(l => {
  436. Lists.update(l._id, {
  437. $set: {
  438. sort: count,
  439. },
  440. });
  441. count += 1;
  442. });
  443. }
  444. this._sortFieldsFixed.add(`lists-${boardId}`);
  445. }
  446. }
  447. },
  448. onRendered() {
  449. // Initialize user settings (zoom and mobile mode)
  450. Utils.initializeUserSettings();
  451. // Detect iPhone devices and add class for better CSS targeting
  452. const isIPhone = /iPhone|iPod/.test(navigator.userAgent);
  453. if (isIPhone) {
  454. document.body.classList.add('iphone-device');
  455. }
  456. // Accessibility: Focus management for popups and menus
  457. function focusFirstInteractive(container) {
  458. if (!container) return;
  459. // Find first focusable element
  460. const focusable = container.querySelectorAll('button, [role="button"], a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
  461. for (let i = 0; i < focusable.length; i++) {
  462. if (!focusable[i].disabled && focusable[i].offsetParent !== null) {
  463. focusable[i].focus();
  464. break;
  465. }
  466. }
  467. }
  468. // Observe for new popups/menus and set focus (but exclude swimlane content)
  469. const popupObserver = new MutationObserver(function(mutations) {
  470. mutations.forEach(function(mutation) {
  471. mutation.addedNodes.forEach(function(node) {
  472. if (node.nodeType === 1 &&
  473. (node.classList.contains('popup') || node.classList.contains('modal') || node.classList.contains('menu')) &&
  474. !node.closest('.js-swimlanes') &&
  475. !node.closest('.swimlane') &&
  476. !node.closest('.list') &&
  477. !node.closest('.minicard')) {
  478. setTimeout(function() { focusFirstInteractive(node); }, 10);
  479. }
  480. });
  481. });
  482. });
  483. popupObserver.observe(document.body, { childList: true, subtree: true });
  484. // Remove tabindex from non-interactive elements (e.g., user abbreviations, labels)
  485. document.querySelectorAll('.user-abbreviation, .user-label, .card-header-label, .edit-label, .private-label').forEach(function(el) {
  486. if (el.hasAttribute('tabindex')) {
  487. el.removeAttribute('tabindex');
  488. }
  489. });
  490. /*
  491. // Add a toggle button for keyboard shortcuts accessibility
  492. if (!document.getElementById('wekan-shortcuts-toggle')) {
  493. const toggleContainer = document.createElement('div');
  494. toggleContainer.id = 'wekan-shortcuts-toggle';
  495. toggleContainer.style.position = 'fixed';
  496. toggleContainer.style.top = '10px';
  497. toggleContainer.style.right = '10px';
  498. toggleContainer.style.zIndex = '1000';
  499. toggleContainer.style.background = '#fff';
  500. toggleContainer.style.border = '2px solid #005fcc';
  501. toggleContainer.style.borderRadius = '6px';
  502. toggleContainer.style.padding = '8px 12px';
  503. toggleContainer.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)';
  504. toggleContainer.style.fontSize = '16px';
  505. toggleContainer.style.color = '#005fcc';
  506. toggleContainer.setAttribute('role', 'region');
  507. toggleContainer.setAttribute('aria-label', 'Keyboard Shortcuts Settings');
  508. toggleContainer.innerHTML = `
  509. <label for="shortcuts-toggle-checkbox" style="cursor:pointer;">
  510. <input type="checkbox" id="shortcuts-toggle-checkbox" ${window.wekanShortcutsEnabled ? 'checked' : ''} style="margin-right:8px;" />
  511. Enable keyboard shortcuts
  512. </label>
  513. `;
  514. document.body.appendChild(toggleContainer);
  515. const checkbox = document.getElementById('shortcuts-toggle-checkbox');
  516. checkbox.addEventListener('change', function(e) {
  517. window.toggleWekanShortcuts(e.target.checked);
  518. });
  519. }
  520. */
  521. // Ensure toggle-buttons, color choices, reactions, renaming, and calendar controls are focusable and have ARIA roles
  522. document.querySelectorAll('.js-toggle').forEach(function(el) {
  523. el.setAttribute('tabindex', '0');
  524. el.setAttribute('role', 'button');
  525. // Short, descriptive label for favorite/star toggle
  526. if (el.classList.contains('js-favorite-toggle')) {
  527. el.setAttribute('aria-label', TAPi18n.__('favorite-toggle-label'));
  528. } else {
  529. el.setAttribute('aria-label', 'Toggle');
  530. }
  531. });
  532. document.querySelectorAll('.js-color-choice').forEach(function(el) {
  533. el.setAttribute('tabindex', '0');
  534. el.setAttribute('role', 'button');
  535. el.setAttribute('aria-label', 'Choose color');
  536. });
  537. document.querySelectorAll('.js-reaction').forEach(function(el) {
  538. el.setAttribute('tabindex', '0');
  539. el.setAttribute('role', 'button');
  540. el.setAttribute('aria-label', 'React');
  541. });
  542. document.querySelectorAll('.js-rename-swimlane').forEach(function(el) {
  543. el.setAttribute('tabindex', '0');
  544. el.setAttribute('role', 'button');
  545. el.setAttribute('aria-label', 'Rename swimlane');
  546. });
  547. document.querySelectorAll('.js-rename-list').forEach(function(el) {
  548. el.setAttribute('tabindex', '0');
  549. el.setAttribute('role', 'button');
  550. el.setAttribute('aria-label', 'Rename list');
  551. });
  552. document.querySelectorAll('.fc-button').forEach(function(el) {
  553. el.setAttribute('tabindex', '0');
  554. el.setAttribute('role', 'button');
  555. });
  556. // Set the language attribute on the <html> element for accessibility
  557. document.documentElement.lang = TAPi18n.getLanguage();
  558. // Ensure the accessible name for the board view switcher matches the visible label "Swimlanes"
  559. // This fixes WCAG 2.5.3: Label in Name
  560. const swimlanesSwitcher = this.$('.js-board-view-swimlanes');
  561. if (swimlanesSwitcher.length) {
  562. swimlanesSwitcher.attr('aria-label', swimlanesSwitcher.text().trim() || 'Swimlanes');
  563. }
  564. // Add a highly visible focus indicator and improve contrast for interactive elements
  565. if (!document.getElementById('wekan-accessible-focus-style')) {
  566. const style = document.createElement('style');
  567. style.id = 'wekan-accessible-focus-style';
  568. style.innerHTML = `
  569. /* Focus indicator */
  570. 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 {
  571. outline: 3px solid #005fcc !important;
  572. outline-offset: 2px !important;
  573. }
  574. /* Input borders */
  575. input, textarea, select {
  576. border: 2px solid #222 !important;
  577. }
  578. /* Plus icon for adding a new card */
  579. .js-add-card {
  580. color: #005fcc !important; /* dark blue for contrast */
  581. cursor: pointer;
  582. outline: none;
  583. }
  584. .js-add-card[tabindex] {
  585. outline: none;
  586. }
  587. /* Hamburger menu */
  588. .fa-bars, .icon-hamburger {
  589. color: #222 !important;
  590. }
  591. /* Grey icons in card detail header */
  592. .card-detail-header .fa, .card-detail-header .icon {
  593. color: #444 !important;
  594. }
  595. /* Grey operating elements in card detail */
  596. .card-detail .fa, .card-detail .icon {
  597. color: #444 !important;
  598. }
  599. /* Blue bar in checklists */
  600. .checklist-progress-bar {
  601. background-color: #005fcc !important;
  602. }
  603. /* Green checkmark in checklists */
  604. .checklist .fa-check {
  605. color: #007a33 !important;
  606. }
  607. /* X-Button and arrow button in menus */
  608. .close, .fa-arrow-left, .icon-arrow-left {
  609. color: #005fcc !important;
  610. }
  611. /* Cross icon to move boards */
  612. .js-move-board {
  613. color: #005fcc !important;
  614. }
  615. /* Current date background */
  616. .current-date {
  617. background-color: #005fcc !important;
  618. color: #fff !important;
  619. }
  620. `;
  621. document.head.appendChild(style);
  622. }
  623. // Ensure plus/add elements are focusable and have ARIA roles
  624. document.querySelectorAll('.js-add-card').forEach(function(el) {
  625. el.setAttribute('tabindex', '0');
  626. el.setAttribute('role', 'button');
  627. el.setAttribute('aria-label', 'Add new card');
  628. });
  629. const boardComponent = this;
  630. const $swimlanesDom = boardComponent.$('.js-swimlanes');
  631. $swimlanesDom.sortable({
  632. tolerance: 'pointer',
  633. appendTo: '.board-canvas',
  634. helper(evt, item) {
  635. const helper = $(`<div class="swimlane"
  636. style="flex-direction: column;
  637. height: ${swimlaneWhileSortingHeight}px;
  638. width: $(boardComponent.width)px;
  639. overflow: hidden;"/>`);
  640. helper.append(item.clone());
  641. // Also grab the list of lists of cards
  642. const list = item.next();
  643. helper.append(list.clone());
  644. return helper;
  645. },
  646. items: '.swimlane:not(.placeholder)',
  647. placeholder: 'swimlane placeholder',
  648. distance: 7,
  649. start(evt, ui) {
  650. const listDom = ui.placeholder.next('.js-swimlane');
  651. const parentOffset = ui.item.parent().offset();
  652. ui.placeholder.height(ui.helper.height());
  653. EscapeActions.executeUpTo('popup-close');
  654. listDom.addClass('moving-swimlane');
  655. boardComponent.setIsDragging(true);
  656. ui.placeholder.insertAfter(ui.placeholder.next());
  657. boardComponent.origPlaceholderIndex = ui.placeholder.index();
  658. // resize all swimlanes + headers to be a total of 150 px per row
  659. // this could be achieved by setIsDragging(true) but we want immediate
  660. // result
  661. ui.item
  662. .siblings('.js-swimlane')
  663. .css('height', `${swimlaneWhileSortingHeight - 26}px`);
  664. // set the new scroll height after the resize and insertion of
  665. // the placeholder. We want the element under the cursor to stay
  666. // at the same place on the screen
  667. ui.item.parent().get(0).scrollTop =
  668. ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
  669. },
  670. beforeStop(evt, ui) {
  671. const parentOffset = ui.item.parent().offset();
  672. const siblings = ui.item.siblings('.js-swimlane');
  673. siblings.css('height', '');
  674. // compute the new scroll height after the resize and removal of
  675. // the placeholder
  676. const scrollTop =
  677. ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY;
  678. // then reset the original view of the swimlane
  679. siblings.removeClass('moving-swimlane');
  680. // and apply the computed scrollheight
  681. ui.item.parent().get(0).scrollTop = scrollTop;
  682. },
  683. stop(evt, ui) {
  684. // To attribute the new index number, we need to get the DOM element
  685. // of the previous and the following card -- if any.
  686. const prevSwimlaneDom = ui.item.prevAll('.js-swimlane').get(0);
  687. const nextSwimlaneDom = ui.item.nextAll('.js-swimlane').get(0);
  688. const sortIndex = calculateIndex(prevSwimlaneDom, nextSwimlaneDom, 1);
  689. $swimlanesDom.sortable('cancel');
  690. const swimlaneDomElement = ui.item.get(0);
  691. const swimlane = Blaze.getData(swimlaneDomElement);
  692. Swimlanes.update(swimlane._id, {
  693. $set: {
  694. sort: sortIndex.base,
  695. },
  696. });
  697. boardComponent.setIsDragging(false);
  698. },
  699. sort(evt, ui) {
  700. // get the mouse position in the sortable
  701. const parentOffset = ui.item.parent().offset();
  702. const cursorY =
  703. evt.pageY - parentOffset.top + ui.item.parent().scrollTop();
  704. // compute the intended index of the placeholder (we need to skip the
  705. // slots between the headers and the list of cards)
  706. const newplaceholderIndex = Math.floor(
  707. cursorY / swimlaneWhileSortingHeight,
  708. );
  709. let destPlaceholderIndex = (newplaceholderIndex + 1) * 2;
  710. // if we are scrolling far away from the bottom of the list
  711. if (destPlaceholderIndex >= ui.item.parent().get(0).childElementCount) {
  712. destPlaceholderIndex = ui.item.parent().get(0).childElementCount - 1;
  713. }
  714. // update the placeholder position in the DOM tree
  715. if (destPlaceholderIndex !== ui.placeholder.index()) {
  716. if (destPlaceholderIndex < boardComponent.origPlaceholderIndex) {
  717. ui.placeholder.insertBefore(
  718. ui.placeholder
  719. .siblings()
  720. .slice(destPlaceholderIndex - 2, destPlaceholderIndex - 1),
  721. );
  722. } else {
  723. ui.placeholder.insertAfter(
  724. ui.placeholder
  725. .siblings()
  726. .slice(destPlaceholderIndex - 1, destPlaceholderIndex),
  727. );
  728. }
  729. }
  730. },
  731. });
  732. this.autorun(() => {
  733. // Always reset dragscroll on view switch
  734. dragscroll.reset();
  735. if ($swimlanesDom.data('uiSortable') || $swimlanesDom.data('sortable')) {
  736. if (Utils.isTouchScreenOrShowDesktopDragHandles()) {
  737. $swimlanesDom.sortable('option', 'handle', '.js-swimlane-header-handle');
  738. } else {
  739. $swimlanesDom.sortable('option', 'handle', '.swimlane-header');
  740. }
  741. // Disable drag-dropping if the current user is not a board member
  742. $swimlanesDom.sortable(
  743. 'option',
  744. 'disabled',
  745. !ReactiveCache.getCurrentUser()?.isBoardAdmin(),
  746. );
  747. }
  748. });
  749. // If there is no data in the board (ie, no lists) we autofocus the list
  750. // creation form by clicking on the corresponding element.
  751. const currentBoard = Utils.getCurrentBoard();
  752. if (Utils.canModifyBoard() && currentBoard.lists().length === 0) {
  753. boardComponent.openNewListForm();
  754. }
  755. dragscroll.reset();
  756. Utils.setBackgroundImage();
  757. },
  758. notDisplayThisBoard() {
  759. let allowPrivateVisibilityOnly = TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly');
  760. let currentBoard = Utils.getCurrentBoard();
  761. return allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue && currentBoard && currentBoard.permission == 'public';
  762. },
  763. isViewSwimlanes() {
  764. const currentUser = ReactiveCache.getCurrentUser();
  765. let boardView;
  766. if (currentUser) {
  767. boardView = (currentUser.profile || {}).boardView;
  768. } else {
  769. boardView = window.localStorage.getItem('boardView');
  770. }
  771. // If no board view is set, default to swimlanes
  772. if (!boardView) {
  773. boardView = 'board-view-swimlanes';
  774. }
  775. return boardView === 'board-view-swimlanes';
  776. },
  777. isViewLists() {
  778. const currentUser = ReactiveCache.getCurrentUser();
  779. let boardView;
  780. if (currentUser) {
  781. boardView = (currentUser.profile || {}).boardView;
  782. } else {
  783. boardView = window.localStorage.getItem('boardView');
  784. }
  785. return boardView === 'board-view-lists';
  786. },
  787. isViewCalendar() {
  788. const currentUser = ReactiveCache.getCurrentUser();
  789. let boardView;
  790. if (currentUser) {
  791. boardView = (currentUser.profile || {}).boardView;
  792. } else {
  793. boardView = window.localStorage.getItem('boardView');
  794. }
  795. return boardView === 'board-view-cal';
  796. },
  797. hasSwimlanes() {
  798. const currentBoard = Utils.getCurrentBoard();
  799. if (!currentBoard) {
  800. if (process.env.DEBUG === 'true') {
  801. console.log('hasSwimlanes: No current board');
  802. }
  803. return false;
  804. }
  805. try {
  806. const swimlanes = currentBoard.swimlanes();
  807. const hasSwimlanes = swimlanes && swimlanes.length > 0;
  808. if (process.env.DEBUG === 'true') {
  809. console.log('hasSwimlanes: Board has', swimlanes ? swimlanes.length : 0, 'swimlanes');
  810. }
  811. return hasSwimlanes;
  812. } catch (error) {
  813. console.error('hasSwimlanes: Error getting swimlanes:', error);
  814. return false;
  815. }
  816. },
  817. isVerticalScrollbars() {
  818. const user = ReactiveCache.getCurrentUser();
  819. return user && user.isVerticalScrollbars();
  820. },
  821. boardView() {
  822. return Utils.boardView();
  823. },
  824. debugBoardState() {
  825. // Enable debug mode by setting ?debug=1 in URL
  826. const urlParams = new URLSearchParams(window.location.search);
  827. return urlParams.get('debug') === '1';
  828. },
  829. debugBoardStateData() {
  830. const currentBoard = Utils.getCurrentBoard();
  831. const currentBoardId = Session.get('currentBoard');
  832. const isBoardReady = this.isBoardReady.get();
  833. const isConverting = this.isConverting.get();
  834. const isMigrating = this.isMigrating.get();
  835. const boardView = Utils.boardView();
  836. if (process.env.DEBUG === 'true') {
  837. console.log('=== BOARD DEBUG STATE ===');
  838. console.log('currentBoardId:', currentBoardId);
  839. console.log('currentBoard:', !!currentBoard, currentBoard ? currentBoard.title : 'none');
  840. console.log('isBoardReady:', isBoardReady);
  841. console.log('isConverting:', isConverting);
  842. console.log('isMigrating:', isMigrating);
  843. console.log('boardView:', boardView);
  844. console.log('========================');
  845. }
  846. return {
  847. currentBoardId,
  848. hasCurrentBoard: !!currentBoard,
  849. currentBoardTitle: currentBoard ? currentBoard.title : 'none',
  850. isBoardReady,
  851. isConverting,
  852. isMigrating,
  853. boardView
  854. };
  855. },
  856. openNewListForm() {
  857. if (this.isViewSwimlanes()) {
  858. // The form had been removed in 416b17062e57f215206e93a85b02ef9eb1ab4902
  859. // this.childComponents('swimlane')[0]
  860. // .childComponents('addListAndSwimlaneForm')[0]
  861. // .open();
  862. } else if (this.isViewLists()) {
  863. this.childComponents('listsGroup')[0]
  864. .childComponents('addListForm')[0]
  865. .open();
  866. }
  867. },
  868. events() {
  869. return [
  870. {
  871. // XXX The board-overlay div should probably be moved to the parent
  872. // component.
  873. mouseup() {
  874. if (this._isDragging) {
  875. this._isDragging = false;
  876. }
  877. },
  878. 'click .js-empty-board-add-swimlane': Popup.open('swimlaneAdd'),
  879. // Global drag and drop file upload handlers for better visual feedback
  880. 'dragover .board-canvas'(event) {
  881. const dataTransfer = event.originalEvent.dataTransfer;
  882. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  883. event.preventDefault();
  884. // Add visual indicator that files can be dropped
  885. $('.board-canvas').addClass('file-drag-over');
  886. }
  887. },
  888. 'dragleave .board-canvas'(event) {
  889. const dataTransfer = event.originalEvent.dataTransfer;
  890. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  891. // Only remove class if we're leaving the board canvas entirely
  892. if (!event.currentTarget.contains(event.relatedTarget)) {
  893. $('.board-canvas').removeClass('file-drag-over');
  894. }
  895. }
  896. },
  897. 'drop .board-canvas'(event) {
  898. const dataTransfer = event.originalEvent.dataTransfer;
  899. if (dataTransfer && dataTransfer.types && dataTransfer.types.includes('Files')) {
  900. event.preventDefault();
  901. $('.board-canvas').removeClass('file-drag-over');
  902. }
  903. },
  904. },
  905. ];
  906. },
  907. // XXX Flow components allow us to avoid creating these two setter methods by
  908. // exposing a public API to modify the component state. We need to investigate
  909. // best practices here.
  910. setIsDragging(bool) {
  911. this.draggingActive.set(bool);
  912. },
  913. scrollLeft(position = 0) {
  914. const swimlanes = this.$('.js-swimlanes');
  915. swimlanes &&
  916. swimlanes.animate({
  917. scrollLeft: position,
  918. });
  919. },
  920. scrollTop(position = 0) {
  921. const swimlanes = this.$('.js-swimlanes');
  922. swimlanes &&
  923. swimlanes.animate({
  924. scrollTop: position,
  925. });
  926. },
  927. }).register('boardBody');
  928. // Accessibility: Allow users to enable/disable keyboard shortcuts
  929. window.wekanShortcutsEnabled = true;
  930. window.toggleWekanShortcuts = function(enabled) {
  931. window.wekanShortcutsEnabled = !!enabled;
  932. };
  933. // Example: Wrap your character key shortcut handler like this
  934. document.addEventListener('keydown', function(e) {
  935. // Example: "W" key shortcut (replace with your actual shortcut logic)
  936. if (!window.wekanShortcutsEnabled) return;
  937. if (e.key === 'w' || e.key === 'W') {
  938. // ...existing shortcut logic...
  939. // e.g. open swimlanes view, etc.
  940. }
  941. });
  942. // Keyboard accessibility for card actions (favorite, archive, duplicate, etc.)
  943. document.addEventListener('keydown', function(e) {
  944. if (!window.wekanShortcutsEnabled) return;
  945. // Only proceed if focus is on a card action element
  946. const active = document.activeElement;
  947. if (active && active.classList.contains('js-card-action')) {
  948. if (e.key === 'Enter' || e.key === ' ') {
  949. e.preventDefault();
  950. active.click();
  951. }
  952. // Move card up/down with arrow keys
  953. if (e.key === 'ArrowUp') {
  954. e.preventDefault();
  955. if (active.dataset.cardId) {
  956. Meteor.call('moveCardUp', active.dataset.cardId);
  957. }
  958. }
  959. if (e.key === 'ArrowDown') {
  960. e.preventDefault();
  961. if (active.dataset.cardId) {
  962. Meteor.call('moveCardDown', active.dataset.cardId);
  963. }
  964. }
  965. }
  966. // Make plus/add elements keyboard accessible
  967. if (active && active.classList.contains('js-add-card')) {
  968. if (e.key === 'Enter' || e.key === ' ') {
  969. e.preventDefault();
  970. active.click();
  971. }
  972. }
  973. // Keyboard move for cards (alternative to drag & drop)
  974. if (active && active.classList.contains('js-move-card')) {
  975. if (e.key === 'ArrowUp') {
  976. e.preventDefault();
  977. if (active.dataset.cardId) {
  978. Meteor.call('moveCardUp', active.dataset.cardId);
  979. }
  980. }
  981. if (e.key === 'ArrowDown') {
  982. e.preventDefault();
  983. if (active.dataset.cardId) {
  984. Meteor.call('moveCardDown', active.dataset.cardId);
  985. }
  986. }
  987. }
  988. // Ensure move card buttons are focusable and have ARIA roles
  989. document.querySelectorAll('.js-move-card').forEach(function(el) {
  990. el.setAttribute('tabindex', '0');
  991. el.setAttribute('role', 'button');
  992. el.setAttribute('aria-label', 'Move card');
  993. });
  994. // Make toggle-buttons, color choices, reactions, and X-buttons keyboard accessible
  995. if (active && (active.classList.contains('js-toggle') || active.classList.contains('js-color-choice') || active.classList.contains('js-reaction') || active.classList.contains('close'))) {
  996. if (e.key === 'Enter' || e.key === ' ') {
  997. e.preventDefault();
  998. active.click();
  999. }
  1000. }
  1001. // Prevent scripts from removing focus when received
  1002. if (active) {
  1003. active.addEventListener('focus', function(e) {
  1004. // Do not remove focus
  1005. // No-op: This prevents F55 failure
  1006. }, { once: true });
  1007. }
  1008. // Make swimlane/list renaming keyboard accessible
  1009. if (active && (active.classList.contains('js-rename-swimlane') || active.classList.contains('js-rename-list'))) {
  1010. if (e.key === 'Enter') {
  1011. e.preventDefault();
  1012. active.click();
  1013. }
  1014. }
  1015. // Calendar navigation buttons
  1016. if (active && active.classList.contains('fc-button')) {
  1017. if (e.key === 'Enter' || e.key === ' ') {
  1018. e.preventDefault();
  1019. active.click();
  1020. }
  1021. }
  1022. });
  1023. BlazeComponent.extendComponent({
  1024. onRendered() {
  1025. // Set the language attribute on the <html> element for accessibility
  1026. document.documentElement.lang = TAPi18n.getLanguage();
  1027. this.autorun(function () {
  1028. $('#calendar-view').fullCalendar('refetchEvents');
  1029. });
  1030. },
  1031. calendarOptions() {
  1032. return {
  1033. id: 'calendar-view',
  1034. defaultView: 'month',
  1035. editable: true,
  1036. selectable: true,
  1037. timezone: 'local',
  1038. weekNumbers: true,
  1039. header: {
  1040. left: 'title today prev,next',
  1041. center:
  1042. 'agendaDay,listDay,timelineDay agendaWeek,listWeek,timelineWeek month,listMonth',
  1043. right: '',
  1044. },
  1045. buttonText: {
  1046. prev: TAPi18n.__('calendar-previous-month-label'), // e.g. "Previous month"
  1047. next: TAPi18n.__('calendar-next-month-label'), // e.g. "Next month"
  1048. },
  1049. ariaLabel: {
  1050. prev: TAPi18n.__('calendar-previous-month-label'),
  1051. next: TAPi18n.__('calendar-next-month-label'),
  1052. },
  1053. // height: 'parent', nope, doesn't work as the parent might be small
  1054. height: 'auto',
  1055. /* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */
  1056. navLinks: true,
  1057. nowIndicator: true,
  1058. businessHours: {
  1059. // days of week. an array of zero-based day of week integers (0=Sunday)
  1060. dow: [1, 2, 3, 4, 5], // Monday - Friday
  1061. start: '8:00',
  1062. end: '18:00',
  1063. },
  1064. locale: TAPi18n.getLanguage(),
  1065. events(start, end, timezone, callback) {
  1066. const currentBoard = Utils.getCurrentBoard();
  1067. const events = [];
  1068. const pushEvent = function (card, title, start, end, extraCls) {
  1069. start = start || card.startAt;
  1070. end = end || card.endAt;
  1071. title = title || card.title;
  1072. const className =
  1073. (extraCls ? `${extraCls} ` : '') +
  1074. (card.color ? `calendar-event-${card.color}` : '');
  1075. events.push({
  1076. id: card._id,
  1077. title,
  1078. start,
  1079. end: end || card.endAt,
  1080. allDay:
  1081. Math.abs(end.getTime() - start.getTime()) / 1000 === 24 * 3600,
  1082. url: FlowRouter.path('card', {
  1083. boardId: currentBoard._id,
  1084. slug: currentBoard.slug,
  1085. cardId: card._id,
  1086. }),
  1087. className,
  1088. });
  1089. };
  1090. currentBoard
  1091. .cardsInInterval(start.toDate(), end.toDate())
  1092. .forEach(function (card) {
  1093. pushEvent(card);
  1094. });
  1095. currentBoard
  1096. .cardsDueInBetween(start.toDate(), end.toDate())
  1097. .forEach(function (card) {
  1098. pushEvent(
  1099. card,
  1100. `${card.title} ${TAPi18n.__('card-due')}`,
  1101. card.dueAt,
  1102. new Date(card.dueAt.getTime() + 36e5),
  1103. );
  1104. });
  1105. events.sort(function (first, second) {
  1106. return first.id > second.id ? 1 : -1;
  1107. });
  1108. callback(events);
  1109. },
  1110. eventResize(event, delta, revertFunc) {
  1111. let isOk = false;
  1112. const card = ReactiveCache.getCard(event.id);
  1113. if (card) {
  1114. card.setEnd(event.end.toDate());
  1115. isOk = true;
  1116. }
  1117. if (!isOk) {
  1118. revertFunc();
  1119. }
  1120. },
  1121. eventDrop(event, delta, revertFunc) {
  1122. let isOk = false;
  1123. const card = ReactiveCache.getCard(event.id);
  1124. if (card) {
  1125. // TODO: add a flag for allDay events
  1126. if (!event.allDay) {
  1127. // https://github.com/wekan/wekan/issues/2917#issuecomment-1236753962
  1128. //card.setStart(event.start.toDate());
  1129. //card.setEnd(event.end.toDate());
  1130. card.setDue(event.start.toDate());
  1131. isOk = true;
  1132. }
  1133. }
  1134. if (!isOk) {
  1135. revertFunc();
  1136. }
  1137. },
  1138. select: function (startDate) {
  1139. const currentBoard = Utils.getCurrentBoard();
  1140. const currentUser = ReactiveCache.getCurrentUser();
  1141. const modalElement = document.createElement('div');
  1142. modalElement.classList.add('modal', 'fade');
  1143. modalElement.setAttribute('tabindex', '-1');
  1144. modalElement.setAttribute('role', 'dialog');
  1145. modalElement.innerHTML = `
  1146. <div class="modal-dialog justify-content-center align-items-center" role="document">
  1147. <div class="modal-content">
  1148. <div class="modal-header">
  1149. <h5 class="modal-title">${TAPi18n.__('r-create-card')}</h5>
  1150. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1151. <span aria-hidden="true">&times;</span>
  1152. </button>
  1153. </div>
  1154. <div class="modal-body text-center">
  1155. <input type="text" class="form-control" id="card-title-input" placeholder="">
  1156. </div>
  1157. <div class="modal-footer">
  1158. <button type="button" class="btn btn-primary" id="create-card-button">${TAPi18n.__('add-card')}</button>
  1159. </div>
  1160. </div>
  1161. </div>
  1162. `;
  1163. const createCardButton = modalElement.querySelector('#create-card-button');
  1164. createCardButton.addEventListener('click', function () {
  1165. const myTitle = modalElement.querySelector('#card-title-input').value;
  1166. if (myTitle) {
  1167. const firstList = currentBoard.draggableLists()[0];
  1168. const firstSwimlane = currentBoard.swimlanes()[0];
  1169. Meteor.call('createCardWithDueDate', currentBoard._id, firstList._id, myTitle, startDate.toDate(), firstSwimlane._id, function(error, result) {
  1170. if (error) {
  1171. if (process.env.DEBUG === 'true') {
  1172. console.log(error);
  1173. }
  1174. } else {
  1175. if (process.env.DEBUG === 'true') {
  1176. console.log("Card Created", result);
  1177. }
  1178. }
  1179. });
  1180. closeModal();
  1181. }
  1182. });
  1183. document.body.appendChild(modalElement);
  1184. const openModal = function() {
  1185. modalElement.style.display = 'flex';
  1186. // Set focus to the input field for better keyboard accessibility
  1187. const input = modalElement.querySelector('#card-title-input');
  1188. if (input) input.focus();
  1189. };
  1190. const closeModal = function() {
  1191. modalElement.style.display = 'none';
  1192. };
  1193. const closeButton = modalElement.querySelector('[data-dismiss="modal"]');
  1194. closeButton.addEventListener('click', closeModal);
  1195. openModal();
  1196. }
  1197. };
  1198. },
  1199. isViewCalendar() {
  1200. const currentUser = ReactiveCache.getCurrentUser();
  1201. if (currentUser) {
  1202. return (currentUser.profile || {}).boardView === 'board-view-cal';
  1203. } else {
  1204. return window.localStorage.getItem('boardView') === 'board-view-cal';
  1205. }
  1206. },
  1207. }).register('calendarView');