Fixed #4412 - use select2 ajax list for asset maintenances

This commit is contained in:
snipe 2017-11-12 17:22:16 -08:00
parent 7eef1b4bcf
commit 0396267388
3 changed files with 13 additions and 21 deletions

View file

@ -154,16 +154,21 @@ class AssetMaintenancesController extends Controller
*/
public function create()
{
$asset = null;
if ($asset = Asset::find(request('asset_id'))) {
// We have to set this so that the correct property is set in the select2 ajax dropdown
$asset->asset_id = $asset->id;
}
// Prepare Asset Maintenance Type List
$assetMaintenanceType = [
'' => 'Select an asset maintenance type',
] + AssetMaintenance::getImprovementOptions();
// Mark the selected asset, if it came in
// Render the view
return view('asset_maintenances/edit')
->with('asset_list', Helper::detailedAssetList())
->with('selectedAsset', request('asset_id'))
->with('supplier_list', Helper::suppliersList())
->with('asset', $asset)
->with('assetMaintenanceType', $assetMaintenanceType)
->with('item', new AssetMaintenance);
}

View file

@ -41,22 +41,8 @@
</div><!-- /.box-header -->
<div class="box-body">
<!-- Asset -->
<div class="form-group {{ $errors->has('asset_id') ? ' has-error' : '' }}">
<label for="asset_id" class="col-md-3 control-label">
{{ trans('admin/asset_maintenances/table.asset_name') }}
</label>
<div class="col-md-7{{ (\App\Helpers\Helper::checkIfRequired($item, 'asset_id')) ? ' required' : '' }}">
@if ($selectedAsset == null)
{{ Form::select('asset_id', $asset_list , Input::old('asset_id', $item->asset_id), ['class'=>'select2', 'style'=>'min-width:350px']) }}
@else
{{ Form::select('asset_id', $asset_list , Input::old('asset_id', $selectedAsset), ['class'=>'select2', 'style'=>'min-width:350px', 'enabled' => 'false']) }}
@endif
{!! $errors->first('asset_id', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div> <!-- .form-group -->
@include ('partials.forms.edit.supplier')
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/asset_maintenances/table.asset_name'), 'fieldname' => 'asset_id'])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@include ('partials.forms.edit.maintenance_type')
<!-- Title -->

View file

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