From 89a52b7551029811b07e9ce98591cf54d503e0dd Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 29 Apr 2025 18:09:32 +0100 Subject: [PATCH] Fixed fieldset display if custom fields are not available Signed-off-by: snipe --- app/Models/CustomField.php | 39 ++++++++++++++++++- app/Models/CustomFieldset.php | 14 +++++++ resources/views/hardware/audit.blade.php | 12 +++--- resources/views/hardware/checkin.blade.php | 2 +- resources/views/hardware/checkout.blade.php | 2 +- .../views/models/custom_fields_form.blade.php | 19 ++++----- .../partials/forms/edit/warranty.blade.php | 2 +- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 4954e2f17b..a852e42b6b 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -183,7 +183,44 @@ 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'); diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index d6bd7a1bef..987eb3b7d0 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -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 diff --git a/resources/views/hardware/audit.blade.php b/resources/views/hardware/audit.blade.php index 72be0e833b..d3560a9a0d 100644 --- a/resources/views/hardware/audit.blade.php +++ b/resources/views/hardware/audit.blade.php @@ -115,12 +115,6 @@ - - @include("models/custom_fields_form", [ - 'model' => $asset->model, - 'show_display_checkout_fields' => 'true' - ]) -
@@ -136,6 +130,12 @@ @include ('partials.forms.edit.image-upload', ['help_text' => trans('general.audit_images_help')]) + + @include("models/custom_fields_form", [ + 'model' => $asset->model, + 'show_custom_fields_type' => 'audit' + ]) +