mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Fixed #7987 - allow toggle of required/optional in custom fields/fieldsets
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
154db9a416
commit
5bb4f271aa
|
@ -194,4 +194,44 @@ class CustomFieldsetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the field in a fieldset to required
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v5.0]
|
||||||
|
*/
|
||||||
|
public function makeFieldRequired($fieldset_id, $field_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->authorize('update', CustomFieldset::class);
|
||||||
|
$field = CustomField::findOrFail($field_id);
|
||||||
|
$fieldset = CustomFieldset::findOrFail($fieldset_id);
|
||||||
|
$fields[$field->id] = ['required' => 1];
|
||||||
|
$fieldset->fields()->syncWithoutDetaching($fields);
|
||||||
|
|
||||||
|
return redirect()->route('fieldsets.show', ['fieldset' => $fieldset_id])
|
||||||
|
->with("success", trans('Field successfully set to required'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the field in a fieldset to optional
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @since [v5.0]
|
||||||
|
*/
|
||||||
|
public function makeFieldOptional($fieldset_id, $field_id)
|
||||||
|
{
|
||||||
|
$this->authorize('update', CustomFieldset::class);
|
||||||
|
$field = CustomField::findOrFail($field_id);
|
||||||
|
$fieldset = CustomFieldset::findOrFail($fieldset_id);
|
||||||
|
$fields[$field->id] = ['required' => 0];
|
||||||
|
$fieldset->fields()->syncWithoutDetaching($fields);
|
||||||
|
|
||||||
|
return redirect()->route('fieldsets.show', ['fieldset' => $fieldset_id])
|
||||||
|
->with("success", trans('Field successfully set to optional'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,19 @@
|
||||||
<td>{{$field->format}}</td>
|
<td>{{$field->format}}</td>
|
||||||
<td>{{$field->element}}</td>
|
<td>{{$field->element}}</td>
|
||||||
<td>{{ $field->field_encrypted=='1' ? trans('general.yes') : trans('general.no') }}</td>
|
<td>{{ $field->field_encrypted=='1' ? trans('general.yes') : trans('general.no') }}</td>
|
||||||
<td>{{$field->pivot->required ? "REQUIRED" : "OPTIONAL"}}</td>
|
<td>
|
||||||
|
@if ($field->pivot->required)
|
||||||
|
<a href="{{ route('fields.optional', [$custom_fieldset->id, $field->id]) }}">
|
||||||
|
<i class="fa fa-check text-success" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">Required - click to make optional</span>
|
||||||
|
</a>
|
||||||
|
@else
|
||||||
|
<a href="{{ route('fields.required', [$custom_fieldset->id, $field->id]) }}">
|
||||||
|
<i class="fa fa-times text-danger" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">Optional - click to make required</span>
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@can('update', $custom_fieldset)
|
@can('update', $custom_fieldset)
|
||||||
<a href="{{ route('fields.disassociate', [$field,$custom_fieldset->id]) }}" class="btn btn-sm btn-danger">Remove</a>
|
<a href="{{ route('fields.disassociate', [$field,$custom_fieldset->id]) }}" class="btn btn-sm btn-danger">Remove</a>
|
||||||
|
|
|
@ -7,6 +7,16 @@
|
||||||
|
|
||||||
Route::group([ 'prefix' => 'fields','middleware' => ['auth'] ], function () {
|
Route::group([ 'prefix' => 'fields','middleware' => ['auth'] ], function () {
|
||||||
|
|
||||||
|
Route::get('required/{fieldset_id}/{field_id}',
|
||||||
|
['uses' => 'CustomFieldsetsController@makeFieldRequired',
|
||||||
|
'as' => 'fields.required']
|
||||||
|
);
|
||||||
|
|
||||||
|
Route::get('optional/{fieldset_id}/{field_id}',
|
||||||
|
['uses' => 'CustomFieldsetsController@makeFieldOptional',
|
||||||
|
'as' => 'fields.optional']
|
||||||
|
);
|
||||||
|
|
||||||
Route::get('{field_id}/fieldset/{fieldset_id}/disassociate',
|
Route::get('{field_id}/fieldset/{fieldset_id}/disassociate',
|
||||||
['uses' => 'CustomFieldsController@deleteFieldFromFieldset',
|
['uses' => 'CustomFieldsController@deleteFieldFromFieldset',
|
||||||
'as' => 'fields.disassociate']
|
'as' => 'fields.disassociate']
|
||||||
|
|
Loading…
Reference in a new issue