Skip to content

Commit

Permalink
Merge pull request #179 from stats4sd/swap-institution
Browse files Browse the repository at this point in the history
add options for users to swap institutions
  • Loading branch information
dave-mills authored Jul 21, 2023
2 parents a1a0060 + 83ab03f commit ba3d865
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 24 deletions.
11 changes: 11 additions & 0 deletions resources/views/vendor/backpack/base/inc/menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
</a>
</li>

@if(\App\Models\Organisation::count() > 1)
<li class="nav-item pr-4">
<a class="nav-link d-flex justify-content-between align-items-center"
href="{{ backpack_url('selected_organisation') }}"
>
<i class="la la-exclamation-circle font-3xl pr-2"></i>
<span>Change Institution</span>
</a>
</li>
@endif

<!-- Logout button - tailored to use Laravel Breeze -->
<li class="nav-item pr-4">
<form method="POST" action={{ route('logout') }}>
Expand Down
69 changes: 45 additions & 24 deletions resources/views/vendor/backpack/base/my_account.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<section class="content-header">
<div class="container-fluid mb-3">
<h1>{{ trans('backpack::base.my_account') }}</h1>
<h4>ROLE: {{ auth()->user()->getRoleNames()->join(', ') }}</h4>
@if(\App\Models\Organisation::count() < 2)
<h4>INSTITUTION: {{ \App\Models\Organisation::first()->name }}</h4>
@endif
</div>
</section>
@endsection
Expand Down Expand Up @@ -47,34 +51,28 @@
</div>
@endif

{{-- UPDATE INFO FORM --}}
<div class="col-lg-8">

<div class="card padding-10">
<div class="card-header">
My Institution and Role
</div>
<div class="card-body backpack-profile-form bold-labels">
<div class="row">
<div class="col-md-3 font-weight-bold text-right pr-4">
Institution:
</div>
<div class="col-md-6">
{{ \App\Models\Organisation::find(Session::get('selectedOrganisationId'))->name }}
</div>
@if(\App\Models\Organisation::count() > 1)
<div class="card padding-10">
<div class="card-header">
<h5>My Institution(s)</h5>
<p>Below are all the institutions that you have access to. The highlighted one is currently selected, and every other page on the site will present information only for the chosen institution. To use the tool on behalf of a different institution, click on one of the other items in the list below.</p>
</div>
<div class="row">

<div class="col-md-3 font-weight-bold text-right pr-4">
User Role:
</div>
<div class="col-md-6">
{{ auth()->user()->getRoleNames()[0] }}
<div class="card-body backpack-profile-form bold-labels">
<div class="list-group list-group-flush">

@foreach(\App\Models\Organisation::all() as $organisation)
<button class="row list-group-item @if($organisation->id === (int) Session::get('selectedOrganisationId')) list-group-item-success @endif" type="button" onclick="submitForm(this)" id="{{$organisation->id}}">
<div class="col-12">
{{ $organisation->name }}
</div>
</button>
@endforeach
</div>
</div>
</div>
</div>

@endif

<form class="form" action="{{ route('backpack.account.info.store') }}" method="post">

Expand Down Expand Up @@ -109,7 +107,9 @@
</div>

<div class="card-footer">
<button type="submit" class="btn btn-success"><i class="la la-save"></i> {{ trans('backpack::base.save') }}</button>
<button type="submit" class="btn btn-success">
<i class="la la-save"></i> {{ trans('backpack::base.save') }}
</button>
<a href="{{ backpack_url() }}" class="btn">{{ trans('backpack::base.cancel') }}</a>
</div>
</div>
Expand Down Expand Up @@ -161,7 +161,9 @@
</div>

<div class="card-footer">
<button type="submit" class="btn btn-success"><i class="la la-save"></i> {{ trans('backpack::base.change_password') }}</button>
<button type="submit" class="btn btn-success">
<i class="la la-save"></i> {{ trans('backpack::base.change_password') }}
</button>
<a href="{{ backpack_url() }}" class="btn">{{ trans('backpack::base.cancel') }}</a>
</div>

Expand Down Expand Up @@ -193,5 +195,24 @@
</div>
@endif

<form name="selectedOrganisationForm" action="{{ backpack_url('selected_organisation') }}" method="POST">
@csrf
@method('POST')
<input type="hidden" name="organisationId">
<input type="hidden" name="redirect" value="{{ backpack_url('edit-account-info') }}">
</form>

</div>
@endsection

@section('after_scripts')
@vite('resources/js/app.js')

<script>
function submitForm(organisationButton) {
this.document.selectedOrganisationForm.organisationId.value = organisationButton.id;
this.document.selectedOrganisationForm.submit();
}
</script>

0 comments on commit ba3d865

Please sign in to comment.