Added capability to merge organisations

- Added an interface for organisation
- Added beforeDelete and beforeMerge callbacks
- Added hard/soft delete to organisations
This commit is contained in:
2022-02-07 16:20:30 +00:00
parent b6edcf03e8
commit 28255e315a
11 changed files with 536 additions and 2 deletions

View File

@@ -76,6 +76,63 @@ function bindOrganisationButtons(el, options) {
attachOrganisationForm();
});
// Manage organisation merge button
el.find('.js-organisation-merge').click(function(e) {
e.preventDefault();
var organisation_slug = $(this).data('slug');
$("body").ufModal({
sourceUrl: site.uri.public + "/modals/organisations/merge",
ajaxParams: {
slug: organisation_slug
},
msgTarget: $("#alerts-page")
});
$("body").on('renderSuccess.ufModal', function(data) {
var modal = $(this).ufModal('getModal');
var form = modal.find('.js-form');
var dropdownTemplate = modal.find('#organisation-select-option').html();
// Set up select2 dropdown
var dropdownControl = modal.find('.js-select-new');
_dropdownTemplateCompiled = Handlebars.compile(dropdownTemplate);
var options = {
ajax: {
url: site.uri.public + '/api/organisations',
processResults: function (data) {
var items = data.rows.filter((i) => i.slug != organisation_slug);
return {
results: items.map((i) => { return {
id: i.slug,
text: i.name,
name: i.name,
description: i.description,
slug: i.slug
}})
};
}
},
placeholder: "Select an organisation to merge with",
selectOnClose: true,
templateResult: $.proxy(function(item) {
// Must wrap this in a jQuery selector to render as HTML
return $(_dropdownTemplateCompiled(item));
}, this)
};
dropdownControl.select2(options);
// Set up form for submission
form.ufForm()
.on("submitSuccess.ufForm", function() {
// Reload page on success
window.location.reload();
});
});
});
// Delete organisation button
el.find('.js-organisation-delete').click(function(e) {
e.preventDefault();