mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Fixes #3414 - bulk update for asset models
This commit is contained in:
parent
a717ca683c
commit
d62896f945
|
@ -394,4 +394,73 @@ class AssetModelsController extends Controller
|
|||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a view that allows the user to bulk edit model attrbutes
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.7]
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function postBulkEdit(Request $request)
|
||||
{
|
||||
$models_raw_array = Input::get('ids');
|
||||
$models = AssetModel::whereIn('id', $models_raw_array)->get();
|
||||
$nochange = ['NC' => 'No Change'];
|
||||
$fieldset_list = $nochange + Helper::customFieldsetList();
|
||||
$depreciation_list = $nochange + Helper::depreciationList();
|
||||
$category_list = $nochange + Helper::categoryList('asset');
|
||||
$manufacturer_list = $nochange + Helper::manufacturerList();
|
||||
|
||||
|
||||
return View::make('models/bulk-edit', compact('models'))
|
||||
->with('manufacturer_list', $manufacturer_list)
|
||||
->with('category_list', $category_list)
|
||||
->with('fieldset_list', $fieldset_list)
|
||||
->with('depreciation_list', $depreciation_list);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a view that allows the user to bulk edit model attrbutes
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.7]
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function postBulkEditSave(Request $request)
|
||||
{
|
||||
|
||||
$models_raw_array = Input::get('ids');
|
||||
$update_array = array();
|
||||
|
||||
if (($request->has('manufacturer_id') && ($request->input('manufacturer_id')!='NC'))) {
|
||||
$update_array['manufacturer_id'] = $request->input('manufacturer_id');
|
||||
}
|
||||
if (($request->has('category_id') && ($request->input('category_id')!='NC'))) {
|
||||
$update_array['category_id'] = $request->input('category_id');
|
||||
}
|
||||
if ($request->input('fieldset_id')!='NC') {
|
||||
$update_array['fieldset_id'] = $request->input('fieldset_id');
|
||||
}
|
||||
if ($request->input('depreciation_id')!='NC') {
|
||||
$update_array['depreciation_id'] = $request->input('depreciation_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (count($update_array) > 0) {
|
||||
AssetModel::whereIn('id', $models_raw_array)->update($update_array);
|
||||
return redirect()->route('models.index')
|
||||
->with('success', trans('admin/models/message.bulkedit.success'));
|
||||
}
|
||||
|
||||
return redirect()->route('models.index')
|
||||
->with('warning', trans('admin/models/message.bulkedit.error'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,4 +28,9 @@ return array(
|
|||
'success' => 'Model restored successfully.'
|
||||
),
|
||||
|
||||
'bulkedit' => array(
|
||||
'error' => 'No fields were changed, so nothing was updated.',
|
||||
'success' => 'Models updated.'
|
||||
),
|
||||
|
||||
);
|
||||
|
|
0
resources/views/hardware/bulk-edit.blade.php
Normal file
0
resources/views/hardware/bulk-edit.blade.php
Normal file
91
resources/views/models/bulk-edit.blade.php
Normal file
91
resources/views/models/bulk-edit.blade.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
@extends('layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
Bulk Edit
|
||||
@parent
|
||||
@stop
|
||||
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ URL::previous() }}" class="btn btn-sm btn-primary pull-right">
|
||||
{{ trans('general.back') }}</a>
|
||||
@stop
|
||||
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
|
||||
|
||||
|
||||
|
||||
<form class="form-horizontal" method="post" action="{{ route('models.bulkedit.store') }}" autocomplete="off" role="form">
|
||||
{{ csrf_field() }}
|
||||
|
||||
<div class="box box-default">
|
||||
<div class="box-body">
|
||||
|
||||
|
||||
|
||||
<!-- manufacturer -->
|
||||
<div class="form-group {{ $errors->has('manufacturer_id') ? ' has-error' : '' }}">
|
||||
<label for="manufacturer_id" class="col-md-3 control-label">
|
||||
{{ trans('general.manufacturer') }}
|
||||
</label>
|
||||
<div class="col-md-7">
|
||||
{{ Form::select('manufacturer_id', $manufacturer_list , Input::old('manufacturer_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }}
|
||||
{!! $errors->first('manufacturer_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- category -->
|
||||
<div class="form-group {{ $errors->has('category_id') ? ' has-error' : '' }}">
|
||||
<label for="category_id" class="col-md-3 control-label">
|
||||
{{ trans('general.category') }}
|
||||
</label>
|
||||
<div class="col-md-7">
|
||||
{{ Form::select('category_id', $category_list , Input::old('category_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }}
|
||||
{!! $errors->first('category_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- custom fields -->
|
||||
<div class="form-group {{ $errors->has('fieldset_id') ? ' has-error' : '' }}">
|
||||
<label for="category_id" class="col-md-3 control-label">
|
||||
{{ trans('admin/models/general.fieldset') }}
|
||||
</label>
|
||||
<div class="col-md-7">
|
||||
{{ Form::select('fieldset_id', $fieldset_list , Input::old('fieldset_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }}
|
||||
{!! $errors->first('fieldset_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- depreciation -->
|
||||
<div class="form-group {{ $errors->has('depreciation_id') ? ' has-error' : '' }}">
|
||||
<label for="category_id" class="col-md-3 control-label">
|
||||
{{ trans('general.depreciation') }}
|
||||
</label>
|
||||
<div class="col-md-7">
|
||||
{{ Form::select('depreciation_id', $depreciation_list , Input::old('depreciation_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }}
|
||||
{!! $errors->first('depreciation_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@foreach ($models as $model)
|
||||
<input type="hidden" name="ids[{{ $model->id }}]" value="{{ $model->id }}">
|
||||
@endforeach
|
||||
</div> <!--/.box-body-->
|
||||
|
||||
<div class="box-footer text-right">
|
||||
<button type="submit" class="btn btn-success"><i class="fa fa-check icon-white"></i> {{ trans('general.save') }}</button>
|
||||
</div>
|
||||
</div> <!--/.box.box-default-->
|
||||
</form>
|
||||
</div> <!--/.col-md-8-->
|
||||
</div>
|
||||
@stop
|
|
@ -20,21 +20,37 @@
|
|||
<div class="col-md-12">
|
||||
<div class="box box-default">
|
||||
<div class="box-body">
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['models.bulkedit.index'],
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkForm']) }}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div id="toolbar">
|
||||
<select name="bulk_actions" class="form-control select2" style="width: 300px;">
|
||||
<option value="edit">Bulk Edit</option>
|
||||
</select>
|
||||
<button class="btn btn-primary" id="bulkEdit" disabled>Go</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<table
|
||||
name="models"
|
||||
class="table table-striped snipe-table"
|
||||
id="table"
|
||||
data-url="{{ route('api.models.index',array('status'=>e(Input::get('status')))) }}"
|
||||
data-url="{{ route('api.models.index') }}"
|
||||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
data-cookie-id-table="modelsTable-{{ config('version.hash_version') }}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-checkbox="true" data-field="checkbox"></th>
|
||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
||||
<th data-sortable="true" data-field="name" data-formatter="modelsLinkFormatter">{{ trans('general.name') }}</th>
|
||||
<th data-sortable="true" data-field="image" data-formatter="imageFormatter" data-visible="false">{{ trans('admin/hardware/table.image') }}</th>
|
||||
<th data-sortable="true" data-field="manufacturer" data-formatter="manufacturersLinkObjFormatter">{{ trans('general.manufacturer') }}</th>
|
||||
|
||||
<th data-sortable="true" data-field="model_number">{{ trans('admin/models/table.modelnumber') }}</th>
|
||||
<th data-sortable="false" data-field="assets_count">{{ trans('admin/models/table.numassets') }}</th>
|
||||
<th data-sortable="false" data-field="depreciation" data-formatter="depreciationsLinkObjFormatter">{{ trans('general.depreciation') }}</th>
|
||||
|
@ -46,6 +62,9 @@
|
|||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.box-body -->
|
||||
</div><!-- /.box -->
|
||||
</div>
|
||||
|
|
|
@ -8,6 +8,8 @@ Route::group([ 'prefix' => 'models', 'middleware' => ['auth'] ], function () {
|
|||
Route::get('{modelId}/view', [ 'as' => 'view/model', 'uses' => 'AssetModelsController@getView' ]);
|
||||
Route::get('{modelID}/restore', [ 'as' => 'restore/model', 'uses' => 'AssetModelsController@getRestore', 'middleware' => ['authorize:superuser'] ]);
|
||||
Route::get('{modelId}/custom_fields', ['as' => 'custom_fields/model','uses' => 'AssetModelsController@getCustomFields']);
|
||||
Route::post('bulkedit', ['as' => 'models.bulkedit.index','uses' => 'AssetModelsController@postBulkEdit']);
|
||||
Route::post('bulksave', ['as' => 'models.bulkedit.store','uses' => 'AssetModelsController@postBulkEditSave']);
|
||||
});
|
||||
|
||||
Route::resource('models', 'AssetModelsController', [
|
||||
|
|
Loading…
Reference in a new issue