mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Update group managemet
This commit is contained in:
+315
-2
@@ -3144,8 +3144,321 @@ function initializeSystemMetricsCharts() {
|
||||
}
|
||||
|
||||
function initAdminGroups() {
|
||||
// Placeholder for admin groups functionality
|
||||
// Group management is handled in event delegation
|
||||
// Get AJAX URL and CSRF token from page
|
||||
const container = document.querySelector('[data-ajax-url]');
|
||||
const ajaxUrl = container ? container.dataset.ajaxUrl : '/admin/ajax';
|
||||
const csrfToken = container ? container.dataset.csrfToken : document.querySelector('meta[name="csrf-token"]')?.content;
|
||||
|
||||
// Toggle group active/inactive status
|
||||
window.ajax_group_status = function(id, status) {
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'toggle_group_active_status',
|
||||
group_id: id,
|
||||
group_status: status
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const groupCell = document.getElementById('group-' + id);
|
||||
if (groupCell && data.newStatus !== undefined) {
|
||||
const isActive = data.newStatus == 1;
|
||||
groupCell.innerHTML = isActive
|
||||
? `<button type="button" data-action="toggle-group-status" data-group-id="${id}" data-status="0" class="inline-flex items-center px-3 py-1 text-xs font-semibold rounded-full bg-green-100 text-green-800 hover:bg-green-200">
|
||||
<i class="fa fa-check-circle mr-1"></i>Active
|
||||
</button>`
|
||||
: `<button type="button" data-action="toggle-group-status" data-group-id="${id}" data-status="1" class="inline-flex items-center px-3 py-1 text-xs font-semibold rounded-full bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200 hover:bg-gray-200">
|
||||
<i class="fa fa-times-circle mr-1"></i>Inactive
|
||||
</button>`;
|
||||
}
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Group status updated', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error updating group status', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error updating group status', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Toggle backfill status
|
||||
window.ajax_backfill_status = function(id, status) {
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'toggle_group_backfill',
|
||||
group_id: id,
|
||||
backfill: status
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const backfillCell = document.getElementById('backfill-' + id);
|
||||
if (backfillCell && data.newStatus !== undefined) {
|
||||
const isEnabled = data.newStatus == 1;
|
||||
backfillCell.innerHTML = isEnabled
|
||||
? `<button type="button" data-action="toggle-backfill" data-group-id="${id}" data-status="0" class="inline-flex items-center px-3 py-1 text-xs font-semibold rounded-full bg-blue-100 text-blue-800 hover:bg-blue-200">
|
||||
<i class="fa fa-check-circle mr-1"></i>Enabled
|
||||
</button>`
|
||||
: `<button type="button" data-action="toggle-backfill" data-group-id="${id}" data-status="1" class="inline-flex items-center px-3 py-1 text-xs font-semibold rounded-full bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200 hover:bg-gray-200">
|
||||
<i class="fa fa-times-circle mr-1"></i>Disabled
|
||||
</button>`;
|
||||
}
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Backfill status updated', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error updating backfill status', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error updating backfill status', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Reset group
|
||||
window.ajax_group_reset = function(id) {
|
||||
if (!confirm('Are you sure you want to reset this group? This will reset the article pointers back to the current state.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'reset_group',
|
||||
group_id: id
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Group reset successfully', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error resetting group', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error resetting group', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Delete group
|
||||
window.confirmGroupDelete = function(id) {
|
||||
if (!confirm('Are you sure you want to delete this group? This action cannot be undone.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'delete_group',
|
||||
group_id: id
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const row = document.getElementById('grouprow-' + id);
|
||||
if (row) {
|
||||
row.style.transition = 'opacity 0.3s';
|
||||
row.style.opacity = '0';
|
||||
setTimeout(() => row.remove(), 300);
|
||||
}
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Group deleted successfully', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error deleting group', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error deleting group', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Purge group
|
||||
window.confirmGroupPurge = function(id) {
|
||||
if (!confirm('Are you sure you want to purge this group? This will delete all releases and binaries for this group. This action cannot be undone!')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'purge_group',
|
||||
group_id: id
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Group purged successfully', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error purging group', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error purging group', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Reset all groups
|
||||
window.ajax_group_reset_all = function() {
|
||||
hideResetAllModal();
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'reset_all_groups'
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'All groups reset successfully', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error resetting all groups', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error resetting all groups', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Purge all groups
|
||||
window.ajax_group_purge_all = function() {
|
||||
hidePurgeAllModal();
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-CSRF-TOKEN': csrfToken,
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'purge_all_groups'
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'All groups purged successfully', 'success');
|
||||
}
|
||||
} else {
|
||||
if (typeof showToast === 'function') {
|
||||
showToast(data.message || 'Error purging all groups', 'error');
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
if (typeof showToast === 'function') {
|
||||
showToast('Error purging all groups', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Modal helpers
|
||||
window.showResetAllModal = function() {
|
||||
const modal = document.getElementById('resetAllModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('hidden');
|
||||
}
|
||||
};
|
||||
|
||||
window.hideResetAllModal = function() {
|
||||
const modal = document.getElementById('resetAllModal');
|
||||
if (modal) {
|
||||
modal.classList.add('hidden');
|
||||
}
|
||||
};
|
||||
|
||||
window.showPurgeAllModal = function() {
|
||||
const modal = document.getElementById('purgeAllModal');
|
||||
if (modal) {
|
||||
modal.classList.remove('hidden');
|
||||
}
|
||||
};
|
||||
|
||||
window.hidePurgeAllModal = function() {
|
||||
const modal = document.getElementById('purgeAllModal');
|
||||
if (modal) {
|
||||
modal.classList.add('hidden');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// TinyMCE Initialization for Admin Content Pages
|
||||
|
||||
Reference in New Issue
Block a user