Create organisation functionality
This commit is contained in:
@@ -13,4 +13,7 @@ $(document).ready(function() {
|
||||
dataUrl: site.uri.public + "/api/organisations",
|
||||
useLoadingTransition: site.uf_table.use_loading_transition
|
||||
});
|
||||
|
||||
// Bind creation button
|
||||
bindOrganisationCreationButton($("#widget-organisations"));
|
||||
});
|
||||
|
||||
61
assets/avsdev/js/widgets/organisations.js
Normal file
61
assets/avsdev/js/widgets/organisations.js
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Organisations widget. Sets up dropdowns, modals, etc for a table of organisations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set up the form in a modal after being successfully attached to the body.
|
||||
*/
|
||||
function attachOrganisationForm() {
|
||||
$("body").on('renderSuccess.ufModal', function(data) {
|
||||
var modal = $(this).ufModal('getModal');
|
||||
var form = modal.find('.js-form');
|
||||
|
||||
/**
|
||||
* Set up modal widgets
|
||||
*/
|
||||
// Set up any widgets inside the modal
|
||||
form.find(".js-select2").select2({
|
||||
width: '100%'
|
||||
});
|
||||
|
||||
// Auto-generate slug
|
||||
form.find('input[name=name]').on('input change', function() {
|
||||
var manualSlug = form.find('#form-organisation-slug-override').prop('checked');
|
||||
if (!manualSlug) {
|
||||
var slug = getSlug($(this).val());
|
||||
form.find('input[name=slug]').val(slug);
|
||||
}
|
||||
});
|
||||
|
||||
form.find('#form-organisation-slug-override').on('change', function() {
|
||||
if ($(this).prop('checked')) {
|
||||
form.find('input[name=slug]').prop('readonly', false);
|
||||
} else {
|
||||
form.find('input[name=slug]').prop('readonly', true);
|
||||
form.find('input[name=name]').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
// Set up the form for submission
|
||||
form.ufForm({
|
||||
validator: page.validators
|
||||
}).on("submitSuccess.ufForm", function() {
|
||||
// Reload page on success
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindOrganisationCreationButton(el) {
|
||||
// Link create button
|
||||
el.find('.js-organisation-create').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/create",
|
||||
msgTarget: $("#alerts-page")
|
||||
});
|
||||
|
||||
attachOrganisationForm();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user