diff --git a/static/js/app/ui.js b/static/js/app/ui.js index 6ac5201d..52bf89f9 100644 --- a/static/js/app/ui.js +++ b/static/js/app/ui.js @@ -997,18 +997,8 @@ const ui = { setContextTarget(card, info); const menuId = info.type === 'folder' ? 'folder-context-menu' : 'file-context-menu'; const menu = document.getElementById(menuId); - if (contextMenus && typeof contextMenus.syncFavoriteOptionLabels === 'function') { - contextMenus.syncFavoriteOptionLabels(); - } - if (contextMenus && typeof contextMenus.syncWopiOptionVisibility === 'function') { - contextMenus.syncWopiOptionVisibility().catch(() => {}); - } - if (contextMenus && typeof contextMenus.syncAddToPlaylistOption === 'function') { - contextMenus.syncAddToPlaylistOption(); - } - if (contextMenus && typeof contextMenus.syncOpenParentFolderOption === 'function') { - contextMenus.syncOpenParentFolderOption(); - } + contextMenus.sync(); + if (menu) { menu.style.left = `${e.pageX}px`; menu.style.top = `${e.pageY}px`; @@ -1201,9 +1191,7 @@ const ui = { } // Keep context-menu label in sync if available - if (contextMenus && typeof contextMenus.syncFavoriteOptionLabels === 'function') { - contextMenus.syncFavoriteOptionLabels(); - } + contextMenus.syncFavoriteOptionLabels(); }); const shared = el.querySelector('.file-badge-shared'); @@ -1547,18 +1535,7 @@ function showContextMenuAtElement(triggerElement, menuId) { top = rect.top - 4 + window.scrollY; // flip above if no room } - if (contextMenus && typeof contextMenus.syncFavoriteOptionLabels === 'function') { - contextMenus.syncFavoriteOptionLabels(); - } - if (contextMenus && typeof contextMenus.syncWopiOptionVisibility === 'function') { - contextMenus.syncWopiOptionVisibility().catch(() => {}); - } - if (contextMenus && typeof contextMenus.syncAddToPlaylistOption === 'function') { - contextMenus.syncAddToPlaylistOption(); - } - if (contextMenus && typeof contextMenus.syncOpenParentFolderOption === 'function') { - contextMenus.syncOpenParentFolderOption(); - } + contextMenus.sync(); menu.style.left = `${left}px`; menu.style.top = `${top}px`; diff --git a/static/js/features/files/contextMenus.js b/static/js/features/files/contextMenus.js index c25145b5..0f02569f 100644 --- a/static/js/features/files/contextMenus.js +++ b/static/js/features/files/contextMenus.js @@ -70,8 +70,8 @@ const contextMenus = { const option = document.getElementById('open-parent-folder-option'); if (!option) return; const folderId = app?.contextMenuTargetFile?.folder_id; - const alreadyViewing = folderId && folderId === app?.currentPath; - option.classList.toggle('hidden', !folderId || alreadyViewing); + const isFilesSection = app.currentSection === 'files'; + option.classList.toggle('hidden', !folderId || isFilesSection); }, syncAddToPlaylistOption() { @@ -87,6 +87,12 @@ const contextMenus = { } }, + sync() { + this.syncFavoriteOptionLabels(); + this.syncWopiOptionVisibility().catch(() => {}); + this.syncAddToPlaylistOption(); + this.syncOpenParentFolderOption(); + }, /** * Assign events to menu items and dialogs */ @@ -688,8 +694,8 @@ const contextMenus = { /** * Load all folders for the move dialog (batch operations) * Uses the same navigation pattern as loadMoveDialogFolders - * @param {string} itemId - ID of the item being moved (unused, kept for compatibility) - * @param {string} mode - 'batch' for batch operations + * @param {string} _itemId - ID of the item being moved (unused, kept for compatibility) + * @param {string} _mode - 'batch' for batch operations */ async loadAllFolders(_itemId, _mode) { // For batch mode, use the same navigation as regular move dialog @@ -731,13 +737,13 @@ const contextMenus = { if (itemName) itemName.textContent = item.name; // Reset form - const pwField = document.getElementById('share-password'); - const expField = document.getElementById('share-expiration'); + const pwField = /** @type HTMLInputElement */ (document.getElementById('share-password')); + const expField = /** @type HTMLInputElement */ (document.getElementById('share-expiration')); if (pwField) pwField.value = ''; if (expField) expField.value = ''; - const permRead = document.getElementById('share-permission-read'); - const permWrite = document.getElementById('share-permission-write'); - const permReshare = document.getElementById('share-permission-reshare'); + const permRead = /** @type HTMLInputElement */ (document.getElementById('share-permission-read')); + const permWrite = /** @type HTMLInputElement */ (document.getElementById('share-permission-write')); + const permReshare = /** @type HTMLInputElement */ (document.getElementById('share-permission-reshare')); if (permRead) permRead.checked = true; if (permWrite) permWrite.checked = false; if (permReshare) permReshare.checked = false; @@ -862,11 +868,11 @@ const contextMenus = { } // Get values from form - const password = document.getElementById('share-password').value; - const expirationDate = document.getElementById('share-expiration').value; - const permissionRead = document.getElementById('share-permission-read').checked; - const permissionWrite = document.getElementById('share-permission-write').checked; - const permissionReshare = document.getElementById('share-permission-reshare').checked; + const password = /** @type HTMLInputElement */ (document.getElementById('share-password')).value; + const expirationDate = /** @type HTMLInputElement */ (document.getElementById('share-expiration')).value; + const permissionRead = /** @type HTMLInputElement */ (document.getElementById('share-permission-read')).checked; + const permissionWrite = /** @type HTMLInputElement */ (document.getElementById('share-permission-write')).checked; + const permissionReshare = /** @type HTMLInputElement */ (document.getElementById('share-permission-reshare')).checked; const item = app.shareDialogItem; const itemType = app.shareDialogItemType; @@ -905,7 +911,7 @@ const contextMenus = { const shareInfo = await response.json(); // Update UI with new share - const shareUrl = document.getElementById('generated-share-url'); + const shareUrl = /** @type HTMLInputElement */ (document.getElementById('generated-share-url')); if (shareUrl) { shareUrl.value = shareInfo.url; document.getElementById('new-share-section').classList.remove('hidden'); @@ -920,7 +926,7 @@ const contextMenus = { ui.showNotification(i18n.t('notifications.link_created'), i18n.t('notifications.share_success')); } catch (error) { console.error('Error creating shared link:', error); - ui.showNotification('Error', error.message || 'Could not create shared link'); + ui.showNotification('Error', /** @type {Error} */ (error).message || 'Could not create shared link'); } }, @@ -931,8 +937,8 @@ const contextMenus = { showEmailNotificationDialog(shareUrl) { // Update dialog content document.getElementById('notification-share-url').textContent = shareUrl; - document.getElementById('notification-email').value = ''; - document.getElementById('notification-message').value = ''; + /** @type HTMLInputElement */ (document.getElementById('notification-email')).value = ''; + /** @type HTMLInputElement */ (document.getElementById('notification-message')).value = ''; // Store the URL for later use app.notificationShareUrl = shareUrl; @@ -945,8 +951,8 @@ const contextMenus = { * Send share notification email */ sendShareNotification() { - const email = document.getElementById('notification-email').value.trim(); - const message = document.getElementById('notification-message').value.trim(); + const email = /** @type HTMLInputElement */ (document.getElementById('notification-email')).value.trim(); + const message = /** @type HTMLInputElement */ (document.getElementById('notification-message')).value.trim(); const shareUrl = app.notificationShareUrl; if (!email || !shareUrl) { @@ -1013,7 +1019,7 @@ const contextMenus = { container.innerHTML = '