Added new ajax dropdown menus for components, consumables, etc editing/creating

This commit is contained in:
snipe 2017-10-28 09:21:39 -07:00
parent fe70792cbd
commit 6a3716a06d
21 changed files with 107 additions and 105 deletions

View file

@ -56,12 +56,7 @@ class AccessoriesController extends Controller
$this->authorize('create', Accessory::class); $this->authorize('create', Accessory::class);
// Show the page // Show the page
return view('accessories/edit') return view('accessories/edit')
->with('item', new Accessory) ->with('item', new Accessory);
->with('category_list', Helper::categoryList('accessory'))
->with('company_list', Helper::companyList())
->with('supplier_list', Helper::suppliersList())
->with('location_list', Helper::locationsList())
->with('manufacturer_list', Helper::manufacturerList());
} }
@ -137,12 +132,7 @@ class AccessoriesController extends Controller
$this->authorize($item); $this->authorize($item);
return view('accessories/edit', compact('item')) return view('accessories/edit', compact('item'));
->with('category_list', Helper::categoryList('accessory'))
->with('company_list', Helper::companyList())
->with('location_list', Helper::locationsList())
->with('supplier_list', Helper::suppliersList())
->with('manufacturer_list', Helper::manufacturerList());
} }

View file

@ -159,7 +159,6 @@ class CategoriesController extends Controller
// This lets us have more flexibility in special cases like assets, where // 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 // they may not have a ->name value but we want to display something anyway
foreach ($categories as $category) { foreach ($categories as $category) {
$category->use_text = $category->name;
$category->use_image = ($category->image) ? url('/').'/uploads/categories/'.$category->image : null; $category->use_image = ($category->image) ? url('/').'/uploads/categories/'.$category->image : null;
} }

View file

@ -171,7 +171,6 @@ class CompaniesController extends Controller
// This lets us have more flexibility in special cases like assets, where // 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 // they may not have a ->name value but we want to display something anyway
foreach ($companies as $company) { foreach ($companies as $company) {
$company->use_text = $company->name;
$company->use_image = ($company->image) ? url('/').'/uploads/companies/'.$company->image : null; $company->use_image = ($company->image) ? url('/').'/uploads/companies/'.$company->image : null;
} }

View file

