A free open source IT asset/license management system
Fixed fieldset display if custom fields are not available
snipe89a52b755102
diff --git a/app/Models/CustomField.php b/app/Models/CustomField.phpindex 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.phpindex d6bd7a1bef..987eb3b7d0 100644--- a/app/Models/CustomFieldset.php+++ b/app/Models/CustomFieldset.php@@ -71,6 +71,20 @@ class CustomFieldset extends Modelreturn $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 formatdiff --git a/resources/views/hardware/audit.blade.php b/resources/views/hardware/audit.blade.phpindex 72be0e833b..d3560a9a0d 100644--- a/resources/views/hardware/audit.blade.php+++ b/resources/views/hardware/audit.blade.php@@ -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">diff --git a/resources/views/hardware/checkin.blade.php b/resources/views/hardware/checkin.blade.phpindex 93f3197cbb..2137c11ca2 100755--- a/resources/views/hardware/checkin.blade.php+++ b/resources/views/hardware/checkin.blade.php@@ -142,7 +142,7 @@<!-- Custom fields -->@include("models/custom_fields_form", ['model' => $asset->model,- 'show_display_checkin_fields' => 'true'+ 'show_custom_fields_type' => 'checkin'])diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.phpindex b237a2d004..3aedbfd054 100755--- a/resources/views/hardware/checkout.blade.php+++ b/resources/views/hardware/checkout.blade.php@@ -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 -->diff --git a/resources/views/models/custom_fields_form.blade.php b/resources/views/models/custom_fields_form.blade.phpindex 27718bc77b..929c5fbea4 100644--- a/resources/views/models/custom_fields_form.blade.php+++ b/resources/views/models/custom_fields_form.blade.php@@ -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,9 +101,8 @@</div>@endif-</div>- @endif+ @endif@endforeach</fieldset></div>diff --git a/resources/views/partials/forms/edit/warranty.blade.php b/resources/views/partials/forms/edit/warranty.blade.phpindex eaa4222289..de4beaf2fa 100644--- a/resources/views/partials/forms/edit/warranty.blade.php+++ b/resources/views/partials/forms/edit/warranty.blade.php@@ -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>