boardBody.js 46 KB

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