mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #12916 from snipe/features/auto_add_to_fieldset
Added ability to auto-add fields to new fieldsets
This commit is contained in:
commit
b716f9f55e
|
@ -94,6 +94,18 @@ class CustomFieldsetsController extends Controller
|
|||
$fieldset->fill($request->all());
|
||||
|
||||
if ($fieldset->save()) {
|
||||
// Sync fieldset with auto_add_to_fieldsets
|
||||
$fields = CustomField::select('id')->where('auto_add_to_fieldsets', '=', '1')->get();
|
||||
|
||||
if ($fields->count() > 0) {
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$field_ids[] = $field->id;
|
||||
}
|
||||
|
||||
$fieldset->fields()->sync($field_ids);
|
||||
}
|
||||
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.create.success')));
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Http\Requests\CustomFieldRequest;
|
|||
use App\Models\CustomField;
|
||||
use App\Models\CustomFieldset;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Redirect;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +46,7 @@ class CustomFieldsController extends Controller
|
|||
* @see CustomFieldsController::storeField()
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v5.1.5]
|
||||
* @return Redirect
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function show()
|
||||
|
@ -63,14 +64,17 @@ class CustomFieldsController extends Controller
|
|||
* @return \Illuminate\Support\Facades\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function create()
|
||||
public function create(Request $request)
|
||||
{
|
||||
$this->authorize('create', CustomField::class);
|
||||
$fieldsets = CustomFieldset::get();
|
||||
|
||||
return view('custom_fields.fields.edit', [
|
||||
'predefinedFormats' => Helper::predefined_formats(),
|
||||
'customFormat' => '',
|
||||
])->with('field', new CustomField());
|
||||
'customFormat' => '',
|
||||
'fieldsets' => $fieldsets,
|
||||
'field' => new CustomField(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +83,7 @@ class CustomFieldsController extends Controller
|
|||
* @see CustomFieldsController::createField()
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v1.8]
|
||||
* @return Redirect
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function store(CustomFieldRequest $request)
|
||||
|
@ -104,6 +108,7 @@ class CustomFieldsController extends Controller
|
|||
"show_in_email" => $show_in_email,
|
||||
"is_unique" => $request->get("is_unique", 0),
|
||||
"display_in_user_view" => $display_in_user_view,
|
||||
"auto_add_to_fieldsets" => $request->get("auto_add_to_fieldsets", 0),
|
||||
"user_id" => Auth::id()
|
||||
]);
|
||||
|
||||
|
@ -115,10 +120,20 @@ class CustomFieldsController extends Controller
|
|||
}
|
||||
|
||||
if ($field->save()) {
|
||||
|
||||
// Sync fields with fieldsets
|
||||
$fieldset_array = $request->input('associate_fieldsets');
|
||||
if ($request->has('associate_fieldsets') && (is_array($fieldset_array))) {
|
||||
$field->fieldset()->sync(array_keys($fieldset_array));
|
||||
} else {
|
||||
$field->fieldset()->sync([]);
|
||||
}
|
||||
|
||||
|
||||
return redirect()->route('fields.index')->with('success', trans('admin/custom_fields/message.field.create.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()
|
||||
return redirect()->back()->with('selected_fieldsets', $request->input('associate_fieldsets'))->withInput()
|
||||
->with('error', trans('admin/custom_fields/message.field.create.error'));
|
||||
}
|
||||
|
||||
|
@ -128,7 +143,7 @@ class CustomFieldsController extends Controller
|
|||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @return Redirect
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function deleteFieldFromFieldset($field_id, $fieldset_id)
|
||||
|
@ -147,8 +162,7 @@ class CustomFieldsController extends Controller
|
|||
->with('success', trans('admin/custom_fields/message.field.delete.success'));
|
||||
} else {
|
||||
return redirect()->back()->withErrors(['message' => "Field is in use and cannot be deleted."]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->back()->withErrors(['message' => "Error deleting field from fieldset"]);
|
||||
|
@ -161,7 +175,7 @@ class CustomFieldsController extends Controller
|
|||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v1.8]
|
||||
* @return Redirect
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function destroy($field_id)
|
||||
|
@ -190,12 +204,12 @@ class CustomFieldsController extends Controller
|
|||
* @return \Illuminate\Support\Facades\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
if ($field = CustomField::find($id)) {
|
||||
|
||||
$this->authorize('update', $field);
|
||||
|
||||
$fieldsets = CustomFieldset::get();
|
||||
$customFormat = '';
|
||||
if ((stripos($field->format, 'regex') === 0) && ($field->format !== CustomField::PREDEFINED_FORMATS['MAC'])) {
|
||||
$customFormat = $field->format;
|
||||
|
@ -204,6 +218,7 @@ class CustomFieldsController extends Controller
|
|||
return view('custom_fields.fields.edit', [
|
||||
'field' => $field,
|
||||
'customFormat' => $customFormat,
|
||||
'fieldsets' => $fieldsets,
|
||||
'predefinedFormats' => Helper::predefined_formats(),
|
||||
]);
|
||||
}
|
||||
|
@ -222,7 +237,7 @@ class CustomFieldsController extends Controller
|
|||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @param int $id
|
||||
* @since [v4.0]
|
||||
* @return Redirect
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(CustomFieldRequest $request, $id)
|
||||
|
@ -249,6 +264,7 @@ class CustomFieldsController extends Controller
|
|||
$field->show_in_email = $show_in_email;
|
||||
$field->is_unique = $request->get("is_unique", 0);
|
||||
$field->display_in_user_view = $display_in_user_view;
|
||||
$field->auto_add_to_fieldsets = $request->get("auto_add_to_fieldsets", 0);
|
||||
|
||||
if ($request->get('format') == 'CUSTOM REGEX') {
|
||||
$field->format = e($request->get('custom_format'));
|
||||
|
@ -256,11 +272,21 @@ class CustomFieldsController extends Controller
|
|||
$field->format = e($request->get('format'));
|
||||
}
|
||||
|
||||
if($field->element == 'checkbox' || $field->element == 'radio'){
|
||||
if ($field->element == 'checkbox' || $field->element == 'radio'){
|
||||
$field->format = 'ANY';
|
||||
}
|
||||
|
||||
if ($field->save()) {
|
||||
|
||||
|
||||
// Sync fields with fieldsets
|
||||
$fieldset_array = $request->input('associate_fieldsets');
|
||||
if ($request->has('associate_fieldsets') && (is_array($fieldset_array))) {
|
||||
$field->fieldset()->sync(array_keys($fieldset_array));
|
||||
} else {
|
||||
$field->fieldset()->sync([]);
|
||||
}
|
||||
|
||||
return redirect()->route('fields.index')->with('success', trans('admin/custom_fields/message.field.update.success'));
|
||||
}
|
||||
|
||||
|
|
|
@ -93,16 +93,27 @@ class CustomFieldsetsController extends Controller
|
|||
{
|
||||
$this->authorize('create', CustomField::class);
|
||||
|
||||
$cfset = new CustomFieldset([
|
||||
$fieldset = new CustomFieldset([
|
||||
'name' => e($request->get('name')),
|
||||
'user_id' => Auth::user()->id,
|
||||
]);
|
||||
|
||||
$validator = Validator::make($request->all(), $cfset->rules);
|
||||
if ($validator->passes()) {
|
||||
$cfset->save();
|
||||
$validator = Validator::make($request->all(), $fieldset->rules);
|
||||
|
||||
return redirect()->route('fieldsets.show', [$cfset->id])
|
||||
if ($validator->passes()) {
|
||||
$fieldset->save();
|
||||
|
||||
// Sync fieldset with auto_add_to_fieldsets
|
||||
$fields = CustomField::select('id')->where('auto_add_to_fieldsets', '=', '1')->get();
|
||||
if ($fields->count() > 0) {
|
||||
foreach ($fields as $field) {
|
||||
$field_ids[] = $field->id;
|
||||
}
|
||||
|
||||
$fieldset->fields()->sync($field_ids);
|
||||
}
|
||||
|
||||
return redirect()->route('fieldsets.show', [$fieldset->id])
|
||||
->with('success', trans('admin/custom_fields/message.fieldset.create.success'));
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ class CustomFieldRequest extends FormRequest
|
|||
{
|
||||
$rules = [];
|
||||
|
||||
$rules['associate_fieldsets.*'] = 'nullable|integer|exists:custom_fieldsets,id';
|
||||
|
||||
switch ($this->method()) {
|
||||
|
||||
// Brand new
|
||||
|
@ -54,4 +56,11 @@ class CustomFieldRequest extends FormRequest
|
|||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'associate_fieldsets.*.exists' => trans('admin/custom_fields/message/does_not_exist'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class CustomFieldsTransformer
|
|||
'type' => e($field->element),
|
||||
'required' => (($field->pivot) && ($field->pivot->required=='1')) ? true : false,
|
||||
'display_in_user_view' => ($field->display_in_user_view =='1') ? true : false,
|
||||
'auto_add_to_fieldsets' => ($field->auto_add_to_fieldsets == '1') ? true : false,
|
||||
'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'),
|
||||
];
|
||||
|
|
|
@ -52,6 +52,7 @@ class CustomField extends Model
|
|||
'name' => 'required|unique:custom_fields',
|
||||
'element' => 'required|in:text,listbox,textarea,checkbox,radio',
|
||||
'field_encrypted' => 'nullable|boolean',
|
||||
'auto_add_to_fieldsets' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -69,6 +70,8 @@ class CustomField extends Model
|
|||
'show_in_email',
|
||||
'is_unique',
|
||||
'display_in_user_view',
|
||||
'auto_add_to_fieldsets',
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,7 @@ class CustomFieldFactory extends Factory
|
|||
'name' => $this->faker->catchPhrase(),
|
||||
'format' => '',
|
||||
'element' => 'text',
|
||||
'auto_add_to_fieldsets' => '0',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddAutoaddToCustomfields extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('custom_fields', function (Blueprint $table) {
|
||||
$table->boolean('auto_add_to_fieldsets')->nullable()->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('custom_fields', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('custom_fields', 'auto_add_to_fieldsets')) {
|
||||
$table->dropColumn('auto_add_to_fieldsets');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -49,4 +49,6 @@ return [
|
|||
'unique' => 'Unique',
|
||||
'display_in_user_view' => 'Allow the checked out user to view these values in their View Assigned Assets page',
|
||||
'display_in_user_view_table' => 'Visible to User',
|
||||
'auto_add_to_fieldsets' => 'Automatically add this to every new fieldset',
|
||||
'add_to_preexisting_fieldsets' => 'Add to any existing fieldsets',
|
||||
];
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
@php
|
||||
use App\Models\CustomField;
|
||||
@endphp
|
||||
@extends('layouts/default', [
|
||||
'helpText' => trans('admin/custom_fields/general.about_fieldsets_text'),
|
||||
'helpPosition' => 'right',
|
||||
])
|
||||
|
||||
@extends('layouts/default')
|
||||
|
||||
{{-- Page title --}}
|
||||
@section('title')
|
||||
|
@ -21,24 +21,31 @@
|
|||
{{-- Page content --}}
|
||||
@section('content')
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<!-- Horizontal Form -->
|
||||
@if ($field->id)
|
||||
{{ Form::open(['route' => ['fields.update', $field->id], 'class'=>'form-horizontal']) }}
|
||||
{{ method_field('PUT') }}
|
||||
@else
|
||||
{{ Form::open(['route' => 'fields.store', 'class'=>'form-horizontal']) }}
|
||||
@endif
|
||||
@if ($field->id)
|
||||
{{ Form::open(['route' => ['fields.update', $field->id], 'class'=>'form-horizontal']) }}
|
||||
{{ method_field('PUT') }}
|
||||
@else
|
||||
{{ Form::open(['route' => 'fields.store', 'class'=>'form-horizontal']) }}
|
||||
@endif
|
||||
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border text-right">
|
||||
<button type="submit" class="btn btn-primary"> {{ trans('general.save') }}</button>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
|
||||
<div class="col-md-8">
|
||||
|
||||
<!-- Name -->
|
||||
<div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
|
||||
<label for="name" class="col-md-4 control-label">
|
||||
<label for="name" class="col-md-3 control-label">
|
||||
{{ trans('admin/custom_fields/general.field_name') }}
|
||||
</label>
|
||||
<div class="col-md-6 required">
|
||||
<div class="col-md-8 required">
|
||||
{{ Form::text('name', old('name', $field->name), array('class' => 'form-control', 'aria-label'=>'name')) }}
|
||||
{!! $errors->first('name', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
</div>
|
||||
|
@ -46,10 +53,10 @@
|
|||
|
||||
<!-- Element Type -->
|
||||
<div class="form-group {{ $errors->has('element') ? ' has-error' : '' }}">
|
||||
<label for="element" class="col-md-4 control-label">
|
||||
<label for="element" class="col-md-3 control-label">
|
||||
{{ trans('admin/custom_fields/general.field_element') }}
|
||||
</label>
|
||||
<div class="col-md-6 required">
|
||||
<div class="col-md-8 required">
|
||||
|
||||
{!! Form::customfield_elements('element', old('element', $field->element), 'field_element select2 form-control') !!}
|
||||
{!! $errors->first('element', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
|
@ -59,10 +66,10 @@
|
|||
|
||||
<!-- Element values -->
|
||||
<div class="form-group {{ $errors->has('field_values') ? ' has-error' : '' }}" id="field_values_text" style="display:none;">
|
||||
<label for="field_values" class="col-md-4 control-label">
|
||||
<label for="field_values" class="col-md-3 control-label">
|
||||
{{ trans('admin/custom_fields/general.field_values') }}
|
||||
</label>
|
||||
<div class="col-md-6 required">
|
||||
<div class="col-md-8 required">
|
||||
{!! Form::textarea('field_values', old('name', $field->field_values), ['style' => 'width: 100%', 'rows' => 4, 'class' => 'form-control', 'aria-label'=>'field_values']) !!}
|
||||
{!! $errors->first('field_values', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
<p class="help-block">{{ trans('admin/custom_fields/general.field_values_help') }}</p>
|
||||
|
@ -71,7 +78,7 @@
|
|||
|
||||
<!-- Format -->
|
||||
<div class="form-group {{ $errors->has('format') ? ' has-error' : '' }}" id="format_values">
|
||||
<label for="format" class="col-md-4 control-label">
|
||||
<label for="format" class="col-md-3 control-label">
|
||||
{{ trans('admin/custom_fields/general.field_format') }}
|
||||
</label>
|
||||
@php
|
||||
|
@ -80,17 +87,17 @@
|
|||
$field_format = 'CUSTOM REGEX';
|
||||
}
|
||||
@endphp
|
||||
<div class="col-md-6 required">
|
||||
<div class="col-md-8 required">
|
||||
{{ Form::select("format",Helper::predefined_formats(), ($field_format == '') ? $field->format : $field_format, array('class'=>'format select2 form-control', 'aria-label'=>'format')) }}
|
||||
{!! $errors->first('format', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
<!-- Custom Format -->
|
||||
<div class="form-group {{ $errors->has('custom_format') ? ' has-error' : '' }}" id="custom_regex" style="display:none;">
|
||||
<label for="custom_format" class="col-md-4 control-label">
|
||||
<label for="custom_format" class="col-md-3 control-label">
|
||||
{{ trans('admin/custom_fields/general.field_custom_format') }}
|
||||
</label>
|
||||
<div class="col-md-6 required">
|
||||
<div class="col-md-8 required">
|
||||
{{ Form::text('custom_format', old('custom_format', (($field->format!='') && (stripos($field->format,'regex')===0)) ? $field->format : ''), array('class' => 'form-control', 'id' => 'custom_format','aria-label'=>'custom_format', 'placeholder'=>'regex:/^[0-9]{15}$/')) }}
|
||||
<p class="help-block">{!! trans('admin/custom_fields/general.field_custom_format_help') !!}</p>
|
||||
|
||||
|
@ -101,68 +108,111 @@
|
|||
|
||||
<!-- Help Text -->
|
||||
<div class="form-group {{ $errors->has('help_text') ? ' has-error' : '' }}">
|
||||
<label for="help_text" class="col-md-4 control-label">
|
||||
<label for="help_text" class="col-md-3 control-label">
|
||||
{{ trans('admin/custom_fields/general.help_text') }}
|
||||
</label>
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-8">
|
||||
{{ Form::text('help_text', old('help_text', $field->help_text), array('class' => 'form-control', 'aria-label'=>'help_text')) }}
|
||||
<p class="help-block">{{ trans('admin/custom_fields/general.help_text_description') }}</p>
|
||||
{!! $errors->first('help_text', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!$field->id)
|
||||
<!-- Auto-Add to Future Fieldsets -->
|
||||
<div class="form-group {{ $errors->has('auto_add_to_fieldsets') ? ' has-error' : '' }}" id="auto_add_to_fieldsets">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" name="auto_add_to_fieldsets" aria-label="auto_add_to_fieldsets" value="1"{{ (old('auto_add_to_fieldsets') || $field->auto_add_to_fieldsets) ? ' checked="checked"' : '' }}>
|
||||
{{ trans('admin/custom_fields/general.auto_add_to_fieldsets') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@if (!$field->id)
|
||||
<!-- Encrypted -->
|
||||
<div class="form-group {{ $errors->has('encrypted') ? ' has-error' : '' }}">
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" value="1" name="field_encrypted" id="field_encrypted"{{ (Request::old('field_encrypted') || $field->field_encrypted) ? ' checked="checked"' : '' }}>
|
||||
{{ trans('admin/custom_fields/general.encrypt_field') }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-md-6 col-md-offset-4" id="encrypt_warning" style="display:none;">
|
||||
|
||||
<div class="col-md-9 col-md-offset-3" id="encrypt_warning" style="display:none;">
|
||||
<div class="callout callout-danger">
|
||||
<p><i class="fas fa-exclamation-triangle" aria-hidden="true"></i> {{ trans('admin/custom_fields/general.encrypt_field_help') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
<!-- Show in Email -->
|
||||
<div class="form-group {{ $errors->has('show_in_email') ? ' has-error' : '' }}" id="show_in_email">
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
<!-- Show in Email -->
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" name="show_in_email" aria-label="show_in_email" value="1"{{ (old('show_in_email') || $field->show_in_email) ? ' checked="checked"' : '' }}>
|
||||
{{ trans('admin/custom_fields/general.show_in_email') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Show in View All Assets profile view -->
|
||||
<div class="form-group {{ $errors->has('display_in_user_view') ? ' has-error' : '' }}" id="display_in_user_view">
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
<!-- Show in View All Assets profile view -->
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" name="display_in_user_view" aria-label="display_in_user_view" value="1" {{ (old('display_in_user_view') || $field->display_in_user_view) ? ' checked="checked"' : '' }}>
|
||||
{{ trans('admin/custom_fields/general.display_in_user_view') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Value Must be Unique -->
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" name="is_unique" aria-label="is_unique" value="1"{{ (old('is_unique') || $field->is_unique) ? ' checked="checked"' : '' }}>
|
||||
{{ trans('admin/custom_fields/general.is_unique') }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Value Must be Unique -->
|
||||
<div class="form-group {{ $errors->has('is_unique') ? ' has-error' : '' }}" id="is_unique">
|
||||
<div class="col-md-8 col-md-offset-4">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" name="is_unique" aria-label="is_unique" value="1"{{ (old('is_unique') || $field->is_unique) ? ' checked="checked"' : '' }}>
|
||||
{{ trans('admin/custom_fields/general.is_unique') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@if ($fieldsets->count() > 0)
|
||||
<!-- begin fieldset columns -->
|
||||
<div class="col-md-4">
|
||||
|
||||
<h4>{{ trans('admin/custom_fields/general.fieldsets') }}</h4>
|
||||
{!! $errors->first('associate_fieldsets', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
|
||||
<label class="form-control">
|
||||
<input type="checkbox" id="checkAll">
|
||||
{{ trans('general.select_all') }}
|
||||
</label>
|
||||
|
||||
@foreach ($fieldsets as $fieldset)
|
||||
@php
|
||||
$array_fieldname = 'associate_fieldsets.'.$fieldset->id;
|
||||
|
||||
// Consider the form data first
|
||||
if (old($array_fieldname) == $fieldset->id) {
|
||||
$checked = 'checked';
|
||||
// Otherwise check DB
|
||||
} elseif (isset($field->fieldset) && ($field->fieldset->contains($fieldset->id))) {
|
||||
$checked = 'checked';
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
@endphp
|
||||
|
||||
<label class="form-control{{ $errors->has('associate_fieldsets.'.$fieldset->id) ? ' has-error' : '' }}">
|
||||
<input type="checkbox"
|
||||
name="associate_fieldsets[{{ $fieldset->id }}]"
|
||||
class="fieldset"
|
||||
value="{{ $fieldset->id }}"
|
||||
{{ $checked }}>
|
||||
{{ $fieldset->name }}
|
||||
{!! $errors->first('associate_fieldsets.'.$fieldset->id, '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
|
||||
|
||||
</label>
|
||||
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
@endif
|
||||
</div> <!-- /.box-body-->
|
||||
|
||||
<div class="box-footer text-right">
|
||||
|
@ -171,20 +221,22 @@
|
|||
|
||||
</div> <!--.box.box-default-->
|
||||
|
||||
{{ Form::close() }}
|
||||
|
||||
</div> <!--/.col-md-9-->
|
||||
|
||||
<div class="col-md-3">
|
||||
<h2>{{ trans('admin/custom_fields/general.about_custom_fields_title') }}</h2>
|
||||
<p>{{ trans('admin/custom_fields/general.about_custom_fields_text') }}</p>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
@stop
|
||||
|
||||
@section('moar_scripts')
|
||||
<script nonce="{{ csrf_token() }}">
|
||||
$(document).ready(function(){
|
||||
|
||||
$("#checkAll").change(function () {
|
||||
$(".fieldset").prop('checked', $(this).prop("checked"));
|
||||
});
|
||||
|
||||
// Only display the custom format field if it's a custom format validation type
|
||||
$(".format").change(function(){
|
||||
$(this).find("option:selected").each(function(){
|
||||
|
|
|
@ -178,26 +178,29 @@
|
|||
</td>
|
||||
<td>
|
||||
<nobr>
|
||||
{{ Form::open(array('route' => array('fields.destroy', $field->id), 'method' => 'delete', 'style' => 'display:inline-block')) }}
|
||||
@can('update', $field)
|
||||
<a href="{{ route('fields.edit', $field->id) }}" class="btn btn-warning btn-sm">
|
||||
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.edit') }}</span>
|
||||
</a>
|
||||
<a href="{{ route('fields.edit', $field->id) }}" class="btn btn-warning btn-sm">
|
||||
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.edit') }}</span>
|
||||
</a>
|
||||
@endcan
|
||||
|
||||
@can('delete', $field)
|
||||
{{ Form::open(array('route' => array('fields.destroy', $field->id), 'method' => 'delete', 'style' => 'display:inline-block')) }}
|
||||
@if($field->fieldset->count()>0)
|
||||
<button type="submit" class="btn btn-danger btn-sm disabled" disabled>
|
||||
<i class="fas fa-trash" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.delete') }}</span></button>
|
||||
@else
|
||||
<button type="submit" class="btn btn-danger btn-sm">
|
||||
<i class="fas fa-trash" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.delete') }}</span>
|
||||
</button>
|
||||
@endif
|
||||
{{ Form::close() }}
|
||||
|
||||
@if($field->fieldset->count()>0)
|
||||
<button type="submit" class="btn btn-danger btn-sm disabled" disabled>
|
||||
<i class="fas fa-trash" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.delete') }}</span></button>
|
||||
@else
|
||||
<button type="submit" class="btn btn-danger btn-sm">
|
||||
<i class="fas fa-trash" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.delete') }}</span>
|
||||
</button>
|
||||
@endif
|
||||
|
||||
@endcan
|
||||
{{ Form::close() }}
|
||||
</nobr>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -13,12 +13,6 @@ class CustomFieldTest extends TestCase
|
|||
public function testFormat()
|
||||
{
|
||||
$customfield = CustomField::factory()->make(['format' => 'IP']);
|
||||
$values = [
|
||||
'name' => $customfield->name,
|
||||
'format' => $customfield->format,
|
||||
'element' => $customfield->element,
|
||||
];
|
||||
|
||||
$this->assertEquals($customfield->getAttributes()['format'], CustomField::PREDEFINED_FORMATS['IP']); //this seems undocumented...
|
||||
$this->assertEquals($customfield->format, 'IP');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue