update usermanager
This commit is contained in:
@@ -401,6 +401,49 @@
|
||||
}, { hideReason: true, confirmText: 'Set Password', unsafeContent: true });
|
||||
};
|
||||
|
||||
window.adminRenameUser = async (btn) => {
|
||||
const id = btn.dataset.id;
|
||||
const currentName = btn.dataset.name;
|
||||
const currentUsername = btn.dataset.username;
|
||||
|
||||
if (typeof ModAction === 'undefined') return alert('Error: ModAction module not loaded');
|
||||
|
||||
ModAction.confirm(
|
||||
'Rename User',
|
||||
'Enter a new login name for <strong>' + escHTML(currentName) + '</strong>.<br>' +
|
||||
'<small style="color:#888;">Current login: <code>' + escHTML(currentUsername) + '</code> — All uploads will be reassigned. User sessions will be invalidated. And the user has to login with the NEW name from now on.</small>',
|
||||
async (newUsername) => {
|
||||
const data = await post('/api/v2/admin/users/rename', { user_id: id, new_username: newUsername });
|
||||
if (data.success) {
|
||||
showFlash(data.msg, 'success');
|
||||
// Update the row in-place: links, text, and all button data attributes
|
||||
const row = document.getElementById('user-row-' + id);
|
||||
if (row) {
|
||||
// Update the name link
|
||||
const link = row.querySelector('.user-info-cell a');
|
||||
if (link) {
|
||||
link.href = '/user/' + data.new_login;
|
||||
// Only overwrite text if there's no display_name (plain username link)
|
||||
if (!link.querySelector('span[style*="accent"]')) {
|
||||
link.textContent = data.new_user;
|
||||
}
|
||||
}
|
||||
// Update all buttons in the row with the new name/username
|
||||
row.querySelectorAll('[data-username]').forEach(el => { el.dataset.username = data.new_login; });
|
||||
row.querySelectorAll('[data-name]').forEach(el => { el.dataset.name = data.new_user; });
|
||||
// Update activity stat links
|
||||
row.querySelectorAll('a[href^="/user/"]').forEach(a => {
|
||||
a.href = a.href.replace(/\/user\/[^/]+/, '/user/' + data.new_login);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new Error(data.msg || 'Rename failed');
|
||||
}
|
||||
},
|
||||
{ hideReason: false, singleLine: true, confirmText: 'Rename', placeholder: 'new username' }
|
||||
);
|
||||
};
|
||||
|
||||
window.adminDeleteUser = async (btn) => {
|
||||
const id = btn.dataset.id;
|
||||
const name = btn.dataset.name;
|
||||
|
||||
@@ -7249,16 +7249,15 @@ class ModAction {
|
||||
if (!modal) return window.flashMessage('Error: Mod modal not found', 3000, 'error');
|
||||
const titleEl = document.getElementById('mod-action-title');
|
||||
const contentEl = document.getElementById('mod-action-content');
|
||||
const textareaEl = document.getElementById('mod-reason');
|
||||
const inputEl = document.getElementById('mod-reason-input');
|
||||
const reasonEl = document.getElementById('mod-reason');
|
||||
const confirmBtn = document.getElementById('mod-action-confirm');
|
||||
const cancelBtn = document.getElementById('mod-action-cancel');
|
||||
const errorEl = document.getElementById('mod-action-error');
|
||||
|
||||
// Pick the active input element based on singleLine option
|
||||
const singleLine = options.singleLine || false;
|
||||
const reasonEl = singleLine ? inputEl : textareaEl;
|
||||
const inactiveEl = singleLine ? textareaEl : inputEl;
|
||||
const hideReason = options.hideReason || false;
|
||||
const allowEmpty = options.allowEmpty || false;
|
||||
const i18n = window.f0ckI18n || {};
|
||||
|
||||
titleEl.innerText = title;
|
||||
if (options.unsafeContent) {
|
||||
@@ -7266,15 +7265,23 @@ class ModAction {
|
||||
} else {
|
||||
contentEl.innerHTML = Sanitizer.clean(promptHtml);
|
||||
}
|
||||
|
||||
reasonEl.value = '';
|
||||
inactiveEl.value = '';
|
||||
inactiveEl.style.display = 'none';
|
||||
errorEl.style.display = 'none';
|
||||
modal.style.display = 'flex';
|
||||
|
||||
const hideReason = options.hideReason || false;
|
||||
const allowEmpty = options.allowEmpty || false;
|
||||
const i18n = window.f0ckI18n || {};
|
||||
// Apply single-line mode: style the textarea to look and act like a text input
|
||||
if (singleLine) {
|
||||
reasonEl.rows = 1;
|
||||
reasonEl.style.resize = 'none';
|
||||
reasonEl.style.overflow = 'hidden';
|
||||
reasonEl.style.height = 'auto';
|
||||
} else {
|
||||
reasonEl.rows = 3;
|
||||
reasonEl.style.resize = '';
|
||||
reasonEl.style.overflow = '';
|
||||
reasonEl.style.height = '';
|
||||
}
|
||||
|
||||
if (hideReason) {
|
||||
reasonEl.style.display = 'none';
|
||||
@@ -7315,24 +7322,19 @@ class ModAction {
|
||||
}
|
||||
};
|
||||
|
||||
// Block Enter from inserting newlines in single-line mode; instead submit
|
||||
const enterHandler = singleLine ? (e) => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); onConfirm(); }
|
||||
} : null;
|
||||
if (enterHandler) reasonEl.addEventListener('keydown', enterHandler);
|
||||
|
||||
const cleanup = () => {
|
||||
confirmBtn.onclick = null;
|
||||
cancelBtn.onclick = null;
|
||||
if (singleLine && inputEl._enterHandler) {
|
||||
inputEl.removeEventListener('keydown', inputEl._enterHandler);
|
||||
inputEl._enterHandler = null;
|
||||
}
|
||||
if (enterHandler) reasonEl.removeEventListener('keydown', enterHandler);
|
||||
confirmBtn.disabled = false;
|
||||
};
|
||||
|
||||
// For single-line input: submit on Enter
|
||||
if (singleLine && !hideReason) {
|
||||
inputEl._enterHandler = (e) => {
|
||||
if (e.key === 'Enter') { e.preventDefault(); onConfirm(); }
|
||||
};
|
||||
inputEl.addEventListener('keydown', inputEl._enterHandler);
|
||||
}
|
||||
|
||||
confirmBtn.onclick = onConfirm;
|
||||
cancelBtn.onclick = close;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user