282 lines
7.7 KiB
Plaintext
282 lines
7.7 KiB
Plaintext
|
|
<% if(it.layout_clean_mode) {%> <% layout("../layouts/admin/Clean", {get_page_name:()=> "Termination Configuration"}) %><% } else {%> <% layout("../layouts/admin/Main",{get_page_name:()=> "Termination Configuration"}) %><%}%>
|
||
|
|
|
||
|
|
<style>
|
||
|
|
.config-form {
|
||
|
|
max-width: 800px;
|
||
|
|
margin: 0 auto;
|
||
|
|
}
|
||
|
|
.config-item {
|
||
|
|
background: #fff;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 20px;
|
||
|
|
margin-bottom: 20px;
|
||
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||
|
|
}
|
||
|
|
.form-group {
|
||
|
|
margin-bottom: 20px;
|
||
|
|
}
|
||
|
|
.form-group label {
|
||
|
|
font-weight: bold;
|
||
|
|
margin-bottom: 8px;
|
||
|
|
display: block;
|
||
|
|
}
|
||
|
|
.form-control {
|
||
|
|
width: 100%;
|
||
|
|
padding: 10px;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
border-radius: 4px;
|
||
|
|
font-size: 14px;
|
||
|
|
}
|
||
|
|
.form-control:focus {
|
||
|
|
outline: none;
|
||
|
|
border-color: #007bff;
|
||
|
|
box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
|
||
|
|
}
|
||
|
|
textarea.form-control {
|
||
|
|
min-height: 100px;
|
||
|
|
resize: vertical;
|
||
|
|
}
|
||
|
|
.btn {
|
||
|
|
padding: 10px 20px;
|
||
|
|
border: none;
|
||
|
|
border-radius: 4px;
|
||
|
|
cursor: pointer;
|
||
|
|
font-size: 14px;
|
||
|
|
margin-right: 10px;
|
||
|
|
}
|
||
|
|
.btn-primary {
|
||
|
|
background: #007bff;
|
||
|
|
color: white;
|
||
|
|
}
|
||
|
|
.btn-primary:hover {
|
||
|
|
background: #0056b3;
|
||
|
|
}
|
||
|
|
.btn-success {
|
||
|
|
background: #28a745;
|
||
|
|
color: white;
|
||
|
|
}
|
||
|
|
.btn-success:hover {
|
||
|
|
background: #1e7e34;
|
||
|
|
}
|
||
|
|
.btn-danger {
|
||
|
|
background: #dc3545;
|
||
|
|
color: white;
|
||
|
|
}
|
||
|
|
.btn-danger:hover {
|
||
|
|
background: #c82333;
|
||
|
|
}
|
||
|
|
.alert {
|
||
|
|
padding: 12px 16px;
|
||
|
|
border-radius: 4px;
|
||
|
|
margin-bottom: 20px;
|
||
|
|
}
|
||
|
|
.alert-success {
|
||
|
|
background: #d4edda;
|
||
|
|
border: 1px solid #c3e6cb;
|
||
|
|
color: #155724;
|
||
|
|
}
|
||
|
|
.alert-danger {
|
||
|
|
background: #f8d7da;
|
||
|
|
border: 1px solid #f5c6cb;
|
||
|
|
color: #721c24;
|
||
|
|
}
|
||
|
|
.config-list {
|
||
|
|
margin-top: 30px;
|
||
|
|
}
|
||
|
|
.config-header {
|
||
|
|
background: #f8f9fa;
|
||
|
|
padding: 15px 20px;
|
||
|
|
border-bottom: 1px solid #ddd;
|
||
|
|
border-radius: 8px 8px 0 0;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
|
||
|
|
<div class="tab-content mx-2 my-2 mx-lg-4 my-lg-4 bg-white p-3" id="nav-tabContent">
|
||
|
|
<div class="config-form">
|
||
|
|
<h2 class="mb-4">Termination Configuration</h2>
|
||
|
|
|
||
|
|
<div id="alert-container"></div>
|
||
|
|
|
||
|
|
<!-- Add New Configuration Form -->
|
||
|
|
<div class="config-item">
|
||
|
|
<h4>Add New Configuration</h4>
|
||
|
|
<form id="add-config-form">
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="message">Termination Message:</label>
|
||
|
|
<textarea
|
||
|
|
id="message"
|
||
|
|
name="message"
|
||
|
|
class="form-control"
|
||
|
|
placeholder="Enter the message to display when quiz is terminated"
|
||
|
|
required
|
||
|
|
></textarea>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="title">Termination Title:</label>
|
||
|
|
<input
|
||
|
|
type="text"
|
||
|
|
id="title"
|
||
|
|
name="title"
|
||
|
|
class="form-control"
|
||
|
|
placeholder="Enter the title to display"
|
||
|
|
required
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="form-group">
|
||
|
|
<label for="counter">Counter (seconds):</label>
|
||
|
|
<input
|
||
|
|
type="number"
|
||
|
|
id="counter"
|
||
|
|
name="counter"
|
||
|
|
class="form-control"
|
||
|
|
placeholder="Enter countdown time in seconds"
|
||
|
|
min="1"
|
||
|
|
max="60"
|
||
|
|
required
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<button type="submit" class="btn btn-success">Add Configuration</button>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Existing Configurations -->
|
||
|
|
<div class="config-list">
|
||
|
|
<h4>Existing Configurations</h4>
|
||
|
|
<div id="configs-container">
|
||
|
|
<% if(it.configs && it.configs.length > 0) { %>
|
||
|
|
<% it.configs.forEach(function(config) { %>
|
||
|
|
<div class="config-item" data-id="<%= config.id %>">
|
||
|
|
<div class="config-header">
|
||
|
|
Configuration #<%= config.id %>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Message:</label>
|
||
|
|
<textarea class="form-control edit-message" data-field="message"><%= config.message %></textarea>
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Title:</label>
|
||
|
|
<input type="text" class="form-control edit-title" data-field="title" value="<%= config.title %>" />
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<label>Counter:</label>
|
||
|
|
<input type="number" class="form-control edit-counter" data-field="counter" value="<%= config.counter %>" min="1" max="60" />
|
||
|
|
</div>
|
||
|
|
<div class="form-group">
|
||
|
|
<button class="btn btn-primary update-config" data-id="<%= config.id %>">Update</button>
|
||
|
|
<button class="btn btn-danger delete-config" data-id="<%= config.id %>">Delete</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<% }); %>
|
||
|
|
<% } else { %>
|
||
|
|
<div class="config-item">
|
||
|
|
<p>No configurations found. Add one above to get started.</p>
|
||
|
|
</div>
|
||
|
|
<% } %>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
$(document).ready(function() {
|
||
|
|
// Add new configuration
|
||
|
|
$('#add-config-form').on('submit', function(e) {
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
const formData = {
|
||
|
|
message: $('#message').val(),
|
||
|
|
title: $('#title').val(),
|
||
|
|
counter: $('#counter').val()
|
||
|
|
};
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: '/admin/termination-config',
|
||
|
|
method: 'POST',
|
||
|
|
data: formData,
|
||
|
|
success: function(response) {
|
||
|
|
if (response.success) {
|
||
|
|
showAlert('Configuration added successfully!', 'success');
|
||
|
|
$('#add-config-form')[0].reset();
|
||
|
|
// Reload page to show new config
|
||
|
|
setTimeout(() => location.reload(), 1000);
|
||
|
|
} else {
|
||
|
|
showAlert('Failed to add configuration: ' + response.message, 'danger');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function() {
|
||
|
|
showAlert('Failed to add configuration. Please try again.', 'danger');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
// Update configuration
|
||
|
|
$(document).on('click', '.update-config', function() {
|
||
|
|
const id = $(this).data('id');
|
||
|
|
const configItem = $(this).closest('.config-item');
|
||
|
|
|
||
|
|
const formData = {
|
||
|
|
message: configItem.find('.edit-message').val(),
|
||
|
|
title: configItem.find('.edit-title').val(),
|
||
|
|
counter: configItem.find('.edit-counter').val()
|
||
|
|
};
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: `/admin/termination-config/${id}`,
|
||
|
|
method: 'PUT',
|
||
|
|
data: formData,
|
||
|
|
success: function(response) {
|
||
|
|
if (response.success) {
|
||
|
|
showAlert('Configuration updated successfully!', 'success');
|
||
|
|
} else {
|
||
|
|
showAlert('Failed to update configuration: ' + response.message, 'danger');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function() {
|
||
|
|
showAlert('Failed to update configuration. Please try again.', 'danger');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
// Delete configuration
|
||
|
|
$(document).on('click', '.delete-config', function() {
|
||
|
|
if (!confirm('Are you sure you want to delete this configuration?')) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const id = $(this).data('id');
|
||
|
|
const configItem = $(this).closest('.config-item');
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: `/admin/termination-config/${id}`,
|
||
|
|
method: 'DELETE',
|
||
|
|
success: function(response) {
|
||
|
|
if (response.success) {
|
||
|
|
showAlert('Configuration deleted successfully!', 'success');
|
||
|
|
configItem.fadeOut();
|
||
|
|
} else {
|
||
|
|
showAlert('Failed to delete configuration: ' + response.message, 'danger');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function() {
|
||
|
|
showAlert('Failed to delete configuration. Please try again.', 'danger');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
function showAlert(message, type) {
|
||
|
|
const alertHtml = `<div class="alert alert-${type}">${message}</div>`;
|
||
|
|
$('#alert-container').html(alertHtml);
|
||
|
|
|
||
|
|
// Auto-hide after 5 seconds
|
||
|
|
setTimeout(() => {
|
||
|
|
$('#alert-container').empty();
|
||
|
|
}, 5000);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|