Integrate ajax select2 menus in all asset checkouts

This commit is contained in:
snipe
2017-10-26 02:28:17 -07:00
parent 75b527ab59
commit 82690e1fd7
17 changed files with 89958 additions and 198 deletions
@@ -263,6 +263,61 @@ class AssetsController extends Controller
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
}
/**
* 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', Asset::class);
$assets = Company::scopeCompanyables(Asset::select([
'assets.id',
'assets.name',
'assets.asset_tag',
'assets.model_id',
]))->with('model')->RTD();
if ($request->has('search')) {
$assets = $assets->where('assets.name', 'LIKE', '%'.$request->get('search').'%')
->orWhere('assets.asset_tag', 'LIKE', '%'.$request->get('search').'%')
->join('models AS assets_models',function ($join) use ($request) {
$join->on('assets_models.id', "=", "assets.model_id");
})->orWhere('assets_models.name','LIKE','%'.$request->get('search').'%');
}
$assets = $assets->paginate(50);
$assets_array = [];
foreach ($assets as $asset) {
$assets_array[] =
[
'id' => (int) $asset->id,
'text' => e($asset->present()->fullName),
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
];
}
$results = [
'items' => $assets_array,
'pagination' =>
[
'more' => ($assets->currentPage() >= $assets->lastPage()) ? false : true,
'per_page' => $assets->perPage()
],
'total_count' => $assets->total(),
'page' => $assets->currentPage(),
'page_count' => $assets->lastPage()
];
return $results;
}
/**
* Accepts a POST request to create a new asset
@@ -139,4 +139,55 @@ class LocationsController extends Controller
$location->delete();
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/locations/message.delete.success')));
}
/**
* 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', Location::class);
$locations = Location::select([
'locations.id',
'locations.name',
'locations.image',
]);
if ($request->has('search')) {
$locations = $locations->where('locations.name', 'LIKE', '%'.$request->get('search').'%');
}
$locations = $locations->paginate(50);
$locations_array = [];
foreach ($locations as $location) {
$locations_array[] =
[
'id' => (int) $location->id,
'text' => e($location->name),
'image' => ($location->image) ? url('/').'/uploads/locations/'.$location->image : null,
];
}
$results = [
'items' => $locations_array,
'pagination' =>
[
'more' => ($locations->currentPage() >= $locations->lastPage()) ? false : true,
'per_page' => $locations->perPage()
],
'total_count' => $locations->total(),
'page' => $locations->currentPage(),
'page_count' => $locations->lastPage()
];
return $results;
}
}