diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 358e20df39..98807c5363 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -110,6 +110,78 @@ class UsersController extends Controller } + /** + * Display a listing of the resource. + * + * @author [A. Gianotto] [] + * @since [v4.0] + * + * @return \Illuminate\Http\Response + */ + public function selectlist(Request $request) + { + $this->authorize('view', User::class); + + $users = User::select( + [ + 'users.id', + 'users.employee_num', + 'users.first_name', + 'users.last_name', + 'users.gravatar', + 'users.avatar', + 'users.email', + ] + ); + + $users = Company::scopeCompanyables($users); + + if ($request->has('search')) { + $users = $users->where('first_name', '=', '%'.$request->get('search').'%') + ->orWhere('last_name', 'LIKE', '%'.$request->get('search').'%') + ->orWhere('username', 'LIKE', '%'.$request->get('search').'%') + ->orWhere('employee_num', '=', '%'.$request->get('search').'%'); + } + + $users = $users->orderBy('last_name', 'asc'); + $users = $users->paginate(50); + $users_array = []; + + foreach ($users as $user) { + $name_str = ''; + if ($user->last_name!='') { + $name_str .= e($user->last_name).', '; + } + $name_str .= e($user->first_name); + + if ($user->employee_num!='') { + $name_str .= ' (#'.e($user->employee_num).')'; + } + + $users_array[] = + [ + 'id' => $user->id, + 'text' => $name_str, + 'image' => ($user->present()->gravatar) ? $user->present()->gravatar : null, + ]; + } + $results = [ + 'items' => $users_array, + 'pagination' => + [ + 'more' => ($users->currentPage() >= $users->lastPage()) ? false : true, + 'per_page' => $users->perPage() + ], + 'total_count' => $users->total(), + 'page' => $users->currentPage(), + 'page_count' => $users->lastPage() + ]; + + return $results; + } + + + /** * Store a newly created resource in storage. * diff --git a/public/js/dist/all.js b/public/js/dist/all.js index 06afa58b0e..b0862be14a 100644 Binary files a/public/js/dist/all.js and b/public/js/dist/all.js differ diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index d8e8ff6b3b..3bd46d985c 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -27,7 +27,7 @@
{{csrf_field()}} @if ($asset->model->name) - +
{{ Form::label('name', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
@@ -45,14 +45,23 @@
- + +
+ + + + {{ Form::label('assigned_user', trans('admin/hardware/form.checkout_to'), array('class' => 'col-md-3 control-label')) }} -
- {{ Form::select('assigned_user', $users_list , Input::old('assigned_user', $asset->assigned_type == 'App\Models\User' ? $asset->assigned_to : 0), array('class'=>'select2', 'id'=>'assigned_user_select', 'style'=>'width:100%')) }} + +
+ +
{!! $errors->first('assigned_user', ' :message') !!} -
+
@can('create', \App\Models\User::class) New diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index fd00a72a5b..596d3bfbb3 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -663,7 +663,63 @@ var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value $.fn.bootstrapDP = datepicker; $('.datepicker').datepicker(); - }) + }); + + // Crazy select2 rich dropdowns with images! + $(".js-data-user-ajax").select2({ + ajax: { + url: '{{ route('api.users.selectlist') }}', + + dataType: 'json', + delay: 250, + headers: { + "X-Requested-With": 'XMLHttpRequest', + "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content') + }, + data: function (params) { + var data = { + search: params.term, + page: params.page || 1 + }; + return data; + }, + processResults: function (data, params) { + + params.page = params.page || 1; + + var answer = { + results: data.items, + pagination: { + more: "true" //(params.page < data.page_count) + } + }; + + return answer; + }, + cache: true + }, + escapeMarkup: function (markup) { return markup; }, // let our custom formatter work + templateResult: formatUserlist, + templateSelection: formatUserSelection + }); + + function formatUserlist (userlist) { + var loading_markup = ' Loading...'; + if (userlist.loading) { + return loading_markup; + } + + var markup = "
" ; + markup +="
"; + markup += "
"; + markup += "
" + userlist.text + "
"; + markup += "
"; + return markup; + } + + function formatUserSelection (userlist) { + return userlist.text; + } diff --git a/routes/api.php b/routes/api.php index db12229776..176c905695 100644 --- a/routes/api.php +++ b/routes/api.php @@ -532,20 +532,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { /*--- Users API ---*/ - Route::resource('users', 'UsersController', - [ - 'names' => - [ - 'index' => 'api.users.index', - 'show' => 'api.users.show', - 'store' => 'api.users.store', - 'update' => 'api.users.update', - 'destroy' => 'api.users.destroy' - ], - 'except' => ['create', 'edit'], - 'parameters' => ['user' => 'user_id'] - ] - ); // Users resource + Route::group([ 'prefix' => 'users' ], function () { @@ -563,6 +550,13 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { ] ); + Route::get('selectlist', + [ + 'as' => 'api.users.selectlist', + 'uses' => 'UsersController@selectList' + ] + ); + Route::get('{user}/assets', [ 'as' => 'api.users.assetlist', @@ -578,6 +572,21 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { ); }); // Users group + Route::resource('users', 'UsersController', + [ + 'names' => + [ + 'index' => 'api.users.index', + 'show' => 'api.users.show', + 'store' => 'api.users.store', + 'update' => 'api.users.update', + 'destroy' => 'api.users.destroy' + ], + 'except' => ['create', 'edit'], + 'parameters' => ['user' => 'user_id'] + ] + ); // Users resource + Route::get( 'reports/activity',