Skip to content

Commit 6f233bc

Browse files
committed
Get more of the select2 ajax lists working
1 parent 448f4b9 commit 6f233bc

File tree

3 files changed

+112
-12
lines changed

3 files changed

+112
-12
lines changed

resources/views/blade/form-input.blade.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
@aware(['name'])
22

33
@props([
4-
'class' => 'col-md-8',
4+
'class' => null,
5+
'new_model' => false,
6+
'category_type' => null,
7+
'modal_type' => false,
8+
'modal_id' => false,
59
])
610

711
<?php
@@ -12,33 +16,48 @@
1216
case 'qty':
1317
case 'min_amt':
1418
case 'seats':
15-
$class = 'col-md-3';
19+
$class_override = $new_model ? 'col-md-3' : 'col-md-4';
1620
break;
1721
case 'purchase_cost':
1822
case 'purchase_date':
1923
case 'termination_date':
2024
case 'expiration_date':
2125
case 'start_date':
2226
case 'end_date':
23-
$class = 'col-md-5';
27+
$class_override = $new_model ? 'col-md-4' : 'col-md-5';
2428
break;
2529
case 'model_number':
2630
case 'item_no':
2731
case 'order_number':
2832
case 'purchase_order':
29-
$class = 'col-md-6';
33+
$class_override = $new_model ? 'col-md-5' : 'col-md-6';
3034
break;
3135
default:
32-
$class = 'col-md-8';
36+
$class_override = $new_model ? 'col-md-7' : 'col-md-8';
3337
break;
3438
}
3539
40+
// Use the explicit override if one is set
41+
if ($class) {
42+
$class_override = $class;
43+
}
3644
?>
3745
<!-- form-input blade component -->
38-
<div {{ $attributes->merge(['class' => $class]) }}>
46+
<div {{ $attributes->merge(['class' => $class_override]) }}>
3947
{{ $slot }}
4048
</div>
4149

50+
@if ($new_model)
51+
<div class="col-md-1 col-sm-1">
52+
@can('create', $new_model)
53+
<a href='{{ route('modal.show',[
54+
'type' => $modal_type ?? null,
55+
'category_type' => $category_type ?? null
56+
]) }}' data-toggle="modal" data-target="#createModal" data-select="{{ $modal_id }}" class="btn btn-sm btn-primary text-left">{{ trans('button.new') }}</a>
57+
@endcan
58+
</div>
59+
@endif
60+
4261

4362
@error($name)
4463
<div class="col-md-8 col-md-offset-3">

resources/views/blade/input/select2-ajax.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'multiple' => false,
99
'item_model' => null,
1010
'name' => null,
11+
'new_button' => false,
1112
])
1213

1314
@if (!$selected)

resources/views/components/edit.blade.php

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,35 @@
1717
{{-- Page content --}}
1818
@section('inputFields')
1919

20-
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/components/table.title')])
21-
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'category_id','category_type' => 'component'])
20+
<!-- Name -->
21+
<x-form-row name="name">
22+
<x-form-label>{{ trans('general.name') }}</x-form-label>
23+
<x-form-input>
24+
<x-input.text
25+
required="true"
26+
:value="old('name', $item->name)"
27+
/>
28+
</x-form-input>
29+
</x-form-row>
30+
31+
32+
<!-- Category -->
33+
<x-form-row name="category_id">
34+
<x-form-label>{{ trans('general.category') }}</x-form-label>
35+
<x-form-input modal_type="category" modal_id="category_select_id" category_type="component" new_model="\App\Models\Category::class">
36+
<x-input.select2-ajax
37+
id="category_select_id"
38+
:data_placeholder="trans('general.select_asset')"
39+
:item="old('category_id', $item->category_id)"
40+
:new_button="true"
41+
:required="Helper::checkIfRequired($item, 'category_id')"
42+
:selected="old('category_id', $item->category_id)"
43+
data_endpoint="categories/component"
44+
item_model="\App\Models\Category"
45+
/>
46+
</x-form-input>
47+
</x-form-row>
48+
2249

2350
<!-- QTY -->
2451
<x-form-row name="qty">
@@ -49,15 +76,68 @@
4976
</x-form-row>
5077

5178
@include ('partials.forms.edit.serial', ['fieldname' => 'serial'])
52-
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id'])
79+
80+
<!-- Manufacturer -->
81+
<x-form-row name="manufacturer_id">
82+
<x-form-label>{{ trans('general.manufacturer') }}</x-form-label>
83+
<x-form-input modal_type="manufacturer" modal_id="manufacturer_select_id" new_model="\App\Models\Manufacturer::class">
84+
<x-input.select2-ajax
85+
id="manufacturer_select_id"
86+
:data_placeholder="trans('general.manufacturer')"
87+
:item="old('manufacturer_id', $item->manufacturer_id)"
88+
:new_button="true"
89+
:required="Helper::checkIfRequired($item, 'manufacturer_id')"
90+
:selected="old('manufacturer_id', $item->manufacturer_id)"
91+
data_endpoint="manufacturers"
92+
item_model="\App\Models\Manufacturer"
93+
/>
94+
</x-form-input>
95+
</x-form-row>
96+
5397
@include ('partials.forms.edit.model_number')
5498
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
5599
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id'])
56100
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
57101
@include ('partials.forms.edit.order_number')
58-
@include ('partials.forms.edit.datepicker', ['translated_name' => trans('general.purchase_date'),'fieldname' => 'purchase_date'])
59-
@include ('partials.forms.edit.purchase_cost', ['unit_cost' => trans('general.unit_cost')])
60-
@include ('partials.forms.edit.notes')
102+
103+
<!--- Purchase Date -->
104+
<x-form-row name="purchase_date">
105+
<x-form-label>{{ trans('general.purchase_date') }}</x-form-label>
106+
<x-form-input>
107+
<x-input.datepicker :value="old('purchase_date', $item->purchase_date_for_datepicker)" />
108+
</x-form-input>
109+
</x-form-row>
110+
111+
112+
<!-- Purchase Cost -->
113+
<x-form-row name="purchase_cost">
114+
<x-form-label>{{ trans('general.unit_cost') }}</x-form-label>
115+
<x-form-input>
116+
<x-input.text
117+
type="number"
118+
:input_group_text="$snipeSettings->default_currency"
119+
:value="old('purchase_cost', $item->purchase_cost)"
120+
input_group_addon="left"
121+
input_max="99999999999999999.000"
122+
input_min="0"
123+
input_min="0.00"
124+
input_step="0.001"
125+
maxlength="25"
126+
/>
127+
</x-form-input>
128+
</x-form-row>
129+
130+
<!-- Notes -->
131+
<x-form-row name="notes">
132+
<x-form-label>{{ trans('general.notes') }}</x-form-label>
133+
<x-form-input>
134+
<x-input.textarea
135+
:value="old('notes', $item->notes)"
136+
placeholder="{{ trans('general.placeholders.notes') }}"
137+
/>
138+
</x-form-input>
139+
</x-form-row>
140+
61141
@include ('partials.forms.edit.image-upload', ['image_path' => app('components_upload_path')])
62142

63143

0 commit comments

Comments
 (0)