@ -8,6 +8,7 @@ use App\Models\Department;
use App\Http\Transformers\DepartmentsTransformer; use App\Http\Transformers\DepartmentsTransformer;
use App\Helpers\Helper; use App\Helpers\Helper;
use Auth; use Auth;
use App\Http\Transformers\SelectlistTransformer;
class DepartmentsController extends Controller class DepartmentsController extends Controller
{ {
@ -111,4 +112,39 @@ class DepartmentsController extends Controller
} }
/**
* 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', Department::class);
$departments = Department::select([
'id',
'name',
'image',
]);
if ($request->has('search')) {
$departments = $departments->where('name', 'LIKE', '%'.$request->get('search').'%');
}
$departments = $departments->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 ($departments as $department) {
$department->use_image = ($department->image) ? url('/').'/uploads/departments/'.$department->image : null;
}
return (new SelectlistTransformer)->transformSelectlist($departments);
}
} }

View file

@ -61,10 +61,7 @@ class ComponentsController extends Controller
$this->authorize('create', Component::class); $this->authorize('create', Component::class);
// Show the page // Show the page
return view('components/edit') return view('components/edit')
->with('item', new Component) ->with('item', new Component);
->with('category_list', Helper::categoryList('component'))
->with('company_list', Helper::companyList())
->with('location_list', Helper::locationsList());
} }
@ -128,9 +125,7 @@ class ComponentsController extends Controller
$this->authorize('update', $item); $this->authorize('update', $item);
return view('components/edit', compact('item')) return view('components/edit', compact('item'))
->with('category_list', Helper::categoryList('component')) ->with('category_list', Helper::categoryList('component'));
->with('company_list', Helper::companyList())
->with('location_list', Helper::locationsList());
} }

View file

@ -58,11 +58,7 @@ class ConsumablesController extends Controller
$this->authorize('create', Consumable::class); $this->authorize('create', Consumable::class);
// Show the page // Show the page
return view('consumables/edit') return view('consumables/edit')
->with('item', new Consumable) ->with('item', new Consumable);
->with('category_list', Helper::categoryList('consumable'))
->with('company_list', Helper::companyList())
->with('location_list', Helper::locationsList())
->with('manufacturer_list', Helper::manufacturerList());
} }

View file

@ -67,10 +67,7 @@ class LicensesController extends Controller
return view('licenses/edit') return view('licenses/edit')
//->with('license_options',$license_options) //->with('license_options',$license_options)
->with('depreciation_list', Helper::depreciationList()) ->with('depreciation_list', Helper::depreciationList())
->with('supplier_list', Helper::suppliersList())
->with('maintained_list', $maintained_list) ->with('maintained_list', $maintained_list)
->with('company_list', Helper::companyList())
->with('manufacturer_list', Helper::manufacturerList())
->with('item', new License); ->with('item', new License);
} }
@ -144,10 +141,7 @@ class LicensesController extends Controller
return view('licenses/edit', compact('item')) return view('licenses/edit', compact('item'))
->with('depreciation_list', Helper::depreciationList()) ->with('depreciation_list', Helper::depreciationList())
->with('supplier_list', Helper::suppliersList()) ->with('maintained_list', $maintained_list);
->with('company_list', Helper::companyList())
->with('maintained_list', $maintained_list)
->with('manufacturer_list', Helper::manufacturerList());
} }
@ -254,9 +248,7 @@ class LicensesController extends Controller
} }
$this->authorize('checkout', $licenseSeat); $this->authorize('checkout', $licenseSeat);
return view('licenses/checkout', compact('licenseSeat')) return view('licenses/checkout', compact('licenseSeat'));
->with('users_list', Helper::usersList())
->with('asset_list', Helper::detailedAssetList());
} }
@ -472,11 +464,8 @@ class LicensesController extends Controller
// Show the page // Show the page
return view('licenses/edit') return view('licenses/edit')
->with('depreciation_list', Helper::depreciationList()) ->with('depreciation_list', Helper::depreciationList())
->with('supplier_list', Helper::suppliersList())
->with('item', $license) ->with('item', $license)
->with('maintained_list', $maintained_list) ->with('maintained_list', $maintained_list);
->with('company_list', Helper::companyList())
->with('manufacturer_list', Helper::manufacturerList());
} }

View file

@ -85,10 +85,6 @@ class UsersController extends Controller
$permissions = $this->filterDisplayable($permissions); $permissions = $this->filterDisplayable($permissions);
return view('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions')) return view('users/edit', compact('groups', 'userGroups', 'permissions', 'userPermissions'))
->with('location_list', Helper::locationsList())
->with('manager_list', Helper::managerList())
->with('company_list', Helper::companyList())
->with('department_list', Helper::departmentList())
->with('user', new User); ->with('user', new User);
} }

View file

@ -25,7 +25,7 @@ class SelectlistTransformer
foreach ($select_items as $select_item) { foreach ($select_items as $select_item) {
$items_array[]= [ $items_array[]= [
'id' => (int) $select_item->id, 'id' => (int) $select_item->id,
'text' => e($select_item->use_text), 'text' => ($select_item->use_text) ? e($select_item->use_text) : e($select_item->name),
'image' => ($select_item->use_image) ? e($select_item->use_image) : null, 'image' => ($select_item->use_image) ? e($select_item->use_image) : null,
]; ];

View file

@ -9,12 +9,12 @@
{{-- Page content --}} {{-- Page content --}}
@section('inputFields') @section('inputFields')
@include ('partials.forms.edit.company') @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/accessories/general.accessory_name')]) @include ('partials.forms.edit.name', ['translated_name' => trans('admin/accessories/general.accessory_name')])
@include ('partials.forms.edit.category') @include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id'])
@include ('partials.forms.edit.supplier') @include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@include ('partials.forms.edit.manufacturer') @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
@include ('partials.forms.edit.location') @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
@include ('partials.forms.edit.model_number') @include ('partials.forms.edit.model_number')
@include ('partials.forms.edit.order_number') @include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_date') @include ('partials.forms.edit.purchase_date')

View file

@ -11,12 +11,12 @@
@section('inputFields') @section('inputFields')
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/components/table.title')]) @include ('partials.forms.edit.name', ['translated_name' => trans('admin/components/table.title')])
@include ('partials.forms.edit.category') @include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id'])
@include ('partials.forms.edit.quantity') @include ('partials.forms.edit.quantity')
@include ('partials.forms.edit.minimum_quantity') @include ('partials.forms.edit.minimum_quantity')
@include ('partials.forms.edit.serial') @include ('partials.forms.edit.serial')
@include ('partials.forms.edit.company') @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
@include ('partials.forms.edit.location') @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
@include ('partials.forms.edit.order_number') @include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_date') @include ('partials.forms.edit.purchase_date')
@include ('partials.forms.edit.purchase_cost') @include ('partials.forms.edit.purchase_cost')

View file

@ -8,11 +8,11 @@
{{-- Page content --}} {{-- Page content --}}
@section('inputFields') @section('inputFields')
@include ('partials.forms.edit.company') @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/consumables/table.title')]) @include ('partials.forms.edit.name', ['translated_name' => trans('admin/consumables/table.title')])
@include ('partials.forms.edit.category') @include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id'])
@include ('partials.forms.edit.manufacturer') @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
@include ('partials.forms.edit.location') @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
@include ('partials.forms.edit.model_number') @include ('partials.forms.edit.model_number')
@include ('partials.forms.edit.item_number') @include ('partials.forms.edit.item_number')
@include ('partials.forms.edit.order_number') @include ('partials.forms.edit.order_number')

View file

@ -30,8 +30,8 @@
{!! $errors->first('seats', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!} {!! $errors->first('seats', '<div class="col-md-8 col-md-offset-3"><span class="alert-msg"><i class="fa fa-times"></i> :message</span></div>') !!}
</div> </div>
@include ('partials.forms.edit.company') @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
@include ('partials.forms.edit.manufacturer') @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
<!-- Licensed to name --> <!-- Licensed to name -->
<div class="form-group {{ $errors->has('license_name') ? ' has-error' : '' }}"> <div class="form-group {{ $errors->has('license_name') ? ' has-error' : '' }}">
@ -61,7 +61,7 @@
</div> </div>
@include ('partials.forms.edit.supplier') @include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@include ('partials.forms.edit.order_number') @include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_cost') @include ('partials.forms.edit.purchase_cost')
@include ('partials.forms.edit.purchase_date') @include ('partials.forms.edit.purchase_date')

View file

@ -3,7 +3,7 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7 required"> <div class="col-md-7 required">
<select class="js-data-ajax" data-endpoint="hardware" name="{{ $fieldname }}" style="width: 100%" id="assigned_asset_select"> <select class="js-data-ajax" data-endpoint="hardware" name="{{ $fieldname }}" style="width: 100%" id="assigned_asset_select">
@if ($asset_id = Input::old($fieldname, $item->{$fieldname})) @if ($asset_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $asset_id }}" selected="selected"> <option value="{{ $asset_id }}" selected="selected">
{{ \App\Models\Asset::find($asset_id)->present()->fullName }} {{ \App\Models\Asset::find($asset_id)->present()->fullName }}
</option> </option>

View file

@ -3,12 +3,12 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7"> <div class="col-md-7">
<select class="js-data-ajax" data-endpoint="companies" name="{{ $fieldname }}" style="width: 100%" id="company_select"> <select class="js-data-ajax" data-endpoint="companies" name="{{ $fieldname }}" style="width: 100%" id="company_select">
@if ($company_id = Input::old($fieldname, $item->{$fieldname})) @if ($company_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $company_id }}" selected="selected"> <option value="{{ $company_id }}" selected="selected">
{{ \App\Models\Company::find($company_id)->name }} {{ \App\Models\Company::find($company_id)->name }}
</option> </option>
@else @else
<option value="">{{ trans('general.select_model') }}</option> <option value="">{{ trans('general.select_company') }}</option>
@endif @endif
</select> </select>
</div> </div>

View file

@ -0,0 +1,20 @@
<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="departments" name="{{ $fieldname }}" style="width: 100%" id="department_select">
@if ($department_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $department_id }}" selected="selected">
{{ \App\Models\Department::find($department_id)->name }}
</option>
@else
<option value="">{{ trans('general.select_department') }}</option>
@endif
</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>

View file

@ -4,7 +4,7 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }} {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}"> <div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="locations" name="{{ $fieldname }}" style="width: 100%" id="{{ $fieldname }}_location_select"> <select class="js-data-ajax" data-endpoint="locations" name="{{ $fieldname }}" style="width: 100%" id="{{ $fieldname }}_location_select">
@if ($location_id = Input::old($fieldname, $item->{$fieldname})) @if ($location_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $location_id }}" selected="selected"> <option value="{{ $location_id }}" selected="selected">
{{ \App\Models\Location::find($location_id)->name }} {{ \App\Models\Location::find($location_id)->name }}
</option> </option>

View file

@ -4,7 +4,7 @@
<div class="col-md-7 required"> <div class="col-md-7 required">
<select class="js-data-ajax" data-endpoint="users" name="{{ $fieldname }}" style="width: 100%" id="assigned_user_select"> <select class="js-data-ajax" data-endpoint="users" name="{{ $fieldname }}" style="width: 100%" id="assigned_user_select">
@if ($user_id = Input::old($fieldname, $item->{$fieldname})) @if ($user_id = Input::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $user_id }}" selected="selected"> <option value="{{ $user_id }}" selected="selected">
{{ \App\Models\User::find($user_id)->name }} {{ \App\Models\User::find($user_id)->name }}
</option> </option>

View file

@ -150,8 +150,7 @@
autocomplete="off" autocomplete="off"
readonly readonly
onfocus="this.removeAttribute('readonly');" onfocus="this.removeAttribute('readonly');"
{{ ((config('app.lock_passwords') && ($user->id)) ? ' disabled' : '') }} {{ ((config('app.lock_passwords') && ($user->id)) ? ' disabled' : '') }}>
>
@else @else
(Managed via LDAP) (Managed via LDAP)
@endif @endif
@ -202,8 +201,7 @@
{{ ((config('app.lock_passwords') && ($user->id)) ? ' disabled' : '') }} {{ ((config('app.lock_passwords') && ($user->id)) ? ' disabled' : '') }}
autocomplete="off" autocomplete="off"
readonly readonly
onfocus="this.removeAttribute('readonly');" onfocus="this.removeAttribute('readonly');">
>
@if (config('app.lock_passwords') && ($user->id)) @if (config('app.lock_passwords') && ($user->id))
<p class="help-block">{{ trans('admin/users/table.lock_passwords') }}</p> <p class="help-block">{{ trans('admin/users/table.lock_passwords') }}</p>
@endif @endif
@ -213,16 +211,7 @@
<!-- Company --> <!-- Company -->
@if (\App\Models\Company::canManageUsersCompanies()) @if (\App\Models\Company::canManageUsersCompanies())
<!-- Company --> @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.select_company'), 'fieldname' => 'company_id'])
<div class="form-group {{ $errors->has('company_id') ? 'has-error' : '' }}">
<div class="col-md-3 control-label">
{{ Form::label('company_id', trans('general.company')) }}
</div>
<div class="col-md-8">
{{ Form::select('company_id', $company_list , Input::old('company_id', $user->company_id), array('class'=>'select2', 'style'=>'width:350px')) }}
{!! $errors->first('company_id', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
@endif @endif
<!-- language --> <!-- language -->
@ -267,35 +256,14 @@
<!-- Manager --> <!-- Manager -->
<div class="form-group {{ $errors->has('manager_id') ? 'has-error' : '' }}"> @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'manager_id'])
<label class="col-md-3 control-label" for="manager_id">{{ trans('admin/users/table.manager') }}</label>
<div class="col-md-8">
{{ Form::select('manager_id', $manager_list , Input::old('manager_id', $user->manager_id), array('class'=>'select2', 'style'=>'width:350px')) }}
{!! $errors->first('manager_id', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
<!-- Department --> <!-- Department -->
<div class="form-group {{ $errors->has('department_id') ? ' has-error' : '' }}"> @include ('partials.forms.edit.department-select', ['translated_name' => trans('general.select_department'), 'fieldname' => 'department_id'])
<label for="status_id" class="col-md-3 control-label">
{{ trans('general.department') }}
</label>
<div class="col-md-7">
{{ Form::select('department_id', $department_list , Input::old('department_id', $user->department_id), array('class'=>'select2', 'style'=>'width:350px')) }}
{!! $errors->first('department_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- Location --> <!-- Location -->
<div class="form-group {{ $errors->has('location_id') ? 'has-error' : '' }}"> @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.select_location'), 'fieldname' => 'location_id'])
<label class="col-md-3 control-label" for="location_id">{{ trans('admin/users/table.location') }}
</label>
<div class="col-md-8">
{{ Form::select('location_id', $location_list , Input::old('location_id', $user->location_id), array('class'=>'select2', 'style'=>'width:350px')) }}
{!! $errors->first('location_id', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
<!-- Phone --> <!-- Phone -->
<div class="form-group {{ $errors->has('phone') ? 'has-error' : '' }}"> <div class="form-group {{ $errors->has('phone') ? 'has-error' : '' }}">

View file

@ -67,7 +67,7 @@
array('deleted'=> (Input::get('status')=='deleted') ? 'true' : 'false','company_id'=>e(Input::get('company_id')))) }}" array('deleted'=> (Input::get('status')=='deleted') ? 'true' : 'false','company_id'=>e(Input::get('company_id')))) }}"
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="userTableDisplay-{{ config('version.hash_version') }}"> data-cookie-id-table="userlTableDisplay-{{ config('version.hash_version') }}">
</table> </table>

View file

@ -98,6 +98,20 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
/*--- Departments API ---*/ /*--- Departments API ---*/
/*--- Suppliers API ---*/
Route::group(['prefix' => 'departments'], function () {
Route::get('selectlist',
[
'as' => 'api.departments.selectlist',
'uses' => 'DepartmentsController@selectlist'
]
);
}); // Departments group
Route::resource('departments', 'DepartmentsController', Route::resource('departments', 'DepartmentsController',
[ [
'names' => 'names' =>
@ -568,7 +582,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
'uses' => 'SuppliersController@selectlist' 'uses' => 'SuppliersController@selectlist'
] ]
); );
}); // Categories group }); // Suppliers group
Route::resource('suppliers', 'SuppliersController', Route::resource('suppliers', 'SuppliersController',