Merge pull request #10967 from veenone/fix/hide_optional_field_on_create_asset

Fixes #8155 -  improve the workflow during asset creation
This commit is contained in:
snipe 2022-06-24 18:53:07 -07:00 committed by GitHub
commit d70b36750c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 143 additions and 60 deletions

View file

@ -20,6 +20,7 @@ use Gate;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Cookie;
use Input; use Input;
use Intervention\Image\Facades\Image; use Intervention\Image\Facades\Image;
use League\Csv\Reader; use League\Csv\Reader;
@ -201,18 +202,36 @@ class AssetsController extends Controller
} }
$success = true; $success = true;
// $cookie = Cookie::queue(Cookie::make('optional_info', $_POST['options'],$minutes));
// $data = $request->session()->all();
// dd($_POST['options']);
} }
} }
if ($success) { if ($success) {
// Redirect to the asset listing page // Redirect to the asset listing page
$minutes = 518400;
// dd( $_POST['options']);
// Cookie::queue(Cookie::make('optional_info', json_decode($_POST['options']), $minutes));
return redirect()->route('hardware.index') return redirect()->route('hardware.index')
->with('success', trans('admin/hardware/message.create.success')); ->with('success', trans('admin/hardware/message.create.success'))
->withCookie(cookie('optional_info',json_encode($_POST['options']),$minutes,null,null,null,false));
} }
return redirect()->back()->withInput()->withErrors($asset->getErrors()); return redirect()->back()->withInput()->withErrors($asset->getErrors());
} }
public function getOptionCookie(Request $request){
$value = $request->cookie('optional_info');
echo $value;
return $value;
}
/** /**
* Returns a view that presents a form to edit an existing asset. * Returns a view that presents a form to edit an existing asset.
* *

View file

@ -46,4 +46,6 @@ return [
'asset_not_deployable' => 'That asset status is not deployable. This asset cannot be checked out.', 'asset_not_deployable' => 'That asset status is not deployable. This asset cannot be checked out.',
'asset_deployable' => 'That status is deployable. This asset can be checked out.', 'asset_deployable' => 'That status is deployable. This asset can be checked out.',
'processing_spinner' => 'Processing...', 'processing_spinner' => 'Processing...',
'optional_infos' => 'Optional Information',
'order_details' => 'Order Related Information'
]; ];

View file

@ -10,16 +10,16 @@
{{-- Page content --}} {{-- Page content --}}
@section('inputFields') @section('inputFields')
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id']) @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
<!-- {{Request::cookie('optional_info');}} -->
<!-- Asset Tag --> <!-- Asset Tag -->
<div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}"> <div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}">
<label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}</label> <label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}</label>
<!-- we are editing an existing asset --> <!-- we are editing an existing asset -->
@if ($item->id) @if ($item->id)
<div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}"> <div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}">
@ -41,78 +41,105 @@
</div> </div>
@endif @endif
</div> </div>
@include ('partials.forms.edit.serial', ['fieldname'=> 'serials[1]', 'translated_serial' => trans('admin/hardware/form.serial')])
<div class="input_fields_wrap"> <div class="input_fields_wrap">
</div> </div>
@include ('partials.forms.edit.model-select', ['translated_name' => trans('admin/hardware/form.model'), 'fieldname' => 'model_id', 'field_req' => true]) @include ('partials.forms.edit.model-select', ['translated_name' => trans('admin/hardware/form.model'), 'fieldname' => 'model_id', 'field_req' => true])
@include ('partials.forms.edit.serial', ['fieldname'=> 'serials[1]', 'translated_serial' => trans('admin/hardware/form.serial')])
<div id='custom_fields_content'> @include ('partials.forms.edit.status', [ 'required' => 'true'])
<!-- Custom Fields --> @if (!$item->id)
@if ($item->model && $item->model->fieldset) @include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true', 'style' => 'display:none;'])
<?php $model=$item->model; ?> @include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user', 'style' => 'display:none;', 'required' => 'false'])
@endif @include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset', 'style' => 'display:none;', 'required' => 'false'])
@if (Request::old('model_id')) @include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required' => 'false'])
<?php $model=\App\Models\AssetModel::find(Request::old('model_id')); ?> @elseif (($item->assignedTo) && ($item->deleted_at==''))
@elseif (isset($selected_model)) <!-- This is an asset and it's currently deployed, so let them edit the expected checkin date -->
<?php $model=$selected_model; ?> @include ('partials.forms.edit.datepicker', ['translated_name' => trans('admin/hardware/form.expected_checkin'),'fieldname' => 'expected_checkin'])
@endif @endif
@if (isset($model) && $model)
@include("models/custom_fields_form",["model" => $model])
@endif
</div>
@include ('partials.forms.edit.status', [ 'required' => 'true']) @include ('partials.forms.edit.notes')
@if (!$item->id) @include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'fieldname' => 'rtd_location_id'])
@include ('partials.forms.checkout-selector', ['user_select' => 'true','asset_select' => 'true', 'location_select' => 'true', 'style' => 'display:none;']) @include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/hardware/general.requestable')])
@include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_user', 'style' => 'display:none;', 'required' => 'false'])
@include ('partials.forms.edit.asset-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_asset', 'style' => 'display:none;', 'required' => 'false'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.checkout_to'), 'fieldname' => 'assigned_location', 'style' => 'display:none;', 'required' => 'false'])
@elseif (($item->assignedTo) && ($item->deleted_at==''))
<!-- This is an asset and it's currently deployed, so let them edit the expected checkin date -->
@include ('partials.forms.edit.datepicker', ['translated_name' => trans('admin/hardware/form.expected_checkin'),'fieldname' => 'expected_checkin'])
@endif
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')]) <!-- Image -->
@include ('partials.forms.edit.purchase_date') @if ($item->image)
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id']) <div class="form-group {{ $errors->has('image_delete') ? 'has-error' : '' }}">
@include ('partials.forms.edit.order_number') <label class="col-md-3 control-label" for="image_delete">{{ trans('general.image_delete') }}</label>
<?php <div class="col-md-5">
$currency_type=null; <label class="control-label" for="image_delete">
if ($item->id && $item->location) { <input type="checkbox" value="1" name="image_delete" id="image_delete" class="minimal" {{ Request::old('image_delete') == '1' ? ' checked="checked"' : '' }}>
$currency_type = $item->location->currency; {!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!}
} </label>
?> <div style="margin-top: 0.5em">
@include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type]) <img src="{{ Storage::disk('public')->url(app('assets_upload_path').e($item->image)) }}" class="img-responsive" />
@include ('partials.forms.edit.warranty') </div>
@include ('partials.forms.edit.notes') </div>
</div>
@endif
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'fieldname' => 'rtd_location_id']) @include ('partials.forms.edit.image-upload')
<div id='custom_fields_content'>
<!-- Custom Fields -->
@if ($item->model && $item->model->fieldset)
<?php $model=$item->model; ?>
@endif
@if (Request::old('model_id'))
<?php $model=\App\Models\AssetModel::find(Request::old('model_id')); ?>
@elseif (isset($selected_model))
<?php $model=$selected_model; ?>
@endif
@if (isset($model) && $model)
@include("models/custom_fields_form",["model" => $model])
@endif
</div>
@include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/hardware/general.requestable')]) <div class="form-group" >
<label class="col-md-3 control-label"></label>
<div class="col-md-2 col-sm-2 text-left form-check" style="z-index:1;">
<!-- Image --> <input class="form-check-input" type="checkbox" id="optional_info" name="options[]" value="optional" <?php if (!empty (json_decode(Cookie::get('optional_info')))) {if(in_array('optional',json_decode(Cookie::get('optional_info')))) {echo 'checked';} else {echo 'unchecked';}} else {echo 'unchecked';} ?>>
@if ($item->image) <label class="form-check-label" for="flexCheckDefault">
<div class="form-group {{ $errors->has('image_delete') ? 'has-error' : '' }}"> {{ trans('admin/hardware/form.optional_infos') }}
<label class="col-md-3 control-label" for="image_delete">{{ trans('general.image_delete') }}</label> </label>
<div class="col-md-5"> </div>
<label class="control-label" for="image_delete">
<input type="checkbox" value="1" name="image_delete" id="image_delete" class="minimal" {{ Request::old('image_delete') == '1' ? ' checked="checked"' : '' }}> <div id="optional_details" class="col-md-12" style="display:none">
{!! $errors->first('image_delete', '<span class="alert-msg">:message</span>') !!} @include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')])
</label> @include ('partials.forms.edit.warranty')
<div style="margin-top: 0.5em"> </div>
<img src="{{ Storage::disk('public')->url(app('assets_upload_path').e($item->image)) }}" class="img-responsive" /> </div>
</div>
</div>
</div>
@endif
@include ('partials.forms.edit.image-upload') <div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-2 col-sm-2 text-left form-check" style="z-index:2;">
<input class="form-check-input" type="checkbox" id="order_info" name="options[]" value="order" <?php if (!empty (json_decode(Cookie::get('optional_info')))) {if(in_array('order',json_decode(Cookie::get('optional_info')))) {echo 'checked';} else {echo 'unchecked';}} else {echo 'unchecked';} ?>>
<label class="form-check-label" for="flexCheckDefault">
{{ trans('admin/hardware/form.order_details') }}
</label>
</div>
<div id='order_details' class="col-md-12" style="z-index:1;" style="display:none">
@include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_date')
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
<?php
$currency_type=null;
if ($item->id && $item->location) {
$currency_type = $item->location->currency;
}
?>
@include ('partials.forms.edit.purchase_cost', ['currency_type' => $currency_type])
</div>
</div>
@stop @stop
@section('moar_scripts') @section('moar_scripts')
@ -121,7 +148,6 @@
<script nonce="{{ csrf_token() }}"> <script nonce="{{ csrf_token() }}">
var transformed_oldvals={}; var transformed_oldvals={};
function fetchCustomFields() { function fetchCustomFields() {
@ -283,6 +309,42 @@
}) })
}); });
$(document).ready(function() {
checkOrderDetailOption();
checkOptionalOption();
});
if ($('#order_info').is(":checked")){
checkOrderDetailOption();
}
$('#order_info').change(function(){
checkOrderDetailOption();
});
if ($('#optional_info').is(":checked")){
checkOptionalOption();
}
$('#optional_info').change(function(){
checkOptionalOption();
});
function checkOptionalOption(){
if ($("#optional_info").prop('checked')==true) {
$('#optional_details').show();
} else {
$('#optional_details').hide();
}
}
function checkOrderDetailOption(){
if ($("#order_info").prop('checked')==true) {
$('#order_details').show();
} else {
$('#order_details').hide();
}
}
</script> </script>
@stop @stop