De-conflict asset bundles
This commit is contained in:
25
assets/organisations/js/pages/organisation.js
Normal file
25
assets/organisations/js/pages/organisation.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
|
||||
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
|
||||
*
|
||||
* This script depends on uf-table.js, moment.js, handlebars-helpers.js, widgets/users.js
|
||||
*
|
||||
* Target page: /organisations/o/{slug}
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
// Control buttons
|
||||
bindOrganisationButtons($("#view-organisation"), { delete_redirect: page.delete_redirect, leave_redirect: page.leave_redirect });
|
||||
|
||||
// Table of users in this organisation
|
||||
$("#widget-organisation-members").ufTable({
|
||||
dataUrl: site.uri.public + '/api/organisations/o/' + page.organisation_slug + '/members',
|
||||
useLoadingTransition: site.uf_table.use_loading_transition
|
||||
});
|
||||
|
||||
// Bind user table buttons
|
||||
$("#widget-organisation-members").on("pagerComplete.ufTable", function () {
|
||||
bindMemberButtons($(this));
|
||||
bindUserButtons($(this));
|
||||
});
|
||||
});
|
||||
38
assets/organisations/js/pages/organisations.js
Normal file
38
assets/organisations/js/pages/organisations.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
|
||||
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
|
||||
*
|
||||
* This script depends on widgets/organisations.js, uf-table.js, moment.js, handlebars-helpers.js
|
||||
*
|
||||
* Target page: /organisations
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
if ($("#widget-organisations").length) {
|
||||
$("#widget-organisations").ufTable({
|
||||
dataUrl: site.uri.public + "/api/organisations",
|
||||
useLoadingTransition: site.uf_table.use_loading_transition
|
||||
});
|
||||
|
||||
// Bind creation button
|
||||
bindOrganisationCreationButton($("#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-deleted-organisations").on("pagerComplete.ufTable", function () {
|
||||
bindOrganisationButtons($(this));
|
||||
});
|
||||
}
|
||||
});
|
||||
13
assets/organisations/js/pages/user.js
Normal file
13
assets/organisations/js/pages/user.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
|
||||
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
|
||||
*
|
||||
* This script depends on uf-table.js, moment.js, handlebars-helpers.js
|
||||
*
|
||||
* Target page: /users/u/{user_name}
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
// Control buttons
|
||||
bindUserButtonsExtra($("#view-user"), { delete_redirect: page.delete_redirect });
|
||||
});
|
||||
15
assets/organisations/js/pages/users.js
Normal file
15
assets/organisations/js/pages/users.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template.
|
||||
* example: {{ assets.js('js/pages/sign-in-or-register') | raw }}
|
||||
*
|
||||
* This script depends on widgets/users.js, uf-table.js, moment.js, handlebars-helpers.js
|
||||
*
|
||||
* Target page: /users
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
// Bind table buttons
|
||||
$("#widget-users").on("pagerComplete.ufTable", function () {
|
||||
bindUserButtonsExtra($(this));
|
||||
});
|
||||
});
|
||||
23
assets/organisations/js/sidebar.js
Normal file
23
assets/organisations/js/sidebar.js
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
$(document).ready(function() {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
$('.sidebar-menu .collapse, .sidebar-menu .collapsing').on('hide.bs.collapse', function() {
|
||||
$(this).prev().find('.fa').eq(1).removeClass('fa-angle-right').addClass('fa-angle-down');
|
||||
var states = JSON.parse(localStorage.getItem('sidebar-states')) || {};
|
||||
states[this.id] = 0;
|
||||
localStorage.setItem('sidebar-states', JSON.stringify(states));
|
||||
});
|
||||
$('.sidebar-menu .collapse, sidebar-menu .collapsing').on('show.bs.collapse', function() {
|
||||
$(this).prev().find('.fa').eq(1).removeClass('fa-angle-down').addClass('fa-angle-right');
|
||||
var states = JSON.parse(localStorage.getItem('sidebar-states')) || {};
|
||||
states[this.id] = 1;
|
||||
localStorage.setItem('sidebar-states', JSON.stringify(states));
|
||||
});
|
||||
|
||||
var states = JSON.parse(localStorage.getItem('sidebar-states')) || {};
|
||||
Object.getOwnPropertyNames(states).forEach((elid) => {
|
||||
if (states[elid] === 1) {
|
||||
$('#' + elid).collapse('show');
|
||||
}
|
||||
});
|
||||
})
|
||||
154
assets/organisations/js/widgets/members.js
Normal file
154
assets/organisations/js/widgets/members.js
Normal file
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Members widget. Sets up dropdowns, modals, etc for a table of members.
|
||||
*
|
||||
* Depends on widgets/users.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* Link extra user action buttons in addition to the base ones.
|
||||
* @param {module:jQuery} el jQuery wrapped element to target.
|
||||
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
|
||||
*/
|
||||
function bindMemberButtons(el, options) {
|
||||
if (!options) options = {};
|
||||
|
||||
// Remove user button
|
||||
el.find('.js-member-promote').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + '/modals/organisations/o/' + $(this).data('slug') + '/members/confirm-promote',
|
||||
ajaxParams: {
|
||||
slug: $(this).data('slug'),
|
||||
user_name: $(this).data('user_name')
|
||||
},
|
||||
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
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Remove user button
|
||||
el.find('.js-member-demote').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + '/modals/organisations/o/' + $(this).data('slug') + '/members/confirm-demote',
|
||||
ajaxParams: {
|
||||
slug: $(this).data('slug'),
|
||||
user_name: $(this).data('user_name')
|
||||
},
|
||||
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
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Remove user button
|
||||
el.find('.js-member-remove').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + '/modals/organisations/o/' + $(this).data('slug') + '/members/confirm-remove',
|
||||
ajaxParams: {
|
||||
slug: $(this).data('slug'),
|
||||
user_name: $(this).data('user_name')
|
||||
},
|
||||
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
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Accept member button
|
||||
el.find('.js-member-accept').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + '/modals/organisations/o/' + $(this).data('slug') + '/members/confirm-accept',
|
||||
ajaxParams: {
|
||||
slug: $(this).data('slug'),
|
||||
user_name: $(this).data('user_name')
|
||||
},
|
||||
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
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Reject user button
|
||||
el.find('.js-member-reject').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + '/modals/organisations/o/' + $(this).data('slug') + '/members/confirm-reject',
|
||||
ajaxParams: {
|
||||
slug: $(this).data('slug'),
|
||||
user_name: $(this).data('user_name')
|
||||
},
|
||||
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
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// function bindMemberCreationButton(el) {
|
||||
// // Link create button
|
||||
// el.find('.js-member-create').click(function(e) {
|
||||
// e.preventDefault();
|
||||
|
||||
// $("body").ufModal({
|
||||
// sourceUrl: site.uri.public + "/modals/users/create",
|
||||
// msgTarget: $("#alerts-page")
|
||||
// });
|
||||
|
||||
// attachUserForm();
|
||||
// });
|
||||
// };
|
||||
453
assets/organisations/js/widgets/organisations.js
Normal file
453
assets/organisations/js/widgets/organisations.js
Normal file
@@ -0,0 +1,453 @@
|
||||
/**
|
||||
* 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(e, data) {
|
||||
// Reload page on success
|
||||
if (data.redirect) {
|
||||
window.location = data.redirect;
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve/Deny organisation registration
|
||||
*/
|
||||
function approveOrganisationRegistration(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' : 'deny');
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
|
||||
*/
|
||||
function bindOrganisationButtons(el, options) {
|
||||
if (!options) options = {};
|
||||
|
||||
/**
|
||||
* Link row buttons after table is loaded.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Buttons that launch a modal dialog
|
||||
*/
|
||||
// Edit organisation details button
|
||||
el.find('.js-organisation-edit').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/edit",
|
||||
ajaxParams: {
|
||||
slug: $(this).data('slug')
|
||||
},
|
||||
msgTarget: $("#alerts-page")
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Join organisation button
|
||||
el.find('.js-organisation-join').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
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/' + $(this).data('slug') + '/members';
|
||||
var debugAjax = (typeof site !== "undefined") && site.debug.ajax;
|
||||
|
||||
return $.ajax({
|
||||
type: "POST",
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel a registration request
|
||||
el.find('.js-organisation-cancelJoin').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/o/" + $(this).data('slug') + "/members/confirm-cancel",
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Leave organisation button
|
||||
el.find('.js-organisation-leave').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/o/" + $(this).data('slug') + "/members/confirm-leave",
|
||||
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.leave_redirect) window.location.href = options.leave_redirect;
|
||||
else window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel a registration request
|
||||
el.find('.js-organisation-cancelRegistration').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/registration/confirm-cancel",
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Cancel a registration request
|
||||
el.find('.js-organisation-approveRegistration').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
approveOrganisationRegistration($(this).data('slug'), true, options);
|
||||
});
|
||||
|
||||
// Cancel a registration request
|
||||
el.find('.js-organisation-denyRegistration').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
approveOrganisationRegistration($(this).data('slug'), false, options);
|
||||
});
|
||||
|
||||
// Delete organisation button
|
||||
el.find('.js-organisation-delete').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/confirm-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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// 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) {
|
||||
// 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();
|
||||
});
|
||||
};
|
||||
|
||||
function bindOrganisationRegistrationButton(el) {
|
||||
// Link create button
|
||||
el.find('.js-organisation-register').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/organisations/register",
|
||||
msgTarget: $("#alerts-page")
|
||||
});
|
||||
|
||||
attachOrganisationForm();
|
||||
});
|
||||
};
|
||||
56
assets/organisations/js/widgets/users.js
Normal file
56
assets/organisations/js/widgets/users.js
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
/**
|
||||
* Link extra user action buttons in addition to the base ones.
|
||||
* @param {module:jQuery} el jQuery wrapped element to target.
|
||||
* @param {{delete_redirect: string}} options Options used to modify behaviour of button actions.
|
||||
*/
|
||||
function bindUserButtonsExtra(el, options) {
|
||||
// Manage user organisations button
|
||||
el.find('.js-user-organisations').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var userName = $(this).data('user_name');
|
||||
$("body").ufModal({
|
||||
sourceUrl: site.uri.public + "/modals/users/organisations",
|
||||
ajaxParams: {
|
||||
user_name: userName
|
||||
},
|
||||
msgTarget: $("#alerts-page")
|
||||
});
|
||||
|
||||
$("body").on('renderSuccess.ufModal', function(data) {
|
||||
var modal = $(this).ufModal('getModal');
|
||||
var form = modal.find('.js-form');
|
||||
|
||||
// Set up collection widget
|
||||
var organisationWidget = modal.find('.js-form-organisations');
|
||||
organisationWidget.ufCollection({
|
||||
dropdown: {
|
||||
ajax: {
|
||||
url: site.uri.public + '/api/organisations'
|
||||
},
|
||||
placeholder: "Select an organisation"
|
||||
},
|
||||
dropdownTemplate: modal.find('#user-organisations-select-option').html(),
|
||||
rowTemplate: modal.find('#user-organisations-row').html()
|
||||
});
|
||||
|
||||
// Get current organisations and add to widget
|
||||
$.getJSON(site.uri.public + '/api/users/u/' + userName + '/organisations')
|
||||
.done(function(data) {
|
||||
$.each(data.rows, function(idx, organisation) {
|
||||
organisation.text = organisation.name;
|
||||
organisationWidget.ufCollection('addRow', organisation);
|
||||
});
|
||||
});
|
||||
|
||||
// Set up form for submission
|
||||
form.ufForm()
|
||||
.on("submitSuccess.ufForm", function() {
|
||||
// Reload page on success
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user