Use blade component for redirect option

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-25 21:35:13 +01:00
parent f77d300549
commit 73a80a5fbc
8 changed files with 213 additions and 170 deletions

View file

@ -1491,21 +1491,23 @@ class Helper
$checkout_to_type = Session::get('checkout_to_type');
// return to index
if ($redirect_option == '0') {
if ($redirect_option == 'index') {
switch ($table) {
case "Assets":
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));
}
}
// return to thing being assigned
if ($redirect_option == '1') {
if ($redirect_option == 'item') {
switch ($table) {
case "Assets":
return redirect()->route('hardware.show', $id ? $id : $asset_id)->with('success', trans('admin/hardware/message.checkout.success'));
}
}
//return to thing being assigned to
if ($redirect_option == '2') {
// return to assignment target
if ($redirect_option == 'target') {
switch ($checkout_to_type) {
case 'user':
return redirect()->route('users.show', $request->assigned_user)->with('success', trans('admin/hardware/message.checkout.success'));

View file

@ -23,6 +23,7 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use League\Csv\Reader;
@ -204,6 +205,8 @@ class AssetsController extends Controller
}
}
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
if ($success) {
return redirect()->route('hardware.index')
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $asset->id]), 'id', 'tag' => e($asset->asset_tag)]));
@ -289,6 +292,8 @@ class AssetsController extends Controller
*/
public function update(ImageUploadRequest $request, $assetId = null) : RedirectResponse
{
// Check if the asset exists
if (! $asset = Asset::find($assetId)) {
// Redirect to the asset management page with error
@ -387,10 +392,10 @@ class AssetsController extends Controller
}
}
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
if ($asset->save()) {
return redirect()->route('hardware.show', $assetId)
->with('success', trans('admin/hardware/message.update.success'));
return Helper::getRedirectOption($request, $assetId, 'Assets');
}
return redirect()->back()->withInput()->withErrors($asset->getErrors());

View file

@ -0,0 +1,38 @@
<!-- begin redirect submit options -->
@props([
'route' => 'hardware.index',
'button_label',
'disabled_select' => false,
'options' => [],
])
<div class="box-footer">
<div class="row">
<div class="col-md-3">
<a class="btn btn-link" href="{{ route($route) }}">{{ trans('button.cancel') }}</a>
</div>
<div class="col-md-9 text-right">
<div class="btn-group text-left">
@if (($options) && (count($options) > 0))
<select class="redirect-options form-control select2" data-minimum-results-for-search="Infinity" name="redirect_option" style="min-width: 200px"{{ ($disabled_select ? ' disabled' : '') }}>
@foreach ($options as $key => $value)
<option value="{{ $key }}"{{ Session::get('redirect_option') == $key ? ' selected' : ''}}>
{{ $value }}
</option>
@endforeach
</select>
@endif
<button type="submit" class="btn btn-primary pull-right{{ ($disabled_select ? ' disabled' : '') }}" style="margin-left:5px; border-radius: 3px;"{!! ($disabled_select ? ' data-tooltip="true" title="'.trans('admin/hardware/general.edit').'" disabled' : '') !!}>
<i class="fas fa-check icon-white" aria-hidden="true"></i>
{{ $button_label }}
</button>
</div><!-- /.btn-group -->
</div><!-- /.col-md-9 -->
</div><!-- /.row -->
</div> <!-- /.box-footer -->
<!-- end redirect submit options -->

View file

