diff --git a/assets/avsdev/js/widgets/organisations.js b/assets/avsdev/js/widgets/organisations.js index cd1b9bb..31c1b1d 100644 --- a/assets/avsdev/js/widgets/organisations.js +++ b/assets/avsdev/js/widgets/organisations.js @@ -39,9 +39,13 @@ function attachOrganisationForm() { // Set up the form for submission form.ufForm({ validator: page.validators - }).on("submitSuccess.ufForm", function() { + }).on("submitSuccess.ufForm", function(e, data) { // Reload page on success - window.location.reload(); + if (data.redirect) { + window.location = data.redirect; + } else { + window.location.reload(); + } }); }); } diff --git a/src/Controller/OrganisationController.php b/src/Controller/OrganisationController.php index f77f648..e308bf4 100644 --- a/src/Controller/OrganisationController.php +++ b/src/Controller/OrganisationController.php @@ -268,6 +268,8 @@ class OrganisationController extends SimpleController return $response->withJson([], 400); } + $oldSlug = $organisation->slug; + // Begin transaction - DB will be rolled back if an exception occurs Capsule::transaction(function () use ($data, $organisation, $currentUser) { // Update the organisation and generate success messages @@ -290,7 +292,13 @@ class OrganisationController extends SimpleController 'name' => $organisation->name, ]); - return $response->withJson([], 200); + if ($oldSlug != $organisation->slug) { + return $response->withJson([ + 'redirect' => $this->ci->router->pathFor('uri_organisation', ['slug' => $organisation->slug]) + ], 200); + } else { + return $response->withJson([], 200); + } } /** @@ -997,7 +1005,8 @@ class OrganisationController extends SimpleController * @throws ForbiddenException If user is not authorized to access page */ public function pageInfo(Request $request, Response $response, $args) - { /** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */ + { + /** @var \UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager $authorizer */ $authorizer = $this->ci->authorizer; /** @var \UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface $currentUser */