forked from UKSOURCE/cms.hailearning.edu.vn
first commit
This commit is contained in:
@@ -1,126 +1,112 @@
|
||||
<!-- Header section -->
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-between align-items-center mt-4 mb-4">
|
||||
<div>
|
||||
<h1 class="h3 mb-0" style="color: var(--primary-dark);">Department Management</h1>
|
||||
<p class="text-muted mb-0">Manage all departments in the system</p>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/admin/department/create" class="btn btn-primary">
|
||||
<i class="fas fa-plus-circle me-1"></i>Create New Department
|
||||
</a>
|
||||
<!-- Page Header -->
|
||||
<div class="page-title-area">
|
||||
<div>
|
||||
<h1>Department Management</h1>
|
||||
<p class="subtitle">All departments registered in the system</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<!-- Add Form -->
|
||||
<div class="col-lg-4">
|
||||
<div class="card border-0">
|
||||
<div class="card-header">
|
||||
<h5 class="card-header-title"><i class="fas fa-plus-circle"></i> Add Department</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="/admin/department/create">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Department Name <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="name" placeholder="Enter department name..." required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">
|
||||
<i class="fas fa-plus"></i> Add Department
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<% if (departments && departments.length > 0) { %>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead>
|
||||
<!-- Table -->
|
||||
<div class="col-lg-8">
|
||||
<div class="card border-0">
|
||||
<div class="card-header">
|
||||
<h5 class="card-header-title"><i class="fas fa-building"></i> Departments</h5>
|
||||
<span class="badge badge-soft-primary"><%= departments ? departments.length : 0 %> total</span>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<% if (departments && departments.length > 0) { %>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:50px">#</th>
|
||||
<th>Department Name</th>
|
||||
<th>Slug</th>
|
||||
<th style="width:130px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% departments.forEach((department, index) => { %>
|
||||
<tr>
|
||||
<th scope="col" style="width: 50px">#</th>
|
||||
<th scope="col">Department Name</th>
|
||||
<th scope="col">Slug</th>
|
||||
<th scope="col" style="width: 200px">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% departments.forEach((department, index) => { %>
|
||||
<tr>
|
||||
<td><%= index + 1 %></td>
|
||||
<td>
|
||||
<span class="fw-medium"><%= department.name %></span>
|
||||
</td>
|
||||
<td>
|
||||
<code class="text-muted"><%= department.slug %></code>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group" role="group">
|
||||
<a href="/admin/department/edit/<%= department._id %>" class="btn btn-sm btn-outline-primary">
|
||||
<i class="fas fa-edit me-1"></i>Edit
|
||||
</a>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger"
|
||||
data-custom-modal="open"
|
||||
data-id="<%= department._id %>"
|
||||
data-name="<%= department.name %>">
|
||||
<i class="fas fa-trash-alt me-1"></i>Delete
|
||||
<td style="color:var(--text-muted)"><%= index + 1 %></td>
|
||||
<td>
|
||||
<span class="dept-name-display-<%= department._id %>" style="font-weight:500"><%= department.name %></span>
|
||||
<form method="POST" action="/admin/department/<%= department._id %>/edit"
|
||||
class="dept-edit-form-<%= department._id %> d-none d-flex gap-2 align-items-center">
|
||||
<input type="text" class="form-control form-control-sm" name="name" value="<%= department.name %>" required>
|
||||
<button type="submit" class="btn btn-sm btn-outline-primary btn-icon" title="Save">
|
||||
<i class="fas fa-check"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary btn-icon" title="Cancel"
|
||||
onclick="cancelEdit('<%= department._id %>')">
|
||||
<i class="fas fa-times"></i>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
<td><code style="font-size:0.8rem;color:var(--text-muted)"><%= department.slug %></code></td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary btn-icon" title="Edit"
|
||||
onclick="startEdit('<%= department._id %>')">
|
||||
<i class="fas fa-pen"></i>
|
||||
</button>
|
||||
<form method="POST" action="/admin/department/<%= department._id %>/delete" style="display:inline;"
|
||||
onsubmit="return confirm('Delete department \"<%= department.name %>\"?')">
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger btn-icon" title="Delete">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% }); %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<div class="text-center py-5">
|
||||
<i class="fas fa-folder-open text-muted mb-3" style="font-size: 3rem;"></i>
|
||||
<h5 class="text-muted mb-3">No Departments Found</h5>
|
||||
<a href="/admin/department/create" class="btn btn-primary">
|
||||
<i class="fas fa-plus-circle me-1"></i>Create First Department
|
||||
</a>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% }); %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon"><i class="fas fa-building"></i></div>
|
||||
<h5>No departments yet</h5>
|
||||
<p>Use the form on the left to add the first department.</p>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Custom Modal -->
|
||||
<div id="customModal" class="custom-modal">
|
||||
<div class="custom-modal-content">
|
||||
<div class="custom-modal-header">
|
||||
<h5 class="custom-modal-title">Delete Confirmation</h5>
|
||||
<button type="button" class="custom-modal-close">×</button>
|
||||
</div>
|
||||
<div class="custom-modal-body">
|
||||
<p id="modalMessage">Are you sure you want to delete this department?</p>
|
||||
</div>
|
||||
<div class="custom-modal-footer">
|
||||
<button type="button" class="btn btn-secondary custom-modal-cancel">Cancel</button>
|
||||
<button type="button" class="btn btn-danger custom-modal-ok">Delete Permanently</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Import custom modal CSS -->
|
||||
<link rel="stylesheet" href="/css/custom-modal.css">
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Khởi tạo modal tùy chỉnh
|
||||
CustomModal.init('customModal', {
|
||||
closeOnOutsideClick: true,
|
||||
animationDuration: 300
|
||||
});
|
||||
|
||||
// Lắng nghe click vào nút xóa
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target.getAttribute('data-custom-modal') === 'open' ||
|
||||
e.target.parentElement.getAttribute('data-custom-modal') === 'open') {
|
||||
|
||||
// Lấy button hoặc icon parent nếu click vào icon
|
||||
const button = e.target.getAttribute('data-custom-modal') === 'open' ?
|
||||
e.target : e.target.parentElement;
|
||||
|
||||
const id = button.getAttribute('data-id');
|
||||
const name = button.getAttribute('data-name');
|
||||
|
||||
// Sử dụng CustomModal.confirm thay vì xử lý trực tiếp
|
||||
CustomModal.confirm(
|
||||
`Are you sure you want to delete department "${name}"? This action cannot be undone.`,
|
||||
function() {
|
||||
// Hành động khi xác nhận
|
||||
window.location.href = `/admin/department/delete/${id}`;
|
||||
},
|
||||
null,
|
||||
'Delete Confirmation'
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
function startEdit(id) {
|
||||
document.querySelector('.dept-name-display-' + id).classList.add('d-none');
|
||||
const form = document.querySelector('.dept-edit-form-' + id);
|
||||
form.classList.remove('d-none');
|
||||
form.classList.add('d-flex');
|
||||
}
|
||||
function cancelEdit(id) {
|
||||
document.querySelector('.dept-name-display-' + id).classList.remove('d-none');
|
||||
const form = document.querySelector('.dept-edit-form-' + id);
|
||||
form.classList.add('d-none');
|
||||
form.classList.remove('d-flex');
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user