/** * GoingsOn - Context Menus Module * Right-click menu handlers (delegates to components.js) */ (function() { 'use strict'; // On touch devices the row's `oncontextmenu` can fire from a long-press, // which competes with long-press selection. Touch users get the kebab // button instead, so swallow the event without showing the menu. function isTouchInvocation(e) { return !!GoingsOn.touch?.isTouchDevice && e?.type === 'contextmenu'; } // ============ Context Menu Handlers ============ /** * Show the right-click context menu for a task. * @param {MouseEvent} e - Right-click event * @param {string} taskId - Task ID */ function showTaskContextMenu(e, taskId) { e.preventDefault(); e.stopPropagation(); if (isTouchInvocation(e)) return; const items = getTaskContextMenuItems(taskId); showContextMenu(e.clientX, e.clientY, items); } /** * Show the right-click context menu for an email. * @param {MouseEvent} e - Right-click event * @param {string} emailId - Email ID */ function showEmailContextMenu(e, emailId) { e.preventDefault(); e.stopPropagation(); if (isTouchInvocation(e)) return; // Get email state from data attributes const emailEl = e.currentTarget; const email = { is_archived: emailEl.dataset.emailArchived === 'true', is_read: emailEl.dataset.emailRead === 'true', snoozed_until: emailEl.dataset.emailSnoozed === 'true' ? new Date() : null }; const items = getEmailContextMenuItems(emailId, email); showContextMenu(e.clientX, e.clientY, items); } /** * Show the right-click context menu for an event. * @param {MouseEvent} e - Right-click event * @param {string} eventId - Event ID */ function showEventContextMenu(e, eventId) { e.preventDefault(); e.stopPropagation(); if (isTouchInvocation(e)) return; const items = getEventContextMenuItems(eventId); showContextMenu(e.clientX, e.clientY, items); } /** * Show the right-click context menu for a project. * @param {MouseEvent} e - Right-click event * @param {string} projectId - Project ID */ function showProjectContextMenu(e, projectId) { e.preventDefault(); e.stopPropagation(); if (isTouchInvocation(e)) return; const items = getProjectContextMenuItems(projectId); showContextMenu(e.clientX, e.clientY, items); } // ============ Populate GoingsOn.contextMenus Namespace ============ GoingsOn.contextMenus = { showTask: showTaskContextMenu, showEmail: showEmailContextMenu, showEvent: showEventContextMenu, showProject: showProjectContextMenu, }; })();