mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 05:47:28 -08:00
Get some basic Livewire going for 'edit model's default values.
This commit is contained in:
parent
8e66abb926
commit
ea1f1eb972
44
app/Http/Livewire/CustomFieldSetDefaultValuesForModel.php
Normal file
44
app/Http/Livewire/CustomFieldSetDefaultValuesForModel.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
use App\Models\CustomFieldset;
|
||||
use App\Models\AssetModel;
|
||||
|
||||
class CustomFieldSetDefaultValuesForModel extends Component
|
||||
{
|
||||
public $add_default_values;
|
||||
|
||||
public $fieldset_id;
|
||||
public $fields;
|
||||
public $model_id;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
\Log::info("INSTANTIATING A THING!!!"); // WORKS!
|
||||
}
|
||||
|
||||
public function foo()
|
||||
{
|
||||
\Log::info("Uh, foo?");
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->fieldset_id = AssetModel::find($this->model_id)->fieldset_id;
|
||||
\Log::error("Mount at least fired, that's got to count for something, yeah?"); //WORKS! YAY!
|
||||
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
// return 'fart<div>Hi: {{ $this->add_default_values }} yeah?</div>';
|
||||
if($this->fieldset_id) {
|
||||
$this->fields = CustomFieldset::find($this->fieldset_id)->fields()->get();
|
||||
}
|
||||
return view('livewire.custom-field-set-default-values-for-model');
|
||||
}
|
||||
}
|
14
public/vendor/livewire/livewire.js
vendored
Normal file
14
public/vendor/livewire/livewire.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
public/vendor/livewire/livewire.js.map
vendored
Normal file
1
public/vendor/livewire/livewire.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
1
public/vendor/livewire/manifest.json
vendored
Normal file
1
public/vendor/livewire/manifest.json
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"/livewire.js":"/livewire.js?id=25f025805c3c370f7e87"}
|
|
@ -80,6 +80,7 @@
|
|||
<script src="{{ url(asset('js/html5shiv.js')) }}" nonce="{{ csrf_token() }}"></script>
|
||||
<script src="{{ url(asset('js/respond.js')) }}" nonce="{{ csrf_token() }}"></script>
|
||||
|
||||
@livewireStyles
|
||||
|
||||
</head>
|
||||
|
||||
|
@ -926,6 +927,6 @@
|
|||
@endif
|
||||
|
||||
|
||||
|
||||
@livewireScripts
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<div>
|
||||
<div class="form-group {{ $errors->has('custom_fieldset') ? ' has-error' : '' }}">
|
||||
<label for="custom_fieldset" class="col-md-3 control-label">{{ trans('admin/models/general.fieldset') }}</label>
|
||||
<div class="col-md-7">
|
||||
{{ Form::select('custom_fieldset', \App\Helpers\Helper::customFieldsetList(),old('custom_fieldset', 0000 /*$item->fieldset_id*/), array('class'=>'select2 js-fieldset-field', 'style'=>'width:350px', 'aria-label'=>'custom_fieldset', 'wire:model' => 'fieldset_id')) }}
|
||||
{!! $errors->first('custom_fieldset', '<span class="alert-msg" aria-hidden="true"><br><i class="fa fa-times"></i> :message</span>') !!}
|
||||
<label class="m-l-xs">
|
||||
{{-- {{ Form::checkbox('add_default_values', 1, Request::old('add_default_values'), ['class' => 'js-default-values-toggler']) }} --}}
|
||||
{{-- I'm not sure that *this* checkboxy thing will render right, because of things. It's not *in* its own view, right? So that's a problem --}}
|
||||
<input wire:click="foo" wire:model="add_default_values" type='checkbox' name='add_default_values' value='1' class='js-default-values-toggler'{{ Request::old('add_default_values')? " checked='checked'" : "" }} />
|
||||
{{ trans('admin/models/general.add_default_values') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@if($this->add_default_values) {{-- 'if the checkbox is enabled *AND* there are more than 0 fields in the fieldsset' --}}
|
||||
<div>
|
||||
<div class="form-group">
|
||||
<fieldset>
|
||||
<legend class="col-md-3 control-label">Default Values</legend>
|
||||
<div class="col-sm-8 col-xl-7">
|
||||
@empty($fields) {{-- There was an error? --}}
|
||||
<p>
|
||||
There was a problem retrieving the fields for this fieldset.
|
||||
</p>
|
||||
@else
|
||||
{{-- NOTE: This stuff could work well also for the 'view this asset and do its custom fields' thing --}}
|
||||
@foreach($fields as $field)
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-lg-6">
|
||||
<label class="control-label" for="default-value{{ $field->id }}">{{ $field->name }}</label>
|
||||
</div>
|
||||
<div class="col-sm-12 col-lg-6">
|
||||
@if($field->element == "text")
|
||||
<input b-if="field.type == 'text'" class="form-control m-b-xs" type="text" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'">
|
||||
@elseif($field->element == "textarea")
|
||||
<textarea x-if="field.type == 'textarea'" class="form-control" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'"></textarea><br>
|
||||
@elseif($field->element == "listbox")
|
||||
|
||||
<select Z-if="field.element == 'listbox'" class="form-control m-b-xs" :name="'default_values[' + field.id + ']'">
|
||||
<option value=""></option>
|
||||
@foreach($field->field_values as $field_value)
|
||||
<option Q-for="field_value in field.field_values_array" :value="field_value" :selected="getValue(field) == field_value">{{ $field_value }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@else
|
||||
Unknonown field element: {{ $field->element }}
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@endif
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
|
@ -34,24 +34,28 @@
|
|||
</div>
|
||||
|
||||
<!-- Custom Fieldset -->
|
||||
<div id="app">
|
||||
<div class="form-group {{ $errors->has('custom_fieldset') ? ' has-error' : '' }}">
|
||||
<div>
|
||||
{{-- <div class="form-group {{ $errors->has('custom_fieldset') ? ' has-error' : '' }}">
|
||||
<label for="custom_fieldset" class="col-md-3 control-label">{{ trans('admin/models/general.fieldset') }}</label>
|
||||
<div class="col-md-7">
|
||||
{{ Form::select('custom_fieldset', \App\Helpers\Helper::customFieldsetList(),old('custom_fieldset', $item->fieldset_id), array('class'=>'select2 js-fieldset-field', 'style'=>'width:350px', 'aria-label'=>'custom_fieldset')) }}
|
||||
{!! $errors->first('custom_fieldset', '<span class="alert-msg" aria-hidden="true"><br><i class="fa fa-times"></i> :message</span>') !!}
|
||||
<label class="m-l-xs">
|
||||
{{ Form::checkbox('add_default_values', 1, Request::old('add_default_values'), ['class' => 'js-default-values-toggler']) }}
|
||||
{{-- {{ Form::checkbox('add_default_values', 1, Request::old('add_default_values'), ['class' => 'js-default-values-toggler']) }} --}}
|
||||
{{-- I'm not sure that *this* checkboxy thing will render right, because of things. It's not *in* its own view, right? So that's a problem --}}
|
||||
{{-- <input wire:click="foo" wire:model="add_default_values" type='checkbox' name='add_default_values' value='1' class='js-default-values-toggler'{{ Request::old('add_default_values')? " checked='checked'" : "" }} />
|
||||
{{ trans('admin/models/general.add_default_values') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div> --}}
|
||||
|
||||
<fieldset-default-values
|
||||
{{-- <fieldset-default-values
|
||||
model-id="{{ $item->id ?: '' }}"
|
||||
fieldset-id="{{ !empty($item->fieldset) ? $item->fieldset->id : Request::old('custom_fieldset') }}"
|
||||
previous-input="{{ json_encode(Request::old('default_values')) }}">
|
||||
</fieldset-default-values>
|
||||
</fieldset-default-values> --}}
|
||||
@livewire('custom-field-set-default-values-for-model',["model_id" => $item->id])
|
||||
|
||||
</div>
|
||||
|
||||
@include ('partials.forms.edit.notes')
|
||||
|
|
Loading…
Reference in a new issue