cutom edit contribution modal
This commit is contained in:
@@ -349,6 +349,33 @@ $news_items = $stmt->fetchAll();
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ============================================================= -->
|
||||||
|
<!-- Edit Contribution Modal -->
|
||||||
|
<!-- ============================================================= -->
|
||||||
|
<div id="edit-modal" class="modal-overlay" style="display:none;">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h2><i class="fa-solid fa-pen"></i> Beitrag bearbeiten</h2>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-title">Titel</label>
|
||||||
|
<input type="text" id="edit-title" class="form-input">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-description">Beschreibung</label>
|
||||||
|
<textarea id="edit-description" class="form-input" rows="4"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" id="edit-contribution-id">
|
||||||
|
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button class="btn btn-secondary" onclick="closeEditModal()">Abbrechen</button>
|
||||||
|
<button class="btn btn-primary" onclick="submitEdit()">Speichern</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- ============================================================= -->
|
<!-- ============================================================= -->
|
||||||
<!-- Loads JavaScript Dependencies -->
|
<!-- Loads JavaScript Dependencies -->
|
||||||
<!-- ============================================================= -->
|
<!-- ============================================================= -->
|
||||||
|
|||||||
@@ -653,58 +653,55 @@ function closeCreateModal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE: Edits existing Contributions
|
// UPDATE: Edits existing Contributions
|
||||||
|
// UPDATE: Opens Edit Modal for existing Contributions
|
||||||
function editContribution(contributionId) {
|
function editContribution(contributionId) {
|
||||||
// Finds Contribution in local Data
|
|
||||||
const contribution = contributionsData.find(function (f) {
|
const contribution = contributionsData.find(function (f) {
|
||||||
return f.properties.contribution_id === contributionId;
|
return f.properties.contribution_id === contributionId;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!contribution) return;
|
if (!contribution) return;
|
||||||
|
|
||||||
const props = contribution.properties;
|
const props = contribution.properties;
|
||||||
|
document.getElementById('edit-contribution-id').value = contributionId;
|
||||||
|
document.getElementById('edit-title').value = props.title;
|
||||||
|
document.getElementById('edit-description').value = props.description || '';
|
||||||
|
document.getElementById('edit-modal').style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
Swal.fire({
|
// Submits Edit from Custom Modal
|
||||||
title: 'Beitrag bearbeiten',
|
function submitEdit() {
|
||||||
html:
|
const contributionId = document.getElementById('edit-contribution-id').value;
|
||||||
'<div class="swal-form">' +
|
const title = document.getElementById('edit-title').value.trim();
|
||||||
'<div class="swal-group">' +
|
const description = document.getElementById('edit-description').value.trim();
|
||||||
'<label class="swal-label">Titel</label>' +
|
|
||||||
'<input id="swal-title" class="swal2-input" value="' + escapeHtml(props.title) + '">' +
|
if (!title) {
|
||||||
'</div>' +
|
Swal.fire('Titel fehlt', 'Bitte geben Sie einen Titel ein.', 'warning');
|
||||||
'<div>' +
|
return;
|
||||||
'<label class="swal-label">Beschreibung</label>' +
|
}
|
||||||
'<textarea id="swal-description" class="swal2-textarea">' + escapeHtml(props.description || '') + '</textarea>' +
|
|
||||||
'</div>' +
|
apiCall({
|
||||||
'</div>',
|
action: 'update',
|
||||||
showCancelButton: true,
|
contribution_id: contributionId,
|
||||||
confirmButtonText: 'Speichern',
|
title: title,
|
||||||
cancelButtonText: 'Abbrechen',
|
description: description
|
||||||
confirmButtonColor: MUNICIPALITY.primaryColor,
|
}, function (response) {
|
||||||
preConfirm: function () {
|
if (response.error) {
|
||||||
return {
|
Swal.fire('Fehler', response.error, 'error');
|
||||||
title: document.getElementById('swal-title').value.trim(),
|
return;
|
||||||
description: document.getElementById('swal-description').value.trim()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}).then(function (result) {
|
closeEditModal();
|
||||||
if (!result.isConfirmed) return;
|
Swal.fire('Gespeichert!', 'Der Beitrag wurde aktualisiert.', 'success');
|
||||||
|
loadContributions();
|
||||||
apiCall({
|
|
||||||
action: 'update',
|
|
||||||
contribution_id: contributionId,
|
|
||||||
title: result.value.title,
|
|
||||||
description: result.value.description
|
|
||||||
}, function (response) {
|
|
||||||
if (response.error) {
|
|
||||||
Swal.fire('Fehler', response.error, 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Swal.fire('Gespeichert!', 'Der Beitrag wurde aktualisiert.', 'success');
|
|
||||||
loadContributions();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Closes Edit Modal
|
||||||
|
function closeEditModal() {
|
||||||
|
document.getElementById('edit-modal').style.display = 'none';
|
||||||
|
document.getElementById('edit-contribution-id').value = '';
|
||||||
|
document.getElementById('edit-title').value = '';
|
||||||
|
document.getElementById('edit-description').value = '';
|
||||||
|
}
|
||||||
|
|
||||||
// DELETE: Deletes existing Contributions
|
// DELETE: Deletes existing Contributions
|
||||||
function deleteContribution(contributionId) {
|
function deleteContribution(contributionId) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
@@ -1082,6 +1079,7 @@ document.addEventListener('keydown', function (e) {
|
|||||||
document.getElementById('welcome-modal').style.display = 'none';
|
document.getElementById('welcome-modal').style.display = 'none';
|
||||||
document.getElementById('login-modal').style.display = 'none';
|
document.getElementById('login-modal').style.display = 'none';
|
||||||
document.getElementById('create-modal').style.display = 'none';
|
document.getElementById('create-modal').style.display = 'none';
|
||||||
|
document.getElementById('edit-modal').style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user