mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Added companies ajax select2 endpoint
This commit is contained in:
parent
1fa6228fb7
commit
bdb95e4e3d
|
@ -141,4 +141,57 @@ class CompaniesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a formatted JSON response for the select2 menus
|
||||||
|
*
|
||||||
|
* @todo: create a transformer for handling these responses
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v4.0]
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function selectlist(Request $request)
|
||||||
|
{
|
||||||
|
$this->authorize('view', Company::class);
|
||||||
|
|
||||||
|
$companies = Company::select([
|
||||||
|
'companies.id',
|
||||||
|
'companies.name',
|
||||||
|
'companies.image',
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
if ($request->has('search')) {
|
||||||
|
$companies = $companies->where('companies.name', 'LIKE', '%'.$request->get('search').'%');
|
||||||
|
}
|
||||||
|
|
||||||
|
$companies = $companies->paginate(50);
|
||||||
|
$companies_array = [];
|
||||||
|
|
||||||
|
foreach ($companies as $company) {
|
||||||
|
$companies_array[] =
|
||||||
|
[
|
||||||
|
'id' => (int) $company->id,
|
||||||
|
'text' => e($company->name),
|
||||||
|
'image' => ($company->image) ? url('/').'/uploads/companies/'.$company->image : null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
array_unshift($companies_array, ['id'=> '', 'text'=> trans('general.select_company'), 'image' => null]);
|
||||||
|
|
||||||
|
$results = [
|
||||||
|
'items' => $companies_array,
|
||||||
|
'pagination' =>
|
||||||
|
[
|
||||||
|
'more' => ($companies->currentPage() >= $companies->lastPage()) ? false : true,
|
||||||
|
'per_page' => $companies->perPage()
|
||||||
|
],
|
||||||
|
'total_count' => $companies->total(),
|
||||||
|
'page' => $companies->currentPage(),
|
||||||
|
'page_count' => $companies->lastPage()
|
||||||
|
];
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
12
resources/views/partials/forms/edit/company-select.blade.php
Normal file
12
resources/views/partials/forms/edit/company-select.blade.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!-- Company -->
|
||||||
|
<div id="{{ $fieldname }}" 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">
|
||||||
|
<select class="js-data-ajax" data-endpoint="companies" name="{{ $fieldname }}" style="width: 100%" id="company_select">
|
||||||
|
</select>
|
||||||
|
</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>
|
|
@ -63,6 +63,12 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
||||||
|
|
||||||
/*--- Companies API ---*/
|
/*--- Companies API ---*/
|
||||||
|
|
||||||
|
Route::get( 'companies/selectlist', [
|
||||||
|
'as' => 'companies.selectlist',
|
||||||
|
'uses' => 'CompaniesController@selectlist'
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
Route::resource('companies', 'CompaniesController',
|
Route::resource('companies', 'CompaniesController',
|
||||||
[
|
[
|
||||||
'names' =>
|
'names' =>
|
||||||
|
|
Loading…
Reference in a new issue