mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Added suppliers ajax list
This commit is contained in:
parent
04130a568c
commit
2172e6cc25
|
@ -7,6 +7,8 @@ use App\Http\Controllers\Controller;
|
|||
use App\Helpers\Helper;
|
||||
use App\Models\Supplier;
|
||||
use App\Http\Transformers\SuppliersTransformer;
|
||||
use App\Http\Transformers\SelectlistTransformer;
|
||||
|
||||
|
||||
class SuppliersController extends Controller
|
||||
{
|
||||
|
@ -133,4 +135,41 @@ class SuppliersController extends Controller
|
|||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/suppliers/message.delete.success')));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a paginated collection for the select2 menus
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0.16]
|
||||
* @see \App\Http\Transformers\SelectlistTransformer
|
||||
*
|
||||
*/
|
||||
public function selectlist(Request $request)
|
||||
{
|
||||
$this->authorize('view', Supplier::class);
|
||||
|
||||
$suppliers = Supplier::select([
|
||||
'id',
|
||||
'name',
|
||||
'image',
|
||||
]);
|
||||
|
||||
if ($request->has('search')) {
|
||||
$suppliers = $suppliers->where('locations.name', 'LIKE', '%'.$request->get('search').'%');
|
||||
}
|
||||
|
||||
$suppliers = $suppliers->orderBy('name', 'ASC')->paginate(50);
|
||||
|
||||
// Loop through and set some custom properties for the transformer to use.
|
||||
// This lets us have more flexibility in special cases like assets, where
|
||||
// they may not have a ->name value but we want to display something anyway
|
||||
foreach ($suppliers as $supplier) {
|
||||
$supplier->use_text = $supplier->name;
|
||||
$supplier->use_image = ($supplier->image) ? url('/').'/uploads/suppliers/'.$supplier->image : null;
|
||||
}
|
||||
|
||||
return (new SelectlistTransformer)->transformSelectlist($suppliers);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
|
||||
<div class="col-md-7 required">
|
||||
<select class="js-data-ajax" data-endpoint="hardware" name="{{ $fieldname }}" style="width: 100%" id="assigned_asset_select">
|
||||
@if (Input::old($fieldname))
|
||||
<option value="{{ Input::old($fieldname) }}" selected="selected">
|
||||
{{ \App\Models\Asset::select('name')->find(Input::old($fieldname))->name }}
|
||||
@if ($asset_id = Input::old($fieldname, $item->{$fieldname}))
|
||||
<option value="{{ $asset_id }}" selected="selected">
|
||||
{{ \App\Models\Asset::find($asset_id)->present()->fullName }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">{{ trans('general.select_asset') }}</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<div id="assigned_user" class="form-group{{ $errors->has($fieldname) ? ' has-error' : '' }}">
|
||||
|
||||
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
|
||||
|
||||
<div class="col-md-7 required">
|
||||
<select class="js-data-ajax" data-endpoint="suppliers" name="{{ $fieldname }}" style="width: 100%" id="suppliers_select">
|
||||
@if ($supplier_id = Input::old($fieldname, $item->{$fieldname}))
|
||||
<option value="{{ $supplier_id }}" selected="selected">
|
||||
{{ \App\Models\Supplier::find($supplier_id)->name }}
|
||||
</option>
|
||||
@else
|
||||
<option value="">{{ trans('general.select_supplier') }}</option>
|
||||
@endif
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', \App\Models\Supplier::class)
|
||||
<a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select' class="btn btn-sm btn-default">New</a>
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
{!! $errors->first($fieldname, '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
|
||||
|
||||
</div>
|
Loading…
Reference in a new issue