mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Refactor controller to use one method that shows all modals based on name.
This commit is contained in:
parent
25d6ceee6e
commit
7ea862787c
4
.gitattributes
vendored
4
.gitattributes
vendored
|
@ -1 +1,3 @@
|
|||
* text=auto
|
||||
* text=auto
|
||||
public/js/** binary
|
||||
public/css/** binary
|
||||
|
|
|
@ -6,47 +6,15 @@ use App\Helpers\Helper;
|
|||
|
||||
class ModalController extends Controller
|
||||
{
|
||||
function location() {
|
||||
return view('modals.location');
|
||||
}
|
||||
function show($type, $itemId = null) {
|
||||
$view = view("modals.${type}");
|
||||
|
||||
function model() {
|
||||
return view('modals.model');
|
||||
}
|
||||
|
||||
function statuslabel() {
|
||||
return view('modals.statuslabel')->with('statuslabel_types', Helper::statusTypeList());
|
||||
}
|
||||
|
||||
function supplier() {
|
||||
return view('modals.supplier');
|
||||
}
|
||||
|
||||
function user() {
|
||||
return view('modals.user');
|
||||
}
|
||||
|
||||
function category() {
|
||||
return view('modals.category');
|
||||
}
|
||||
|
||||
function manufacturer() {
|
||||
return view('modals.manufacturer');
|
||||
}
|
||||
|
||||
function kitModel() {
|
||||
return view('modals.kit-model');
|
||||
}
|
||||
|
||||
function kitLicense() {
|
||||
return view('modals.kit-license');
|
||||
}
|
||||
|
||||
function kitConsumable() {
|
||||
return view('modals.kit-consumable');
|
||||
}
|
||||
|
||||
function kitAccessory() {
|
||||
return view('modals.kit-accessory');
|
||||
if($type == "statuslabel") {
|
||||
$view->with('statuslabel_types', Helper::statusTypeList());
|
||||
}
|
||||
if(in_array($type, ['kit-model', 'kit-license', 'kit-consumable', 'kit-accessory'])) {
|
||||
$view->with('kitId', $itemId);
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
Create a Button looking like this:
|
||||
|
||||
<a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_to' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_to' class="btn btn-sm btn-primary">New</a>
|
||||
|
||||
If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href'
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'>
|
||||
</table>
|
||||
<a href="{{ route('modal.kit.model', ['kit' => $item->id]) }}" data-refresh="kitModelsTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append</a>
|
||||
<a href="{{ route('modal.show', ['type' => 'kit-model', 'itemId' => $item->id]) }}" data-refresh="kitModelsTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append</a>
|
||||
</div>
|
||||
</div> <!--.box-body-->
|
||||
</div> <!-- /.box.box-default-->
|
||||
|
@ -73,7 +73,7 @@
|
|||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'>
|
||||
</table>
|
||||
<a href="{{ route('modal.kit.license', ['kit' => $item->id]) }}" data-refresh="kitLicensesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
|
||||
<a href="{{ route('modal.show', [ 'type' => 'kit-license', 'itemId' => $item->id]) }}" data-refresh="kitLicensesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
|
||||
</div>
|
||||
</div> <!--.box-body-->
|
||||
</div> <!-- /.box.box-default-->
|
||||
|
@ -107,7 +107,7 @@
|
|||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'>
|
||||
</table>
|
||||
<a href="{{ route('modal.kit.consumable', ['kit' => $item->id]) }}" data-refresh="kitConsumablesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
|
||||
<a href="{{ route('modal.show', ['type' => 'kit-consumable', 'itemId' => $item->id]) }}" data-refresh="kitConsumablesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
|
||||
</div>
|
||||
</div> <!--.box-body-->
|
||||
</div> <!-- /.box.box-default-->
|
||||
|
@ -141,7 +141,7 @@
|
|||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'>
|
||||
</table>
|
||||
<a href="{{ route('modal.kit.accessory', ['kit' => $item->id]) }}" data-refresh="kitAccessoriesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
|
||||
<a href="{{ route('modal.show', ['type' => 'kit-accessory', 'itemId' => $item->id]) }}" data-refresh="kitAccessoriesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
|
||||
</div>
|
||||
</div> <!--.box-body-->
|
||||
</div> <!-- /.box.box-default-->
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
<h4 class="modal-title">Append accessory{{-- TODO: trans --}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ route('api.kits.accessories.store', ['kit_id' => request('kit')]) }}" onsubmit="return false">
|
||||
<form action="{{ route('api.kits.accessories.store', $kitId) }}" onsubmit="return false">
|
||||
{{ csrf_field() }}
|
||||
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-accessory_id">{{ trans('general.accessory') }}:
|
||||
</label></div>
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
<h4 class="modal-title">Append consumable{{-- TODO: trans --}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ route('api.kits.consumables.store', ['kit_id' => request('kit')]) }}" onsubmit="return false">
|
||||
<form action="{{ route('api.kits.consumables.store', $kitId) }}" onsubmit="return false">
|
||||
{{ csrf_field() }}
|
||||
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-consumable_id">{{ trans('general.consumable') }}:
|
||||
</label></div>
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
<h4 class="modal-title">Append license{{-- TODO: trans --}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ route('api.kits.licenses.store', ['kit_id' => request('kit')]) }}" onsubmit="return false">
|
||||
<form action="{{ route('api.kits.licenses.store', $kitId) }}" onsubmit="return false">
|
||||
{{ csrf_field() }}
|
||||
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="dynamic-form-row">
|
||||
<div class="col-md-4 col-xs-12"><label for="modal-license_id">{{ trans('general.license') }}:
|
||||
</label></div>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<h4 class="modal-title">Append model{{-- TODO: trans --}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="{{ route('api.kits.models.store', ['kit_id' => request('kit')]) }}" onsubmit="return false">
|
||||
<form action="{{ route('api.kits.models.store', $kitId) }}" onsubmit="return false">
|
||||
{{ csrf_field() }}
|
||||
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\Category::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
<a href='{{ route('modal.category',['category_type' => isset($category_type) ? $category_type : 'assets' ]) }}' data-toggle="modal" data-target="#createModal" data-select='category_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show',['type' => 'category', 'category_type' => isset($category_type) ? $category_type : 'assets' ]) }}' data-toggle="modal" data-target="#createModal" data-select='category_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\PredefinedKit::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
{{-- <a href='{{ route('modal.kit') }}' data-toggle="modal" data-target="#createModal" data-select='kit_id_select' class="btn btn-sm btn-default">New</a> --}}
|
||||
{{-- <a href='{{ route('modal.show, 'kit') }}' data-toggle="modal" data-target="#createModal" data-select='kit_id_select' class="btn btn-sm btn-default">New</a> --}}
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\Location::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
<a href='{{ route('modal.location') }}' data-toggle="modal" data-target="#createModal" data-select='{{ $fieldname }}_location_select' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'location') }}' data-toggle="modal" data-target="#createModal" data-select='{{ $fieldname }}_location_select' class="btn btn-sm btn-primary">New</a>
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\Manufacturer::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
<a href='{{ route('modal.manufacturer') }}' data-toggle="modal" data-target="#createModal" data-select='manufacturer_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'manufacturer') }}' data-toggle="modal" data-target="#createModal" data-select='manufacturer_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\AssetModel::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
<a href='{{ route('modal.model') }}' data-toggle="modal" data-target="#createModal" data-select='model_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'model') }}' data-toggle="modal" data-target="#createModal" data-select='model_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
<span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;">
|
||||
<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
|
||||
</span>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<div class="col-md-2 col-sm-2 text-left">
|
||||
|
||||
@can('create', \App\Models\Statuslabel::class)
|
||||
<a href='{{ route('modal.statuslabel') }}' data-toggle="modal" data-target="#createModal" data-select='status_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'statuslabel') }}' data-toggle="modal" data-target="#createModal" data-select='status_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
@endcan
|
||||
|
||||
<span class="status_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin" aria-hidden="true"></i> </span>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\Supplier::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
<a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-select='supplier_select' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'supplier') }}' data-toggle="modal" data-target="#createModal" data-select='supplier_select' class="btn btn-sm btn-primary">New</a>
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
{!! $errors->first('supplier_id', '<span class="alert-msg" aria-hidden="true"><i class="fa fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
</div>
|
||||
<div class="col-md-1 col-sm-1 text-left">
|
||||
<a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select_id' class="btn btn-sm btn-primary">New</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\User::class)
|
||||
@if ((!isset($hide_new)) || ($hide_new!='true'))
|
||||
<a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_user_select' class="btn btn-sm btn-primary">New</a>
|
||||
<a href='{{ route('modal.show', 'user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_user_select' class="btn btn-sm btn-primary">New</a>
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
|
|
@ -80,17 +80,7 @@ Route::group(['middleware' => 'auth'], function () {
|
|||
*/
|
||||
|
||||
Route::group(['middleware' => 'auth','prefix' => 'modals'], function () {
|
||||
Route::get('location',['as' => 'modal.location','uses' => 'ModalController@location']);
|
||||
Route::get('category',['as' => 'modal.category','uses' => 'ModalController@category']);
|
||||
Route::get('manufacturer',['as' => 'modal.manufacturer','uses' => 'ModalController@manufacturer']);
|
||||
Route::get('model',['as' => 'modal.model','uses' => 'ModalController@model']);
|
||||
Route::get('statuslabel',['as' => 'modal.statuslabel','uses' => 'ModalController@statuslabel']);
|
||||
Route::get('supplier',['as' => 'modal.supplier','uses' => 'ModalController@supplier']);
|
||||
Route::get('user',['as' => 'modal.user','uses' => 'ModalController@user']);
|
||||
Route::get('kit-model',['as' => 'modal.kit.model','uses' => 'ModalController@kitModel']);
|
||||
Route::get('kit-license',['as' => 'modal.kit.license','uses' => 'ModalController@kitLicense']);
|
||||
Route::get('kit-consumable',['as' => 'modal.kit.consumable','uses' => 'ModalController@kitConsumable']);
|
||||
Route::get('kit-accessory',['as' => 'modal.kit.accessory','uses' => 'ModalController@kitAccessory']);
|
||||
Route::get('{type}/{itemId?}',['as' => 'modal.show', 'uses' => 'ModalController@show']);
|
||||
});
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue