fixed help articles
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
{% block title %}Support Articles - DocuPulse{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<meta name="csrf-token" content="{{ csrf_token }}">
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">
|
||||
<style>
|
||||
@@ -227,6 +231,7 @@
|
||||
<div class="modal-body">
|
||||
<p>Are you sure you want to delete this article? This action cannot be undone.</p>
|
||||
<p class="text-muted" id="deleteArticleTitle"></p>
|
||||
<input type="hidden" id="deleteArticleId" value="">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
@@ -295,7 +300,15 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
function loadArticles() {
|
||||
fetch('/api/admin/help-articles')
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
return response.text().then(text => {
|
||||
throw new Error(`Server returned non-JSON response: ${text.substring(0, 200)}...`);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
const articlesList = document.getElementById('articlesList');
|
||||
articlesList.innerHTML = '';
|
||||
@@ -377,7 +390,17 @@ function createArticle() {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
// Check if response is JSON
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
// If not JSON, get the text and throw an error
|
||||
return response.text().then(text => {
|
||||
throw new Error(`Server returned non-JSON response: ${text.substring(0, 200)}...`);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('createArticleModal'));
|
||||
@@ -398,7 +421,15 @@ function createArticle() {
|
||||
|
||||
function editArticle(articleId) {
|
||||
fetch(`/api/admin/help-articles/${articleId}`)
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
return response.text().then(text => {
|
||||
throw new Error(`Server returned non-JSON response: ${text.substring(0, 200)}...`);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
document.getElementById('editArticleId').value = data.article.id;
|
||||
document.getElementById('editArticleTitle').value = data.article.title;
|
||||
@@ -426,7 +457,15 @@ function updateArticle() {
|
||||
method: 'PUT',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
return response.text().then(text => {
|
||||
throw new Error(`Server returned non-JSON response: ${text.substring(0, 200)}...`);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('editArticleModal'));
|
||||
@@ -457,7 +496,15 @@ function deleteArticle() {
|
||||
fetch(`/api/admin/help-articles/${articleId}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
return response.text().then(text => {
|
||||
throw new Error(`Server returned non-JSON response: ${text.substring(0, 200)}...`);
|
||||
});
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const modal = bootstrap.Modal.getInstance(document.getElementById('deleteArticleModal'));
|
||||
|
||||
@@ -416,23 +416,5 @@
|
||||
{% include 'components/footer_nav.html' %}
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
// Search functionality
|
||||
document.querySelector('.search-box').addEventListener('input', function(e) {
|
||||
const searchTerm = e.target.value.toLowerCase();
|
||||
const faqItems = document.querySelectorAll('.faq-item');
|
||||
|
||||
faqItems.forEach(item => {
|
||||
const question = item.querySelector('.faq-question').textContent.toLowerCase();
|
||||
const answer = item.querySelector('.faq-answer').textContent.toLowerCase();
|
||||
|
||||
if (question.includes(searchTerm) || answer.includes(searchTerm)) {
|
||||
item.style.display = 'block';
|
||||
} else {
|
||||
item.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user