Re-jigged some of the registration routes and modified the buttons/links to use them
This commit is contained in:
@@ -46,6 +46,48 @@ function attachOrganisationForm() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve/Reject organisation
|
||||
*/
|
||||
function approveOrganisation(slug, approve, 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 + '/registration/' + (approve ? 'approve' : 'reject');
|
||||
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) {
|
||||
if (!approve && options.delete_redirect) window.location.href = options.delete_redirect;
|
||||
else 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.
|
||||
@@ -183,6 +225,20 @@ function bindOrganisationButtons(el, options) {
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel a registration request
|
||||
el.find('.js-organisation-approveRegistration').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
approveOrganisation($(this).data('slug'), true, options);
|
||||
});
|
||||
|
||||
// Cancel a registration request
|
||||
el.find('.js-organisation-rejectRegistration').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
approveOrganisation($(this).data('slug'), false, options);
|
||||
});
|
||||
|
||||
// Delete organisation button
|
||||
el.find('.js-organisation-delete').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user