Move form into its own component
This commit is contained in:
@@ -24,6 +24,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
|
||||
/**
|
||||
* This service provider handles setting the observers on models
|
||||
@@ -42,6 +43,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(UrlGenerator $url)
|
||||
{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This is a workaround for proxies/reverse proxies that don't always pass the proper headers.
|
||||
*
|
||||
@@ -76,6 +80,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
Consumable::observe(ConsumableObserver::class);
|
||||
License::observe(LicenseObserver::class);
|
||||
Setting::observe(SettingObserver::class);
|
||||
|
||||
// https://laravel.com/docs/11.x/blade#html-entity-encoding
|
||||
Blade::withoutDoubleEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,7 @@
|
||||
|
||||
|
||||
<div {{ $attributes->merge(['class' => 'col-lg-6 col-lg-offset-3 col-md-10 col-md-offset-1 col-sm-12 col-sm-offset-0']) }}>
|
||||
@if ($item->id)
|
||||
<form class="form-horizontal" method="post" action="{{ route('maintenances.update', $item->id) }}" autocomplete="off" enctype="multipart/form-data">
|
||||
{{ method_field('PUT') }}
|
||||
@else
|
||||
<form class="form-horizontal" method="post" action="{{ route('maintenances.store') }}" autocomplete="off" enctype="multipart/form-data">
|
||||
@endif
|
||||
|
||||
|
||||
<!-- CSRF Token -->
|
||||
{{ csrf_field() }}
|
||||
@@ -48,5 +43,5 @@
|
||||
<!-- /.box-footer -->
|
||||
|
||||
</div> <!-- /.box-default -->
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<!-- form-row blade component -->
|
||||
@props([
|
||||
'errors_class' => ($errors->has($name) ? ' has-error' : null),
|
||||
'help_text' => null,
|
||||
'info_tooltip_text' => null,
|
||||
'input_div_class' => 'col-md-8',
|
||||
'input_class' => null,
|
||||
'input_group_addon' => null,
|
||||
'input_group_text' => null,
|
||||
'input_icon' => null,
|
||||
@@ -14,18 +14,25 @@
|
||||
'label' => null,
|
||||
'min' => null,
|
||||
'maxlength' => null,
|
||||
'name' => null,
|
||||
'name' => false,
|
||||
'placeholder' => null,
|
||||
'rows' => null,
|
||||
'static_value' => null,
|
||||
'type' => 'text',
|
||||
'data_endpoint' => false,
|
||||
'multiple' => false,
|
||||
'required' => false,
|
||||
'show_create_new' => false,
|
||||
])
|
||||
|
||||
<div {{ $attributes->merge(['class' => 'form-group'. $errors_class]) }}>
|
||||
<div class="form-group">
|
||||
{{-- <div {{ $attributes->merge(['class' => 'form-group '. ($errors->has($name) ? ' has-error' : '')]) }}> --}}
|
||||
|
||||
<!-- form label -->
|
||||
@if (isset($label))
|
||||
@if (isset($name) && $label)
|
||||
<x-form-label :for="$name" class="{{ $label_class ?? 'col-md-3' }}">{{ $label }}</x-form-label>
|
||||
@else
|
||||
<div class="{{ $label_class ?? 'col-md-3' }}">{{ $label }}</div>
|
||||
@endif
|
||||
|
||||
|
||||
@@ -34,29 +41,51 @@
|
||||
@endphp
|
||||
|
||||
<div class="{{ $input_div_class }}">
|
||||
<x-dynamic-component
|
||||
:$name
|
||||
:$type
|
||||
:aria-label="$name"
|
||||
:component="'input.'.$blade_type"
|
||||
:id="$name"
|
||||
:required="Helper::checkIfRequired($item, $name)"
|
||||
:value="old($name, $item->{$name})"
|
||||
:input_icon="$input_icon"
|
||||
:input_group_addon="$input_group_addon"
|
||||
:input_group_text="$input_group_text"
|
||||
:rows="$rows"
|
||||
:placeholder="$placeholder"
|
||||
:options="$input_options"
|
||||
:selected="$input_selected"
|
||||
:style="$input_style_override"
|
||||
:maxlength="$maxlength"
|
||||
:min="$min"
|
||||
:static_value="$static_value"
|
||||
|
||||
/>
|
||||
@if ($slot->isNotEmpty())
|
||||
<p class="form-control-static">
|
||||
{{ $slot }}
|
||||
</p>
|
||||
@else
|
||||
|
||||
<x-dynamic-component
|
||||
:$name
|
||||
:$type
|
||||
:aria-label="$name"
|
||||
:class="$input_class"
|
||||
:component="'input.'.$blade_type"
|
||||
:data-placeholder="$placeholder"
|
||||
:data_endpoint="$data_endpoint"
|
||||
:id="$name"
|
||||
:input_group_addon="$input_group_addon"
|
||||
:input_group_text="$input_group_text"
|
||||
:input_icon="$input_icon"
|
||||
:maxlength="$maxlength"
|
||||
:min="$min"
|
||||
:options="$input_options"
|
||||
:placeholder="$placeholder"
|
||||
:required="($required=='true' || Helper::checkIfRequired($item, $name))"
|
||||
:rows="$rows"
|
||||
:selected="$input_selected"
|
||||
:static_value="$static_value"
|
||||
:style="$input_style_override"
|
||||
:value="old($name, $item->{$name})"
|
||||
:multiple="$multiple"
|
||||
/>
|
||||
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
@if ($show_create_new)
|
||||
<div class="col-md-1 col-sm-1 text-left">
|
||||
@can('create', '\App\Models\\'.ucwords($show_create_new).'::class')
|
||||
<a href='{{ route('modal.show', class_basename($show_create_new)) }}' data-toggle="modal" data-target="#createModal" data-select='supplier_select' class="btn btn-sm btn-primary">{{ trans('button.new') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@if ($info_tooltip_text)
|
||||
<!-- Info Tooltip -->
|
||||
<div class="col-md-1 text-left" style="padding-left:0; margin-top: 5px;">
|
||||
@@ -87,4 +116,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
@props([
|
||||
'item' => null,
|
||||
'update_route' => null,
|
||||
'create_route' => null,
|
||||
])
|
||||
|
||||
<form class="form-horizontal" id="create-form" method="post" action="{{ ($item->id) ? route($update_route, $item->id) : route($create_route) }}" autocomplete="off" enctype="multipart/form-data">
|
||||
|
||||
@if ($item->id)
|
||||
{{ method_field('PUT') }}
|
||||
@endif
|
||||
|
||||
{{ $slot }}
|
||||
|
||||
</form>
|
||||
@@ -0,0 +1,16 @@
|
||||
@props([
|
||||
'selected' => null,
|
||||
'forLivewire' => false,
|
||||
'data_endpoint' => false,
|
||||
'data_placeholder' => false,
|
||||
'multiple' => false,
|
||||
])
|
||||
<select
|
||||
{{ ($multiple == 'true')? ' multiple' : '' }}
|
||||
{{ $attributes->class(['select2', 'livewire-select2' => $forLivewire])->style(['width:100%']) }}
|
||||
@if($forLivewire) data-livewire-component="{{ $this->getId() }}" @endif
|
||||
data-endpoint="{{ $data_endpoint }}"
|
||||
data-placeholder="{{ $data_placeholder }}"
|
||||
>
|
||||
|
||||
</select>
|
||||
@@ -3,5 +3,5 @@
|
||||
])
|
||||
|
||||
<p class="form-control-static">
|
||||
{{ $static_value }}
|
||||
{{ $slot ?? $static_value }}
|
||||
</p>
|
||||
@@ -19,73 +19,62 @@
|
||||
|
||||
{{-- Page content --}}
|
||||
@section('content')
|
||||
|
||||
<div class="row">
|
||||
<x-box
|
||||
:$item
|
||||
header_icon="maintenances"
|
||||
>
|
||||
|
||||
|
||||
<!-- Inititate form component -->
|
||||
<x-form :$item update_route="maintenances.update" create_route="maintenances.store">
|
||||
|
||||
<!-- Name -->
|
||||
<x-form-row
|
||||
:label="trans('general.name')"
|
||||
:$item
|
||||
name="name"
|
||||
/>
|
||||
|
||||
<!-- This is a new maintenance -->
|
||||
@if (!$item->id)
|
||||
|
||||
|
||||
@include ('partials.forms.edit.asset-select', [
|
||||
'translated_name' => trans('general.assets'),
|
||||
'fieldname' => 'selected_assets[]',
|
||||
'multiple' => true,
|
||||
'required' => true,
|
||||
'select_id' => 'assigned_assets_select',
|
||||
'asset_selector_div_id' => 'assets_for_maintenance_div',
|
||||
'asset_ids' => $item->id ? $item->asset()->pluck('id')->toArray() : old('selected_assets'),
|
||||
'asset_id' => $item->id ? $item->asset()->pluck('id')->toArray() : null
|
||||
])
|
||||
@else
|
||||
<!-- Start box component -->
|
||||
<x-box :$item header_icon="maintenances">
|
||||
|
||||
<!-- This is an existing maintenance -->
|
||||
@if ($item->id)
|
||||
|
||||
@if ($item->asset)
|
||||
<x-form-row
|
||||
:label="trans('general.asset')"
|
||||
:$item
|
||||
name="asset"
|
||||
type="static"
|
||||
:static_value="$item->asset->display_name"
|
||||
/>
|
||||
<x-form-row :label="trans('general.asset')" name="asset">
|
||||
{{ $item->asset->display_name }}
|
||||
</x-form-row>
|
||||
|
||||
@if ($item->asset->company)
|
||||
<x-form-row
|
||||
:label="trans('general.company')"
|
||||
:$item
|
||||
name="company"
|
||||
type="static"
|
||||
:static_value="$item->asset->company->name"
|
||||
/>
|
||||
@endif
|
||||
@if ($item->asset->company)
|
||||
<x-form-row :label="trans('general.company')" name="company">
|
||||
{{ $item->asset->company->display_name }}
|
||||
</x-form-row>
|
||||
|
||||
@endif
|
||||
|
||||
|
||||
@if ($item->asset->location)
|
||||
<x-form-row
|
||||
:label="trans('general.location')"
|
||||
:$item
|
||||
name="location"
|
||||
type="static"
|
||||
:static_value="$item->asset->location"
|
||||
/>
|
||||
@endif
|
||||
@if ($item->asset->location)
|
||||
<x-form-row :label="trans('general.location')" name="location">
|
||||
{{ $item->asset->location->display_name }}
|
||||
</x-form-row>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@endif
|
||||
|
||||
<!-- Name -->
|
||||
<x-form-row
|
||||
:label="trans('general.name')"
|
||||
:$item
|
||||
name="name"
|
||||
/>
|
||||
|
||||
|
||||
@if (!$item->id)
|
||||
<x-form-row
|
||||
:$item
|
||||
:data_placeholder="trans('general.select_asset')"
|
||||
:label="trans('general.assets')"
|
||||
:selected="$item->id ? $item->asset()->pluck('id')->toArray() : old('selected_assets')"
|
||||
data_endpoint="hardware"
|
||||
input_class="js-data-ajax select2"
|
||||
name="selected_assets[]"
|
||||
required="true"
|
||||
type="select2-ajax"
|
||||
multiple="true"
|
||||
/>
|
||||
@endif
|
||||
|
||||
|
||||
<x-form-row
|
||||
@@ -132,7 +121,18 @@
|
||||
placeholder="https://example.com"
|
||||
/>
|
||||
|
||||
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
|
||||
<x-form-row
|
||||
:$item
|
||||
:data_placeholder="trans('general.select_supplier')"
|
||||
:label="trans('general.supplier')"
|
||||
:selected="$item->id ? $item->supplier()->pluck('id')->toArray() : old('suppliers')"
|
||||
data_endpoint="suppliers"
|
||||
input_div_class="col-md-7"
|
||||
input_class="js-data-ajax select2"
|
||||
name="supplier_id"
|
||||
type="select2-ajax"
|
||||
show_create_new="supplier"
|
||||
/>
|
||||
|
||||
|
||||
<!-- Warranty -->
|
||||
@@ -147,7 +147,6 @@
|
||||
|
||||
|
||||
<!-- Asset Maintenance Cost -->
|
||||
<!-- Purchase Cost -->
|
||||
<x-form-row
|
||||
:label="trans('admin/maintenances/form.cost')"
|
||||
:$item
|
||||
@@ -176,6 +175,10 @@
|
||||
/>
|
||||
|
||||
|
||||
<!-- End box component -->
|
||||
</x-box>
|
||||
<!-- Start form component -->
|
||||
</x-form>
|
||||
|
||||
</div>
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user