mirror of
https://github.com/snipe/snipe-it.git
synced 2024-09-19 23:37:38 -07:00
Wiring up custom fields for users - still some big UI challenges tho
This commit is contained in:
parent
4f182c0a50
commit
636da2ab5e
|
@ -372,7 +372,9 @@ class UsersController extends Controller
|
|||
$user->password = bcrypt($request->get('password', $tmp_pass));
|
||||
|
||||
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
|
||||
|
||||
|
||||
$user->customFill($request,Auth::user());
|
||||
|
||||
if ($user->save()) {
|
||||
if ($request->filled('groups')) {
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
|
@ -463,7 +465,9 @@ class UsersController extends Controller
|
|||
|
||||
|
||||
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
|
||||
|
||||
|
||||
$user->customFill($request,Auth::user());
|
||||
|
||||
if ($user->save()) {
|
||||
|
||||
// Sync group memberships:
|
||||
|
|
|
@ -133,6 +133,9 @@ class UsersController extends Controller
|
|||
// we have to invoke the
|
||||
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
|
||||
|
||||
\Log::info("About to call customFill, in the 'store' controller!!!");
|
||||
$user->customFill($request, Auth::user());
|
||||
|
||||
if ($user->save()) {
|
||||
if ($request->filled('groups')) {
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
|
@ -300,6 +303,8 @@ class UsersController extends Controller
|
|||
// Handle uploaded avatar
|
||||
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
|
||||
|
||||
\Log::debug("calling custom fill from the UPDATE method!");
|
||||
$user->customFill($request, Auth::user());
|
||||
//\Log::debug(print_r($user, true));
|
||||
|
||||
// Was the user updated?
|
||||
|
|
|
@ -42,7 +42,7 @@ trait HasCustomFields
|
|||
public function getFieldset(): ?CustomFieldset {
|
||||
$pivot = $this->getFieldsetKey();
|
||||
if(is_int($pivot)) { //why does this look just like the other thing? (below, look for is_int()
|
||||
return Fieldset::find($pivot);
|
||||
return CustomFieldset::find($pivot);
|
||||
}
|
||||
return $pivot->fieldset;
|
||||
}
|
||||
|
@ -113,7 +113,6 @@ trait HasCustomFields
|
|||
}
|
||||
|
||||
public function customFill(Request $request, User $user, bool $shouldSetDefaults = false) {
|
||||
$this->_filled = true;
|
||||
if ($this->getFieldset()) {
|
||||
foreach ($this->getFieldset()->fields as $field) {
|
||||
if (is_array($request->input($field->db_column))) {
|
||||
|
|
|
@ -75,20 +75,17 @@
|
|||
|
||||
<div id='custom_fields_content'>
|
||||
<!-- Custom Fields -->
|
||||
@if ($item->model && $item->model->fieldset)
|
||||
<?php $model = $item->model; ?>
|
||||
@endif
|
||||
@if (Request::old('model_id'))
|
||||
@php
|
||||
$model = \App\Models\AssetModel::find(old('model_id'));
|
||||
$item->model = \App\Models\AssetModel::find(old('model_id'));
|
||||
@endphp
|
||||
@elseif (isset($selected_model))
|
||||
@php
|
||||
$model = $selected_model;
|
||||
$item->model_id = $selected_model;
|
||||
@endphp
|
||||
@endif
|
||||
@if (isset($model) && $model)
|
||||
@include("models/custom_fields_form",["model" => $model])
|
||||
@if ($item->getFieldset())
|
||||
@include("models/custom_fields_form",["item" => $item])
|
||||
@endif
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,5 +1,28 @@
|
|||
@if (($model) && ($model->fieldset))
|
||||
@foreach($model->fieldset->fields AS $field)
|
||||
{{--
|
||||
|
||||
Okay, now how am I going to work *this* out. I think it's less bad than I think.
|
||||
|
||||
I think we can pass the $asset or the $user to this partial.
|
||||
|
||||
This partial can be aware of the HasCustomFields trait, and call getFieldset() to get the appropriate fieldset; that's good.
|
||||
|
||||
But we also need the 'discriminator' so that we can use defaultValuesForCustomFields, right?
|
||||
|
||||
Well, that should be easy enough, right? Just call getFieldsetKey(), right? Or maybe we don't even have to do that -
|
||||
|
||||
We can call $item->getDefaultValue($field), right?
|
||||
|
||||
So the old way - already on this page - is:
|
||||
|
||||
$item->defaultValue($field))
|
||||
|
||||
And we just do a simple 'replace' to make it be:
|
||||
|
||||
$item->defaultValue($field)
|
||||
--}}
|
||||
|
||||
@if ($item->getFieldset())
|
||||
@foreach($item->getFieldset()->fields AS $field)
|
||||
<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{{ ($field->pivot->required=='1') ? ' required' : '' }}">
|
||||
|
@ -12,14 +35,14 @@
|
|||
Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, htmlspecialchars($item->{$field->db_column_name()}, ENT_QUOTES)) : $field->defaultValue($model->id))), ['class'=>'format select2 form-control']) }}
|
||||
|
||||
@elseif ($field->element=='textarea')
|
||||
<textarea class="col-md-6 form-control" id="{{ $field->db_column_name() }}" name="{{ $field->db_column_name() }}">{{ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}</textarea>
|
||||
<textarea class="col-md-6 form-control" id="{{ $field->db_column_name() }}" name="{{ $field->db_column_name() }}">{{ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $item->defaultValue($field))) }}</textarea>
|
||||
|
||||
@elseif ($field->element=='checkbox')
|
||||
<!-- Checkboxes -->
|
||||
@foreach ($field->formatFieldValuesAsArray() as $key => $value)
|
||||
<div>
|
||||
<label class="form-control">
|
||||
<input type="checkbox" value="{{ $value }}" name="{{ $field->db_column_name() }}[]" {{ isset($item) ? (in_array($value, array_map('trim', explode(',', $item->{$field->db_column_name()}))) ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : (in_array($key, array_map('trim', explode(',', $field->defaultValue($model->id)))) ? ' checked="checked"' : '')) }}>
|
||||
<input type="checkbox" value="{{ $value }}" name="{{ $field->db_column_name() }}[]" {{ isset($item) ? (in_array($value, array_map('trim', explode(',', $item->{$field->db_column_name()}))) ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : (in_array($key, array_map('trim', explode(',', $item->defaultValue($field)))) ? ' checked="checked"' : '')) }}>
|
||||
{{ $value }}
|
||||
</label>
|
||||
</div>
|
||||
|
@ -30,7 +53,7 @@
|
|||
|
||||
<div>
|
||||
<label class="form-control">
|
||||
<input type="radio" value="{{ $value }}" name="{{ $field->db_column_name() }}" {{ isset($item) ? ($item->{$field->db_column_name()} == $value ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : (in_array($value, explode(', ', $field->defaultValue($model->id))) ? ' checked="checked"' : '')) }}>
|
||||
<input type="radio" value="{{ $value }}" name="{{ $field->db_column_name() }}" {{ isset($item) ? ($item->{$field->db_column_name()} == $value ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : (in_array($value, explode(', ', $item->defaultValue($field))) ? ' checked="checked"' : '')) }}>
|
||||
{{ $value }}
|
||||
</label>
|
||||
</div>
|
||||
|
@ -46,7 +69,7 @@
|
|||
|
||||
<div class="input-group col-md-5" style="padding-left: 0px;">
|
||||
<div class="input-group date" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-autoclose="true" data-date-clear-btn="true">
|
||||
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="{{ $field->db_column_name() }}" id="{{ $field->db_column_name() }}" readonly value="{{ old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}" style="background-color:inherit">
|
||||
<input type="text" class="form-control" placeholder="{{ trans('general.select_date') }}" name="{{ $field->db_column_name() }}" id="{{ $field->db_column_name() }}" readonly value="{{ old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $item->defaultValue($field))) }}" style="background-color:inherit">
|
||||
<span class="input-group-addon"><i class="fas fa-calendar" aria-hidden="true"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -54,7 +77,7 @@
|
|||
|
||||
@else
|
||||
@if (($field->field_encrypted=='0') || (Gate::allows('assets.view.encrypted_custom_fields')))
|
||||
<input type="text" value="{{ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}" id="{{ $field->db_column_name() }}" class="form-control" name="{{ $field->db_column_name() }}" placeholder="Enter {{ strtolower($field->format) }} text">
|
||||
<input type="text" value="{{ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $item->defaultValue($field))) }}" id="{{ $field->db_column_name() }}" class="form-control" name="{{ $field->db_column_name() }}" placeholder="Enter {{ strtolower($field->format) }} text">
|
||||
@else
|
||||
<input type="text" value="{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}" class="form-control disabled" disabled>
|
||||
@endif
|
||||
|
|
|
@ -279,6 +279,15 @@
|
|||
|
||||
@include ('partials.forms.edit.image-upload', ['fieldname' => 'avatar', 'image_path' => app('users_upload_path')])
|
||||
|
||||
{{-- FIXME - copypasta from hardware/edit.blade.php <start> --}}
|
||||
<div id='custom_fields_content'>
|
||||
<!-- Custom Fields -->
|
||||
@if ($user->getFieldset())
|
||||
@include("models/custom_fields_form",["item" => $user])
|
||||
@endif
|
||||
</div>
|
||||
{{-- FIXME - copypasts from hardware/edit.blade.php <end> --}}
|
||||
|
||||
|
||||
<!-- begin optional disclosure arrow stuff -->
|
||||
<div class="form-group">
|
||||
|
|
Loading…
Reference in a new issue