cutom edit contribution modal
This commit is contained in:
@@ -653,58 +653,55 @@ function closeCreateModal() {
|
||||
}
|
||||
|
||||
// UPDATE: Edits existing Contributions
|
||||
// UPDATE: Opens Edit Modal for existing Contributions
|
||||
function editContribution(contributionId) {
|
||||
// Finds Contribution in local Data
|
||||
const contribution = contributionsData.find(function (f) {
|
||||
return f.properties.contribution_id === contributionId;
|
||||
});
|
||||
|
||||
if (!contribution) return;
|
||||
|
||||
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({
|
||||
title: 'Beitrag bearbeiten',
|
||||
html:
|
||||
'<div class="swal-form">' +
|
||||
'<div class="swal-group">' +
|
||||
'<label class="swal-label">Titel</label>' +
|
||||
'<input id="swal-title" class="swal2-input" value="' + escapeHtml(props.title) + '">' +
|
||||
'</div>' +
|
||||
'<div>' +
|
||||
'<label class="swal-label">Beschreibung</label>' +
|
||||
'<textarea id="swal-description" class="swal2-textarea">' + escapeHtml(props.description || '') + '</textarea>' +
|
||||
'</div>' +
|
||||
'</div>',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Speichern',
|
||||
cancelButtonText: 'Abbrechen',
|
||||
confirmButtonColor: MUNICIPALITY.primaryColor,
|
||||
preConfirm: function () {
|
||||
return {
|
||||
title: document.getElementById('swal-title').value.trim(),
|
||||
description: document.getElementById('swal-description').value.trim()
|
||||
};
|
||||
// Submits Edit from Custom Modal
|
||||
function submitEdit() {
|
||||
const contributionId = document.getElementById('edit-contribution-id').value;
|
||||
const title = document.getElementById('edit-title').value.trim();
|
||||
const description = document.getElementById('edit-description').value.trim();
|
||||
|
||||
if (!title) {
|
||||
Swal.fire('Titel fehlt', 'Bitte geben Sie einen Titel ein.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
apiCall({
|
||||
action: 'update',
|
||||
contribution_id: contributionId,
|
||||
title: title,
|
||||
description: description
|
||||
}, function (response) {
|
||||
if (response.error) {
|
||||
Swal.fire('Fehler', response.error, 'error');
|
||||
return;
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (!result.isConfirmed) return;
|
||||
|
||||
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();
|
||||
});
|
||||
closeEditModal();
|
||||
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
|
||||
function deleteContribution(contributionId) {
|
||||
Swal.fire({
|
||||
@@ -1082,6 +1079,7 @@ document.addEventListener('keydown', function (e) {
|
||||
document.getElementById('welcome-modal').style.display = 'none';
|
||||
document.getElementById('login-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