Skip to main content

max / goingson

2.8 KB · 87 lines History Blame Raw
1 /**
2 * GoingsOn - Context Menus Module
3 * Right-click menu handlers (delegates to components.js)
4 */
5
6 (function() {
7 'use strict';
8
9 // On touch devices the row's `oncontextmenu` can fire from a long-press,
10 // which competes with long-press selection. Touch users get the kebab
11 // button instead, so swallow the event without showing the menu.
12 function isTouchInvocation(e) {
13 return !!GoingsOn.touch?.isTouchDevice && e?.type === 'contextmenu';
14 }
15
16 // ============ Context Menu Handlers ============
17
18 /**
19 * Show the right-click context menu for a task.
20 * @param {MouseEvent} e - Right-click event
21 * @param {string} taskId - Task ID
22 */
23 function showTaskContextMenu(e, taskId) {
24 e.preventDefault();
25 e.stopPropagation();
26 if (isTouchInvocation(e)) return;
27 const items = getTaskContextMenuItems(taskId);
28 showContextMenu(e.clientX, e.clientY, items);
29 }
30
31 /**
32 * Show the right-click context menu for an email.
33 * @param {MouseEvent} e - Right-click event
34 * @param {string} emailId - Email ID
35 */
36 function showEmailContextMenu(e, emailId) {
37 e.preventDefault();
38 e.stopPropagation();
39 if (isTouchInvocation(e)) return;
40 // Get email state from data attributes
41 const emailEl = e.currentTarget;
42 const email = {
43 is_archived: emailEl.dataset.emailArchived === 'true',
44 is_read: emailEl.dataset.emailRead === 'true',
45 snoozed_until: emailEl.dataset.emailSnoozed === 'true' ? new Date() : null
46 };
47 const items = getEmailContextMenuItems(emailId, email);
48 showContextMenu(e.clientX, e.clientY, items);
49 }
50
51 /**
52 * Show the right-click context menu for an event.
53 * @param {MouseEvent} e - Right-click event
54 * @param {string} eventId - Event ID
55 */
56 function showEventContextMenu(e, eventId) {
57 e.preventDefault();
58 e.stopPropagation();
59 if (isTouchInvocation(e)) return;
60 const items = getEventContextMenuItems(eventId);
61 showContextMenu(e.clientX, e.clientY, items);
62 }
63
64 /**
65 * Show the right-click context menu for a project.
66 * @param {MouseEvent} e - Right-click event
67 * @param {string} projectId - Project ID
68 */
69 function showProjectContextMenu(e, projectId) {
70 e.preventDefault();
71 e.stopPropagation();
72 if (isTouchInvocation(e)) return;
73 const items = getProjectContextMenuItems(projectId);
74 showContextMenu(e.clientX, e.clientY, items);
75 }
76
77 // ============ Populate GoingsOn.contextMenus Namespace ============
78
79 GoingsOn.contextMenus = {
80 showTask: showTaskContextMenu,
81 showEmail: showEmailContextMenu,
82 showEvent: showEventContextMenu,
83 showProject: showProjectContextMenu,
84 };
85
86 })();
87