Fixed fieldset display if custom fields are not available

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-04-29 18:09:32 +01:00
parent 15870d0e75
commit 89a52b7551
7 changed files with 68 additions and 22 deletions

View file

@ -184,6 +184,43 @@ class CustomField extends Model
return $this->belongsToMany(\App\Models\CustomFieldset::class);
}
public function displayFieldInCheckinForm()
{
if ($this->display_checkin == '1') {
return true;
}
return false;
}
public function displayFieldInCheckoutForm()
{
if ($this->display_checkout == '1') {
return true;
}
return false;
}
public function displayFieldInAuditForm()
{
if ($this->display_audit == '1') {
return true;
}
return false;
}
public function displayFieldInCurrentForm($form_type = null)
{
switch ($form_type) {
case 'audit':
return $this->displayFieldInAuditForm();
case 'checkin':
return $this->displayFieldInCheckinForm();
case 'checkin':
return $this->displayFieldInCheckoutForm();
}
}
public function assetModels()
{
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');

View file

@ -71,6 +71,20 @@ class CustomFieldset extends Model
return $this->belongsTo(\App\Models\User::class); //WARNING - not all CustomFieldsets have a User!!
}
public function displayAnyFieldsInForm($form_type = null)
{
switch ($form_type) {
case 'audit':
return $this->displayFieldInAuditForm();
case 'checkin':
return $this->displayFieldInCheckinForm();
case 'checkout':
return $this->displayFieldInCheckoutForm();
default:
return true;
}
}
/**
* Determine the validation rules we should apply based on the
* custom field format

View file

@ -115,12 +115,6 @@
</div>
</div>
<!-- Custom fields -->
@include("models/custom_fields_form", [
'model' => $asset->model,
'show_display_checkout_fields' => 'true'
])
<!-- Note -->
<div class="form-group{{ $errors->has('note') ? ' has-error' : '' }}">
@ -136,6 +130,12 @@
<!-- Audit Image -->
@include ('partials.forms.edit.image-upload', ['help_text' => trans('general.audit_images_help')])
<!-- Custom fields -->
@include("models/custom_fields_form", [
'model' => $asset->model,
'show_custom_fields_type' => 'audit'
])
</div> <!--/.box-body-->
<div class="box-footer">

View file

@ -142,7 +142,7 @@
<!-- Custom fields -->
@include("models/custom_fields_form", [
'model' => $asset->model,
'show_display_checkin_fields' => 'true'
'show_custom_fields_type' => 'checkin'
])

View file

@ -145,7 +145,7 @@
<!-- Custom fields -->
@include("models/custom_fields_form", [
'model' => $asset->model,
'show_display_checkout_fields' => 'true'
'show_custom_fields_type' => 'checkout'
])
<!-- Note -->

View file

@ -1,25 +1,21 @@
@if (($model) && ($model->fieldset))
@if (($model) && ($model->fieldset) && $model->fieldset->displayAnyFieldsInForm($show_custom_fields_type ?? ''))
<div class="col-md-12 col-sm-12">
<fieldset name="custom-fields" class="bottom-padded">
<legend class="highlight">
{{ trans('admin/custom_fields/general.custom_fields') }}
</legend>
@foreach($model->fieldset->fields AS $field)
@if (
((!isset($show_display_checkin_fields))
|| (($field->display_checkin == '1')
&& ($show_display_checkin_fields =='true'))) &&
((!isset($show_display_checkout_fields))
|| (($field->display_checkout == '1')
&& ($show_display_checkout_fields =='true')))
)
@foreach($model->fieldset->fields as $field)
@if (!isset($show_custom_fields_type) || ($field->displayFieldInCurrentForm($show_custom_fields_type)))
<div class="form-group{{ $errors->has($field->db_column_name()) ? ' has-error' : '' }}">
<label for="{{ $field->db_column_name() }}" class="col-md-3 control-label">
{{ $field->name }}
</label>
<div class="col-md-7 col-sm-12">
@ -105,7 +101,6 @@
</div>
@endif
</div>
@endif
@endforeach

View file

@ -2,7 +2,7 @@
<div class="form-group {{ $errors->has('warranty_months') ? ' has-error' : '' }}">
<label for="warranty_months" class="col-md-3 control-label">{{ trans('admin/hardware/form.warranty') }}</label>
<div class="col-md-9">
<div class="input-group col-md-3" style="padding-left: 0px;">
<div class="input-group col-md-4 col-sm-6" style="padding-left: 0px;">
<input class="form-control" type="text" name="warranty_months" id="warranty_months" value="{{ old('warranty_months', $item->warranty_months) }}" maxlength="3" />
<span class="input-group-addon">{{ trans('admin/hardware/form.months') }}</span>
</div>