fixed help articles

This commit is contained in:
2025-06-25 13:34:43 +02:00
parent 0466b11c71
commit de3880e880
6 changed files with 64 additions and 23 deletions

View File

@@ -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'));