709 lines
34 KiB
HTML
Executable File
709 lines
34 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="robots" content="noindex, nofollow, noarchive">
|
|
<title>News Management - MSPE Admin</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha384-t1nt8BQoYMLFN5p42tRAtuAAFQaCQODekUVeKKZrEnEyp4H2R0RHFz0KWpmj7i8g" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="/admin/css/admin.css">
|
|
</head>
|
|
<body>
|
|
<div class="admin-wrapper">
|
|
<!-- Sidebar -->
|
|
<aside class="sidebar" id="sidebar">
|
|
<div class="sidebar-header">
|
|
<a href="/admin/dashboard.html" class="sidebar-logo">
|
|
<i class="fas fa-cube"></i>
|
|
<span>MSPE</span>
|
|
</a>
|
|
<button class="sidebar-toggle" id="sidebar-toggle">
|
|
<i class="fas fa-bars"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<nav class="sidebar-nav">
|
|
<div class="nav-section">
|
|
<span class="nav-section-title">Main</span>
|
|
<ul class="nav-menu">
|
|
<li class="nav-item">
|
|
<a href="/admin/dashboard.html" class="nav-link">
|
|
<i class="fas fa-th-large"></i>
|
|
<span>Dashboard</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="nav-section">
|
|
<span class="nav-section-title">Content</span>
|
|
<ul class="nav-menu">
|
|
<li class="nav-item">
|
|
<a href="/admin/pages.html" class="nav-link">
|
|
<i class="fas fa-file-alt"></i>
|
|
<span>Pages</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/services.html" class="nav-link">
|
|
<i class="fas fa-concierge-bell"></i>
|
|
<span>Services</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/portfolio.html" class="nav-link">
|
|
<i class="fas fa-briefcase"></i>
|
|
<span>Portfolio</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item active">
|
|
<a href="/admin/news.html" class="nav-link">
|
|
<i class="fas fa-newspaper"></i>
|
|
<span>News & Events</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/testimonials.html" class="nav-link">
|
|
<i class="fas fa-quote-right"></i>
|
|
<span>Testimonials</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/team.html" class="nav-link">
|
|
<i class="fas fa-users"></i>
|
|
<span>Team</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="nav-section">
|
|
<span class="nav-section-title">Media</span>
|
|
<ul class="nav-menu">
|
|
<li class="nav-item">
|
|
<a href="/admin/media.html" class="nav-link">
|
|
<i class="fas fa-images"></i>
|
|
<span>Media Library</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="nav-section">
|
|
<span class="nav-section-title">Inquiries</span>
|
|
<ul class="nav-menu">
|
|
<li class="nav-item">
|
|
<a href="/admin/messages.html" class="nav-link">
|
|
<i class="fas fa-envelope"></i>
|
|
<span>Messages</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/subscribers.html" class="nav-link">
|
|
<i class="fas fa-bell"></i>
|
|
<span>Subscribers</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/bookings.html" class="nav-link">
|
|
<i class="fas fa-calendar-check"></i>
|
|
<span>Bookings</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="nav-section">
|
|
<span class="nav-section-title">Settings</span>
|
|
<ul class="nav-menu">
|
|
<li class="nav-item">
|
|
<a href="/admin/settings.html" class="nav-link">
|
|
<i class="fas fa-cog"></i>
|
|
<span>Site Settings</span>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="/admin/users.html" class="nav-link">
|
|
<i class="fas fa-user-shield"></i>
|
|
<span>Admin Users</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="sidebar-footer">
|
|
<a href="/index.html" class="view-site-btn" target="_blank">
|
|
<i class="fas fa-external-link-alt"></i>
|
|
<span>View Website</span>
|
|
</a>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- Main Content -->
|
|
<main class="main-content">
|
|
<!-- Header -->
|
|
<header class="admin-header">
|
|
<div class="header-left">
|
|
<button class="mobile-toggle" id="mobile-toggle">
|
|
<i class="fas fa-bars"></i>
|
|
</button>
|
|
<h1 class="page-title">News & Events</h1>
|
|
</div>
|
|
|
|
<div class="header-right">
|
|
<div class="header-user">
|
|
<div class="user-avatar">
|
|
<img src="https://ui-avatars.com/api/?name=Admin&background=0ea5e9&color=fff" alt="Admin">
|
|
</div>
|
|
<div class="user-info">
|
|
<span class="user-name">Admin</span>
|
|
<span class="user-role">Administrator</span>
|
|
</div>
|
|
<div class="user-dropdown">
|
|
<button class="dropdown-toggle">
|
|
<i class="fas fa-chevron-down"></i>
|
|
</button>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="/admin/settings.html"><i class="fas fa-cog"></i> Settings</a></li>
|
|
<li class="divider"></li>
|
|
<li><a href="#" id="logout-btn"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Content -->
|
|
<div class="content-wrapper">
|
|
<!-- List View -->
|
|
<div id="list-view">
|
|
<div class="content-header">
|
|
<div class="content-filters">
|
|
<div class="filter-group">
|
|
<select id="category-filter">
|
|
<option value="">All Categories</option>
|
|
<option value="news">Company News</option>
|
|
<option value="events">Events</option>
|
|
<option value="insights">Industry Insights</option>
|
|
<option value="updates">Product Updates</option>
|
|
</select>
|
|
</div>
|
|
<div class="filter-group">
|
|
<select id="status-filter">
|
|
<option value="">All Status</option>
|
|
<option value="published">Published</option>
|
|
<option value="draft">Draft</option>
|
|
</select>
|
|
</div>
|
|
<div class="search-box">
|
|
<i class="fas fa-search"></i>
|
|
<input type="text" id="search-input" placeholder="Search news...">
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-primary" id="add-new-btn">
|
|
<i class="fas fa-plus"></i> Add New
|
|
</button>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="table-responsive">
|
|
<table class="data-table">
|
|
<thead>
|
|
<tr>
|
|
<th width="50">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="select-all">
|
|
<span class="checkmark"></span>
|
|
</label>
|
|
</th>
|
|
<th>Title</th>
|
|
<th width="120">Category</th>
|
|
<th width="100">Status</th>
|
|
<th width="120">Date</th>
|
|
<th width="120">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="news-table-body">
|
|
<!-- Data will be loaded via JS -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="table-footer">
|
|
<div class="bulk-actions">
|
|
<select id="bulk-action">
|
|
<option value="">Bulk Actions</option>
|
|
<option value="publish">Publish</option>
|
|
<option value="draft">Set as Draft</option>
|
|
<option value="delete">Delete</option>
|
|
</select>
|
|
<button class="btn btn-secondary btn-sm" id="apply-bulk">Apply</button>
|
|
</div>
|
|
<div class="pagination">
|
|
<span class="pagination-info" id="pagination-info">Showing 0 articles</span>
|
|
<div class="pagination-controls" id="pagination-controls">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Edit/Add Form -->
|
|
<div id="form-view" style="display: none;">
|
|
<div class="content-header">
|
|
<button class="btn btn-secondary" id="back-to-list">
|
|
<i class="fas fa-arrow-left"></i> Back to List
|
|
</button>
|
|
</div>
|
|
|
|
<form id="news-form" class="edit-form">
|
|
<div class="form-grid">
|
|
<div class="form-main">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2 id="form-title">Add New Article</h2>
|
|
</div>
|
|
<div class="card-body">
|
|
<input type="hidden" id="article-id" name="id">
|
|
|
|
<div class="form-group">
|
|
<label for="title">Title *</label>
|
|
<input type="text" id="title" name="title" required placeholder="Enter article title">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="slug">Slug</label>
|
|
<input type="text" id="slug" name="slug" placeholder="auto-generated-from-title">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="excerpt">Excerpt *</label>
|
|
<textarea id="excerpt" name="excerpt" rows="3" required placeholder="Brief description of the article"></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="content">Content *</label>
|
|
<textarea id="content" name="content" rows="15" required placeholder="Write your article content here..."></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-sidebar">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>Publish</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="form-group">
|
|
<label for="status">Status</label>
|
|
<select id="status" name="status">
|
|
<option value="draft">Draft</option>
|
|
<option value="published">Published</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="publish-date">Publish Date</label>
|
|
<input type="datetime-local" id="publish-date" name="publish_date">
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="button" class="btn btn-secondary btn-block" id="save-draft">
|
|
Save Draft
|
|
</button>
|
|
<button type="submit" class="btn btn-primary btn-block">
|
|
<i class="fas fa-check"></i> Publish
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>Category</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="form-group">
|
|
<select id="category" name="category" required>
|
|
<option value="">Select Category</option>
|
|
<option value="news">Company News</option>
|
|
<option value="events">Events</option>
|
|
<option value="insights">Industry Insights</option>
|
|
<option value="updates">Product Updates</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>Featured Image</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="image-upload" id="image-upload">
|
|
<div class="upload-placeholder" id="upload-placeholder">
|
|
<i class="fas fa-cloud-upload-alt"></i>
|
|
<p>Drag & drop or click to upload</p>
|
|
<span>Recommended: 800x500px</span>
|
|
</div>
|
|
<img id="image-preview" src="" alt="" style="display: none;">
|
|
<input type="file" id="featured-image" name="featured_image" accept="image/*" hidden>
|
|
<button type="button" class="btn btn-secondary btn-sm remove-image" id="remove-image" style="display: none;">
|
|
<i class="fas fa-times"></i> Remove
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>Author</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="form-group">
|
|
<input type="text" id="author" name="author" value="Admin" placeholder="Author name">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- Delete Confirmation Modal -->
|
|
<div class="modal" id="delete-modal">
|
|
<div class="modal-overlay"></div>
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h3>Confirm Delete</h3>
|
|
<button class="modal-close">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Are you sure you want to delete this article? This action cannot be undone.</p>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button class="btn btn-secondary modal-cancel">Cancel</button>
|
|
<button class="btn btn-danger" id="confirm-delete">Delete</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="/admin/js/admin.js"></script>
|
|
<script>
|
|
let allArticles = [];
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
loadArticles();
|
|
setupEventListeners();
|
|
|
|
// Check for edit param in URL
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const editId = urlParams.get('edit');
|
|
const action = urlParams.get('action');
|
|
|
|
if (editId) {
|
|
editArticle(editId);
|
|
} else if (action === 'add') {
|
|
showForm();
|
|
}
|
|
});
|
|
|
|
function setupEventListeners() {
|
|
document.getElementById('add-new-btn').addEventListener('click', showForm);
|
|
document.getElementById('back-to-list').addEventListener('click', showList);
|
|
document.getElementById('news-form').addEventListener('submit', saveArticle);
|
|
|
|
// Save draft button
|
|
document.getElementById('save-draft').addEventListener('click', function() {
|
|
document.getElementById('status').value = 'draft';
|
|
document.getElementById('news-form').dispatchEvent(new Event('submit', { cancelable: true }));
|
|
});
|
|
|
|
// Bulk actions
|
|
document.getElementById('apply-bulk').addEventListener('click', applyBulkAction);
|
|
|
|
// Filters
|
|
document.getElementById('category-filter').addEventListener('change', filterArticles);
|
|
document.getElementById('status-filter').addEventListener('change', filterArticles);
|
|
document.getElementById('search-input').addEventListener('input', MSPE.debounce(filterArticles, 300));
|
|
|
|
// Select all
|
|
document.getElementById('select-all').addEventListener('change', function() {
|
|
document.querySelectorAll('.row-select').forEach(cb => cb.checked = this.checked);
|
|
});
|
|
|
|
// Image upload handling
|
|
const imageUpload = document.getElementById('image-upload');
|
|
const imageInput = document.getElementById('featured-image');
|
|
const removeImageBtn = document.getElementById('remove-image');
|
|
|
|
imageUpload.addEventListener('click', function(e) {
|
|
if (e.target !== removeImageBtn && !removeImageBtn.contains(e.target)) {
|
|
imageInput.click();
|
|
}
|
|
});
|
|
|
|
imageInput.addEventListener('change', function() {
|
|
if (this.files && this.files[0]) {
|
|
const reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
document.getElementById('image-preview').src = e.target.result;
|
|
document.getElementById('image-preview').style.display = 'block';
|
|
document.getElementById('upload-placeholder').style.display = 'none';
|
|
removeImageBtn.style.display = 'block';
|
|
};
|
|
reader.readAsDataURL(this.files[0]);
|
|
}
|
|
});
|
|
|
|
removeImageBtn.addEventListener('click', function(e) {
|
|
e.stopPropagation();
|
|
imageInput.value = '';
|
|
document.getElementById('image-preview').style.display = 'none';
|
|
document.getElementById('image-preview').src = '';
|
|
document.getElementById('upload-placeholder').style.display = 'flex';
|
|
removeImageBtn.style.display = 'none';
|
|
});
|
|
|
|
// Auto-slug
|
|
document.getElementById('title').addEventListener('input', function() {
|
|
const slug = this.value
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/(^-|-$)/g, '');
|
|
document.getElementById('slug').value = slug;
|
|
});
|
|
}
|
|
|
|
async function loadArticles() {
|
|
try {
|
|
const response = await MSPE.API.get('news.php');
|
|
if (response && response.success) {
|
|
allArticles = response.data;
|
|
renderArticles(allArticles);
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load articles:', error);
|
|
document.getElementById('news-table-body').innerHTML = `
|
|
<tr><td colspan="6" class="text-center">Failed to load articles</td></tr>
|
|
`;
|
|
}
|
|
}
|
|
|
|
function renderArticles(articles) {
|
|
const tbody = document.getElementById('news-table-body');
|
|
|
|
// Update pagination info
|
|
const infoEl = document.getElementById('pagination-info');
|
|
if (infoEl) {
|
|
infoEl.textContent = articles.length === 0
|
|
? 'No articles'
|
|
: `Showing ${articles.length} article${articles.length !== 1 ? 's' : ''}`;
|
|
}
|
|
|
|
if (articles.length === 0) {
|
|
tbody.innerHTML = `
|
|
<tr>
|
|
<td colspan="6">
|
|
<div class="empty-state">
|
|
<i class="fas fa-newspaper"></i>
|
|
<p>No articles found</p>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
tbody.innerHTML = articles.map(article => `
|
|
<tr>
|
|
<td>
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" class="row-select" value="${article.id}">
|
|
<span class="checkmark"></span>
|
|
</label>
|
|
</td>
|
|
<td>
|
|
<div class="table-item">
|
|
<img src="${article.featured_image || 'https://via.placeholder.com/60x40'}" alt="" style="object-fit: cover; width: 60px; height: 40px;">
|
|
<span>${article.title}</span>
|
|
</div>
|
|
</td>
|
|
<td><span class="category-badge ${article.category}">${article.category}</span></td>
|
|
<td><span class="status-badge ${article.status}">${article.status}</span></td>
|
|
<td>${MSPE.formatDate(article.created_at)}</td>
|
|
<td>
|
|
<div class="table-actions">
|
|
<button class="action-btn edit" onclick="editArticle('${article.id}')" title="Edit"><i class="fas fa-edit"></i></button>
|
|
<button class="action-btn delete" onclick="deleteArticle('${article.id}')" title="Delete"><i class="fas fa-trash"></i></button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
|
|
function filterArticles() {
|
|
const category = document.getElementById('category-filter').value;
|
|
const status = document.getElementById('status-filter').value;
|
|
const search = document.getElementById('search-input').value.toLowerCase();
|
|
|
|
let filtered = allArticles;
|
|
|
|
if (category) filtered = filtered.filter(a => a.category === category);
|
|
if (status) filtered = filtered.filter(a => a.status === status);
|
|
if (search) filtered = filtered.filter(a => a.title.toLowerCase().includes(search));
|
|
|
|
renderArticles(filtered);
|
|
}
|
|
|
|
function showForm() {
|
|
document.getElementById('list-view').style.display = 'none';
|
|
document.getElementById('form-view').style.display = 'block';
|
|
document.getElementById('form-title').textContent = 'Add New Article';
|
|
document.getElementById('news-form').reset();
|
|
document.getElementById('article-id').value = '';
|
|
|
|
// Reset image
|
|
document.getElementById('image-preview').style.display = 'none';
|
|
document.getElementById('upload-placeholder').style.display = 'flex';
|
|
document.getElementById('remove-image').style.display = 'none';
|
|
}
|
|
|
|
function showList() {
|
|
document.getElementById('form-view').style.display = 'none';
|
|
document.getElementById('list-view').style.display = 'block';
|
|
// Update URL without refresh
|
|
const url = new URL(window.location);
|
|
url.searchParams.delete('edit');
|
|
url.searchParams.delete('action');
|
|
window.history.pushState({}, '', url);
|
|
}
|
|
|
|
async function editArticle(id) {
|
|
try {
|
|
const response = await MSPE.API.get(`news.php?id=${id}`);
|
|
if (response && response.success) {
|
|
const article = response.data;
|
|
|
|
showForm();
|
|
document.getElementById('form-title').textContent = 'Edit Article';
|
|
document.getElementById('article-id').value = article.id;
|
|
document.getElementById('title').value = article.title;
|
|
document.getElementById('slug').value = article.slug || '';
|
|
document.getElementById('excerpt').value = article.excerpt || '';
|
|
document.getElementById('content').value = article.content || '';
|
|
document.getElementById('category').value = article.category;
|
|
document.getElementById('status').value = article.status;
|
|
document.getElementById('author').value = article.author;
|
|
|
|
if (article.featured_image) {
|
|
document.getElementById('image-preview').src = article.featured_image;
|
|
document.getElementById('image-preview').style.display = 'block';
|
|
document.getElementById('upload-placeholder').style.display = 'none';
|
|
document.getElementById('remove-image').style.display = 'block';
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load article:', error);
|
|
MSPE.showNotification('Failed to load article details', 'error');
|
|
}
|
|
}
|
|
|
|
async function saveArticle(e) {
|
|
e.preventDefault();
|
|
|
|
const form = e.target;
|
|
const formData = new FormData(form);
|
|
const submitBtn = form.querySelector('button[type="submit"]');
|
|
|
|
submitBtn.disabled = true;
|
|
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Saving...';
|
|
|
|
try {
|
|
const result = await MSPE.API.upload('news.php', formData);
|
|
|
|
if (result && result.success) {
|
|
MSPE.showNotification('Article saved successfully', 'success');
|
|
loadArticles();
|
|
showList();
|
|
} else {
|
|
MSPE.showNotification(result?.message || 'Failed to save article', 'error');
|
|
}
|
|
} catch (error) {
|
|
console.error('Save error:', error);
|
|
MSPE.showNotification('An error occurred while saving', 'error');
|
|
} finally {
|
|
submitBtn.disabled = false;
|
|
submitBtn.innerHTML = '<i class="fas fa-check"></i> Publish';
|
|
}
|
|
}
|
|
|
|
async function deleteArticle(id) {
|
|
if (!await MSPE.confirmDialog('Are you sure you want to delete this article?')) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await MSPE.API.delete(`news.php?id=${id}`);
|
|
if (response && response.success) {
|
|
MSPE.showNotification('Article deleted successfully', 'success');
|
|
loadArticles();
|
|
}
|
|
} catch (error) {
|
|
console.error('Delete error:', error);
|
|
MSPE.showNotification('Failed to delete article', 'error');
|
|
}
|
|
}
|
|
|
|
async function applyBulkAction() {
|
|
const action = document.getElementById('bulk-action').value;
|
|
if (!action) {
|
|
MSPE.showNotification('Please select a bulk action', 'warning');
|
|
return;
|
|
}
|
|
|
|
const selected = Array.from(document.querySelectorAll('.row-select:checked')).map(cb => cb.value);
|
|
if (selected.length === 0) {
|
|
MSPE.showNotification('No articles selected', 'warning');
|
|
return;
|
|
}
|
|
|
|
if (action === 'delete') {
|
|
if (!await MSPE.confirmDialog(`Delete ${selected.length} selected article(s)?`)) return;
|
|
let success = 0;
|
|
for (const id of selected) {
|
|
try {
|
|
const res = await MSPE.API.delete(`news.php?id=${id}`);
|
|
if (res && res.success) success++;
|
|
} catch (e) { /* continue */ }
|
|
}
|
|
MSPE.showNotification(`${success} article(s) deleted`, 'success');
|
|
} else {
|
|
// publish or draft
|
|
let success = 0;
|
|
for (const id of selected) {
|
|
try {
|
|
const formData = new FormData();
|
|
formData.append('id', id);
|
|
formData.append('status', action === 'publish' ? 'published' : 'draft');
|
|
const res = await MSPE.API.upload('news.php', formData);
|
|
if (res && res.success) success++;
|
|
} catch (e) { /* continue */ }
|
|
}
|
|
MSPE.showNotification(`${success} article(s) updated`, 'success');
|
|
}
|
|
|
|
document.getElementById('select-all').checked = false;
|
|
loadArticles();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|