()
| 831 | row.classList.add('inline-rename-active'); |
| 832 | |
| 833 | const commit = async () => { |
| 834 | if (!inlineRenameState || inlineRenameState !== state || state.submitting) return; |
| 835 | const newName = String(input.value || '').trim(); |
| 836 | if (!newName || newName === oldName) { |
| 837 | clearInlineRenameState(); |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | state.submitting = true; |
| 842 | input.disabled = true; |
| 843 | |
| 844 | try { |
| 845 | const res = await fetch(withBase('/api/file/renameFile.php'), { |
| 846 | method: 'POST', |
| 847 | credentials: 'include', |
| 848 | headers: { |
| 849 | 'Content-Type': 'application/json', |
| 850 | 'X-CSRF-Token': window.csrfToken |
| 851 | }, |
| 852 | body: JSON.stringify({ |
| 853 | folder: state.folder, |
| 854 | oldName: oldName, |
| 855 | newName: newName |
| 856 | }) |
| 857 | }); |
| 858 | const data = await res.json().catch(() => ({})); |
| 859 | if (data && data.success) { |
| 860 | showToast(t('rename_file_success'), 'success'); |
| 861 | clearInlineRenameState({ restore: false }); |
| 862 | loadFileList(state.folder); |
| 863 | return; |
| 864 | } |
| 865 | const errMsg = data.error || t('unknown_error'); |
| 866 | showToast(t('rename_file_error', { error: errMsg }), 'error'); |
| 867 | } catch (err) { |
| 868 | console.error('Error renaming file:', err); |
| 869 | showToast(t('rename_file_error_generic'), 'error'); |
| 870 | } |
| 871 | |
| 872 | if (inlineRenameState === state) { |
| 873 | state.submitting = false; |
| 874 | input.disabled = false; |
| 875 | focusRenameInput(input, newName, true); |
| 876 | } |
| 877 | }; |
| 878 | |
| 879 | const cancel = () => { |
| 880 | clearInlineRenameState(); |
no test coverage detected