@ -31,9 +31,13 @@
<div class="col-md-12"><!-- .col-md-12 -->
@if ($backto == 'user')
<form class="form-horizontal" method="post" action="{{ route('hardware.checkin.store', array('assetId'=> $asset->id, 'backto'=>'user')) }}" autocomplete="off">
<form class="form-horizontal" method="post"
action="{{ route('hardware.checkin.store', array('assetId'=> $asset->id, 'backto'=>'user')) }}"
autocomplete="off">
@else
<form class="form-horizontal" method="post" action="{{ route('hardware.checkin.store', array('assetId'=> $asset->id)) }}" autocomplete="off">
<form class="form-horizontal" method="post"
action="{{ route('hardware.checkin.store', array('assetId'=> $asset->id)) }}"
autocomplete="off">
@endif
{{csrf_field()}}
@ -68,7 +72,8 @@
{{ trans('general.name') }}
</label>
<div class="col-md-8">
<input class="form-control" type="text" name="name" aria-label="name" id="name" value="{{ old('name', $asset->name) }}"/>
<input class="form-control" type="text" name="name" aria-label="name"
id="name" value="{{ old('name', $asset->name) }}"/>
{!! $errors->first('name', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
@ -94,9 +99,14 @@
<div class="col-md-8">
<div class="input-group col-md-5 required">
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="checkin_at" id="checkin_at" value="{{ old('checkin_at', date('Y-m-d')) }}">
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
<div class="input-group date" data-provide="datepicker"
data-date-format="yyyy-mm-dd" data-autoclose="true">
<input type="text" class="form-control"
placeholder="{{ trans('general.select_date') }}"
name="checkin_at" id="checkin_at"
value="{{ old('checkin_at', date('Y-m-d')) }}">
<span class="input-group-addon"><i class="fas fa-calendar"
aria-hidden="true"></i></span>
</div>
{!! $errors->first('checkin_at', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
@ -109,25 +119,27 @@
{{ trans('general.notes') }}
</label>
<div class="col-md-8">
<textarea class="col-md-6 form-control" id="note" name="note">{{ old('note', $asset->note) }}</textarea>
<textarea class="col-md-6 form-control" id="note"
name="note">{{ old('note', $asset->note) }}</textarea>
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
</div> <!--/.box-body-->
</div> <!--/.box-body-->
@include ('partials.forms.redirect_submit_options',
[
'route' => 'hardware.index',
'table_name' => $table_name,
'type'=> ($asset->model ? $asset->model->name : trans('general.asset_model')),
'checkin' => true
])
<x-redirect_submit_options
route="hardware.index"
:button_label="trans('general.checkout')"
:disabled_select="!$asset->model"
:options="[
'index' => trans('admin/hardware/form.redirect_to_all', ['type' => 'assets']),
'item' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset')]),
]"
/>
</form>
</div>
</div>
</div>
@stop

View file

@ -70,7 +70,8 @@
</label>
<div class="col-md-8">
<input class="form-control" type="text" name="name" id="name" value="{{ old('name', $asset->name) }}" tabindex="1">
<input class="form-control" type="text" name="name" id="name"
value="{{ old('name', $asset->name) }}" tabindex="1">
{!! $errors->first('name', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
@ -103,9 +104,13 @@
{{ trans('admin/hardware/form.checkout_date') }}
</label>
<div class="col-md-8">
<div class="input-group date col-md-7" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-end-date="0d" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="checkout_at" id="checkout_at" value="{{ old('checkout_at', date('Y-m-d')) }}">
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
<div class="input-group date col-md-7" data-provide="datepicker"
data-date-format="yyyy-mm-dd" data-date-end-date="0d" data-date-clear-btn="true">
<input type="text" class="form-control"
placeholder="{{ trans('general.select_date') }}" name="checkout_at"
id="checkout_at" value="{{ old('checkout_at', date('Y-m-d')) }}">
<span class="input-group-addon"><i class="fas fa-calendar"
aria-hidden="true"></i></span>
</div>
{!! $errors->first('checkout_at', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
@ -118,9 +123,13 @@
</label>
<div class="col-md-8">
<div class="input-group date col-md-7" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-start-date="0d" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="expected_checkin" id="expected_checkin" value="{{ old('expected_checkin') }}">
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
<div class="input-group date col-md-7" data-provide="datepicker"
data-date-format="yyyy-mm-dd" data-date-start-date="0d" data-date-clear-btn="true">
<input type="text" class="form-control"
placeholder="{{ trans('general.select_date') }}" name="expected_checkin"
id="expected_checkin" value="{{ old('expected_checkin') }}">
<span class="input-group-addon"><i class="fas fa-calendar"
aria-hidden="true"></i></span>
</div>
{!! $errors->first('expected_checkin', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
@ -132,7 +141,8 @@
{{ trans('general.notes') }}
</label>
<div class="col-md-8">
<textarea class="col-md-6 form-control" id="note" name="note">{{ old('note', $asset->note) }}</textarea>
<textarea class="col-md-6 form-control" id="note"
name="note">{{ old('note', $asset->note) }}</textarea>
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
@ -164,13 +174,19 @@
@endif
</div> <!--/.box-body-->
@include ('partials.forms.redirect_submit_options',
[
'route' => 'hardware.index',
'table_name' => $table_name,
'type'=> ($asset->model ? $asset->model->name : trans('general.asset_model')),
'checkin' => false
])
<x-redirect_submit_options
route="hardware.index"
:button_label="trans('general.checkout')"
:disabled_select="!$asset->model"
:options="[
'index' => trans('admin/hardware/form.redirect_to_all', ['type' => 'assets']),
'item' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset')]),
'target' => trans('admin/hardware/form.redirect_to_checked_out_to'),
]"
/>
</form>
</div>
</div> <!--/.col-md-7-->

View file

@ -6,6 +6,10 @@
'helpText' => trans('help.assets'),
'helpPosition' => 'right',
'formAction' => ($item->id) ? route('hardware.update', ['hardware' => $item->id]) : route('hardware.store'),
'options' => [
'index' => trans('admin/hardware/form.redirect_to_all', ['type' => 'assets']),
'item' => trans('admin/hardware/form.redirect_to_type', ['type' => trans('general.asset')]),
]
])
@ -130,8 +134,6 @@
</div>
<!-- byod checkbox -->
<div class="form-group">
<div class="col-md-7 col-md-offset-3">

View file

@ -66,7 +66,11 @@
<!-- CSRF Token -->
{{ csrf_field() }}
@yield('inputFields')
@include('partials.forms.edit.submit')
<x-redirect_submit_options
route="hardware.index"
:button_label="trans('general.save')"
:options="$options ?? []"
/>
</div>
</div> <!-- ./box-body -->

View file

@ -1,36 +0,0 @@
<!-- begin redirect submit options -->
<div class="box-footer">
<div class="row">
<div class="col-md-3">
<a class="btn btn-link" href="{{ route($route) }}">{{ trans('button.cancel') }}</a>
</div>
<div class="col-md-9 text-right">
<div class="btn-group text-left">
<select class="redirect-options form-control select2" data-minimum-results-for-search="Infinity" name="redirect_option" style="min-width: 200px"{{ (!$asset->model ? ' disabled' : '') }}>
<option {{ (Session::get('redirect_option')=="0" || (Session::get('redirect_option')=="2" && $checkin)) ? 'selected' : '' }} value="0">
{{ trans('admin/hardware/form.redirect_to_all', ['type' => $table_name]) }}
</option>
<option {{ Session::get('redirect_option')=="1" ? 'selected' : ''}} value="1">
{{ trans('admin/hardware/form.redirect_to_type', ['type' => $type]) }}
</option>
<option {{ Session::get('redirect_option')=="2" && !$checkin ? 'selected' : ''}}{{ $checkin ? 'hidden disabled' : '' }} value="2" >
{{ !$checkin ? trans('admin/hardware/form.redirect_to_checked_out_to') : '' }}
</option>
</select>
<button type="submit" class="btn btn-primary pull-right{{ (!$asset->model ? ' disabled' : '') }}" style="margin-left:5px; border-radius: 3px;"{!! (!$asset->model ? ' data-tooltip="true" title="'.trans('admin/hardware/general.edit').'" disabled' : '') !!}>
<i class="fas fa-check icon-white" aria-hidden="true"></i>
{{ $checkin ? trans('general.checkin') : trans('general.checkout') }}
</button>
</div><!-- /.btn-group -->
</div><!-- /.col-md-9 -->
</div><!-- /.row -->
</div> <!-- /.box-footer -->
<!-- end redirect submit options -->