Added functionality to permenently delete or restore deleted organisations

This commit is contained in:
2022-02-10 15:52:57 +00:00
parent c3cf97ea50
commit 57dfed304f
10 changed files with 603 additions and 17 deletions

View File

@@ -8,20 +8,31 @@
*/
$(document).ready(function() {
if ($("#widget-organisations").length) {
$("#widget-organisations").ufTable({
dataUrl: site.uri.public + "/api/organisations",
useLoadingTransition: site.uf_table.use_loading_transition
});
$("#widget-organisations").ufTable({
dataUrl: site.uri.public + "/api/organisations",
useLoadingTransition: site.uf_table.use_loading_transition
});
// Bind creation button
bindOrganisationCreationButton($("#widget-organisations"));
// Bind creation button
bindOrganisationCreationButton($("#widget-organisations"));
// Bind registration button
bindOrganisationRegistrationButton($("#widget-organisations"));
// Bind registration button
bindOrganisationRegistrationButton($("#widget-organisations"));
// Bind table buttons
$("#widget-organisations").on("pagerComplete.ufTable", function () {
bindOrganisationButtons($(this));
});
} else {
$("#widget-deleted-organisations").ufTable({
dataUrl: site.uri.public + "/api/organisations/deleted",
useLoadingTransition: site.uf_table.use_loading_transition
});
// Bind table buttons
$("#widget-organisations").on("pagerComplete.ufTable", function () {
bindOrganisationButtons($(this));
});
// Bind table buttons
$("#widget-deleted-organisations").on("pagerComplete.ufTable", function () {
bindOrganisationButtons($(this));
});
}
});

View File

@@ -88,6 +88,47 @@ function approveOrganisation(slug, approve, options) {
});
}
/**
* Restore a deleted organisation
*/
function restoreOrganisation(slug, options) {
var data = {};
data[site.csrf.keys.name] = site.csrf.name;
data[site.csrf.keys.value] = site.csrf.value;
var url = site.uri.public + '/api/organisations/o/' + slug + '/restore';
var debugAjax = (typeof site !== "undefined") && site.debug.ajax;
return $.ajax({
type: "PUT",
url: url,
data: data,
dataType: debugAjax ? 'html' : 'json',
}).fail(function(jqXHR) {
// Error messages
if (debugAjax && jqXHR.responseText) {
document.write(jqXHR.responseText);
document.close();
} else {
console.log("Error (" + jqXHR.status + "): " + jqXHR.responseText);
// Display errors on failure
// TODO: ufAlerts widget should have a 'destroy' method
if (!$("#alerts-page").data('ufAlerts')) {
$("#alerts-page").ufAlerts();
} else {
$("#alerts-page").ufAlerts('clear');
}
$("#alerts-page").ufAlerts('fetch').ufAlerts('render');
}
return jqXHR;
}).done(function(response) {
window.location.reload();
});
}
/**
* Link organisation action buttons, for example in a table or on a specific organisation's page.
* @param {module:jQuery} el jQuery wrapped element to target.
@@ -263,6 +304,53 @@ function bindOrganisationButtons(el, options) {
});
});
});
// View the deleted organisations page
el.find('.js-organisation-viewDeleted').click(function(e) {
e.preventDefault();
window.location.href = site.uri.public + '/organisations/deleted';
});
// Permenetly delete organisation button
el.find('.js-organisation-permenentDelete').click(function(e) {
e.preventDefault();
$("body").ufModal({
sourceUrl: site.uri.public + "/modals/organisations/confirm-permenent-delete",
ajaxParams: {
slug: $(this).data('slug')
},
msgTarget: $("#alerts-page")
});
$("body").on('renderSuccess.ufModal', function() {
var modal = $(this).ufModal('getModal');
var form = modal.find('.js-form');
form.ufForm()
.on("submitSuccess.ufForm", function() {
// Navigate or reload page on success
if (options.delete_redirect) window.location.href = options.delete_redirect;
else window.location.reload();
});
});
});
// Permenetly delete organisation button
el.find('.js-organisation-restore').click(function(e) {
e.preventDefault();
restoreOrganisation($(this).data('slug'), options);
});
// Return from the deleted organisations page
el.find('.js-organisation-return').click(function(e) {
e.preventDefault();
window.location.href = site.uri.public + '/organisations';
});
}
function bindOrganisationCreationButton(el) {