mirror of
https://github.com/grokability/snipe-it.git
synced 2026-03-12 17:52:00 +08:00
Merge pull request #18529 from grokability/consolidate-customfieldset-edit
Consolidated custom fieldset edit/show
This commit is contained in:
@@ -50,8 +50,8 @@ class ResetDemoSettings extends Command
|
||||
$settings->alert_email = 'service@snipe-it.io';
|
||||
$settings->login_note = 'Use `admin` / `password` to login to the demo.';
|
||||
$settings->header_color = '#3c8dbc';
|
||||
$settings->link_dark_color = '#86cbf2';
|
||||
$settings->link_light_color = '#084d73;';
|
||||
$settings->link_dark_color = '#5fa4cc';
|
||||
$settings->link_light_color = '#296282;';
|
||||
$settings->label2_2d_type = 'QRCODE';
|
||||
$settings->default_currency = 'USD';
|
||||
$settings->brand = 2;
|
||||
|
||||
@@ -74,7 +74,7 @@ class CustomFieldsetsController extends Controller
|
||||
{
|
||||
$this->authorize('create', CustomField::class);
|
||||
|
||||
return view('custom_fields.fieldsets.edit')->with('item', new CustomFieldset());
|
||||
return view('custom_fields.fieldsets.view')->with('custom_fieldset', new CustomFieldset());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ class CustomFieldsetsController extends Controller
|
||||
public function edit(CustomFieldset $fieldset) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize('create', CustomField::class);
|
||||
return view('custom_fields.fieldsets.edit')->with('item', $fieldset);
|
||||
return view('custom_fields.fieldsets.view')->with('custom_fieldset', $fieldset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,10 +12,6 @@
|
||||
|
||||
@section('content')
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ route('fields.index') }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.back') }}</a>
|
||||
@stop
|
||||
|
||||
|
||||
{{-- Page content --}}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
@extends('layouts/edit-form', [
|
||||
'createText' => trans('admin/custom_fields/general.create_fieldset') ,
|
||||
'updateText' => trans('admin/custom_fields/general.update_fieldset'),
|
||||
'helpText' => trans('admin/custom_fields/general.about_fieldsets_text'),
|
||||
'helpPosition' => 'right',
|
||||
'formAction' => (isset($item->id)) ? route('fieldsets.update', ['fieldset' => $item->id]) : route('fieldsets.store'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
@parent
|
||||
@stop
|
||||
|
||||
@section('inputFields')
|
||||
@include ('partials.forms.edit.name', ['translated_name' => trans('general.name')])
|
||||
@stop
|
||||
|
||||
|
||||
@@ -6,172 +6,183 @@
|
||||
@parent
|
||||
@stop
|
||||
|
||||
@section('header_right')
|
||||
<a href="{{ route('fields.index') }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.back') }}</a>
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h2 class="box-title">{{ $custom_fieldset->name }} {{ trans('admin/custom_fields/general.fieldset') }}</h2>
|
||||
<div class="box-tools pull-right">
|
||||
</div>
|
||||
</div><!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
<table id="sort" class="table table-responsive table-striped snipe-table table-no-bordered todo-list">
|
||||
<thead>
|
||||
<tr>
|
||||
{{-- Hide the sorting handle if we can't update the fieldset --}}
|
||||
@can('update', $custom_fieldset)
|
||||
<th class="col-md-1"><span class="sr-only">{{ trans('admin/custom_fields/general.reorder') }}</span></th>
|
||||
@endcan
|
||||
<th class="col-md-1" style="display: none;">{{ trans('admin/custom_fields/general.order') }}</th>
|
||||
<th class="col-md-3">{{ trans('admin/custom_fields/general.field_name') }}</th>
|
||||
<th class="col-md-2">{{ trans('admin/custom_fields/general.field_format') }}</th>
|
||||
<th class="col-md-2">{{ trans('admin/custom_fields/general.field_element') }}</th>
|
||||
<th class="col-md-1">{{ trans('admin/custom_fields/general.encrypted') }}</th>
|
||||
<th class="col-md-1">{{ trans('admin/custom_fields/general.required') }}</th>
|
||||
<th class="col-md-1"><span class="sr-only">{{ trans('button.remove') }}</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($custom_fieldset->fields as $field)
|
||||
<tr class="{{ Auth::user()->can('update', $custom_fieldset)?'cansort':'' }}" data-index="{{ $field->pivot->custom_field_id }}" id="item_{{ $field->pivot->custom_field_id }}">
|
||||
{{-- Hide the sorting handle if we can't update the fieldset --}}
|
||||
@can('update', $custom_fieldset)
|
||||
<td>
|
||||
<!-- drag handle -->
|
||||
<span class="handle">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</span>
|
||||
</td>
|
||||
@endcan
|
||||
<td class="index" style="display: none;">{{$field->pivot->order + 1}}</td> {{--this +1 needs to exist to keep the first row from reverting to 0 if you edit/delete fields in/from a fielset--}}
|
||||
<td>{{$field->name}}</td>
|
||||
<td>{{$field->format}}</td>
|
||||
<td>{{$field->element}}</td>
|
||||
<td>{{ $field->field_encrypted=='1' ? trans('general.yes') : trans('general.no') }}</td>
|
||||
<td>
|
||||
|
||||
@if ($field->pivot->required)
|
||||
<form method="post" action="{{ route('fields.optional', [$custom_fieldset->id, $field->id]) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-link"><i class="fa fa-check text-success" aria-hidden="true"></i></button>
|
||||
</form>
|
||||
|
||||
@else
|
||||
|
||||
<form method="post" action="{{ route('fields.required', [$custom_fieldset->id, $field->id]) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-link"><i class="fa fa-times text-danger" aria-hidden="true"></i></button>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
</td>
|
||||
<td>
|
||||
@can('update', $custom_fieldset)
|
||||
<form method="post" action="{{ route('fields.disassociate', [$field, $custom_fieldset->id]) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-sm btn-danger" data-tooltip="true" title="{{ trans('general.remove_customfield_association') }}"><i class="fa fa-minus icon-white" aria-hidden="true"></i></button>
|
||||
</form>
|
||||
@endcan
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@can('update', $custom_fieldset)
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="8">
|
||||
<form method="POST" action="{{ route('fieldsets.associate', $custom_fieldset->id) }}" accept-charset="UTF-8" class="form-inline" id="ordering">
|
||||
@csrf
|
||||
|
||||
<x-container>
|
||||
<x-box>
|
||||
<x-form :item="$custom_fieldset" route="{{ (isset($custom_fieldset->id)) ? route('fieldsets.update', ['fieldset' => $custom_fieldset->id]) : route('fieldsets.store') }}">
|
||||
<!-- Name -->
|
||||
<div class="form-group">
|
||||
<label for="field_id" class="sr-only">
|
||||
{{ trans('admin/custom-field/general.add_field_to_fieldset')}}
|
||||
</label>
|
||||
<x-input.select
|
||||
name="field_id"
|
||||
:options="$custom_fields_list"
|
||||
style="min-width:400px"
|
||||
aria-label="field_id"
|
||||
/>
|
||||
<x-form.label for="name" class="col-md-3">
|
||||
{{ trans('general.name') }}
|
||||
</x-form.label>
|
||||
|
||||
<div class="col-md-6">
|
||||
<input type="text" class="form-control" name="name" value="{{ $custom_fieldset->name }}" required>
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<button class="btn btn-success">{{ trans('general.update') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</x-form>
|
||||
|
||||
<div class="form-group" style="display: none;">
|
||||
<input aria-label="order" maxlength="3" size="3" name="order" type="text" value="{{ $maxid }}">
|
||||
<label for="order">{{ trans('admin/custom_fields/general.order') }}</label>
|
||||
</div>
|
||||
@if((isset($custom_fieldset)) && ($custom_fieldset->id!=''))
|
||||
<table id="sort" class="table table-responsive table-striped snipe-table table-no-bordered todo-list" style="padding-top: 30px">
|
||||
<thead>
|
||||
<tr>
|
||||
{{-- Hide the sorting handle if we can't update the fieldset --}}
|
||||
@can('update', $custom_fieldset)
|
||||
<th class="col-md-1"><span class="sr-only">{{ trans('admin/custom_fields/general.reorder') }}</span></th>
|
||||
@endcan
|
||||
<th class="col-md-1" style="display: none;">{{ trans('admin/custom_fields/general.order') }}</th>
|
||||
<th class="col-md-3">{{ trans('admin/custom_fields/general.field_name') }}</th>
|
||||
<th class="col-md-2">{{ trans('admin/custom_fields/general.field_format') }}</th>
|
||||
<th class="col-md-2">{{ trans('admin/custom_fields/general.field_element') }}</th>
|
||||
<th class="col-md-1">{{ trans('admin/custom_fields/general.encrypted') }}</th>
|
||||
<th class="col-md-1">{{ trans('admin/custom_fields/general.required') }}</th>
|
||||
<th class="col-md-1"><span class="sr-only">{{ trans('button.remove') }}</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($custom_fieldset->fields as $field)
|
||||
<tr class="{{ Auth::user()->can('update', $custom_fieldset)?'cansort':'' }}" data-index="{{ $field->pivot->custom_field_id }}" id="item_{{ $field->pivot->custom_field_id }}">
|
||||
{{-- Hide the sorting handle if we can't update the fieldset --}}
|
||||
@can('update', $custom_fieldset)
|
||||
<td>
|
||||
<!-- drag handle -->
|
||||
<span class="handle">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</span>
|
||||
</td>
|
||||
@endcan
|
||||
<td class="index" style="display: none;">{{$field->pivot->order + 1}}</td> {{--this +1 needs to exist to keep the first row from reverting to 0 if you edit/delete fields in/from a fielset--}}
|
||||
<td>{{$field->name}}</td>
|
||||
<td>{{$field->format}}</td>
|
||||
<td>{{$field->element}}</td>
|
||||
<td>{{ $field->field_encrypted=='1' ? trans('general.yes') : trans('general.no') }}</td>
|
||||
<td>
|
||||
|
||||
<div class="checkbox-inline">
|
||||
<label>
|
||||
<input type="checkbox" name="required" value="on" @checked(old('required'))>
|
||||
<span style="padding-left: 10px;">{{ trans('admin/custom_fields/general.required') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
@if ($field->pivot->required)
|
||||
<form method="post" action="{{ route('fields.optional', [$custom_fieldset->id, $field->id]) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-link"><i class="fa fa-check text-success" aria-hidden="true"></i></button>
|
||||
</form>
|
||||
|
||||
<span style="padding-left: 10px;">
|
||||
<button type="submit" class="btn btn-primary"> {{ trans('general.save') }}</button>
|
||||
</span>
|
||||
@else
|
||||
|
||||
</form>
|
||||
<form method="post" action="{{ route('fields.required', [$custom_fieldset->id, $field->id]) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-link"><i class="fa fa-times text-danger" aria-hidden="true"></i></button>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
@endcan
|
||||
</table>
|
||||
</div> <!-- /.box-body-->
|
||||
</div> <!-- /.box.box-default-->
|
||||
</div> <!-- /.col-md-12-->
|
||||
</div> <!--/.row-->
|
||||
</td>
|
||||
<td>
|
||||
@can('update', $custom_fieldset)
|
||||
<form method="post" action="{{ route('fields.disassociate', [$field, $custom_fieldset->id]) }}">
|
||||
@csrf
|
||||
<button type="submit" class="btn btn-sm btn-danger" data-tooltip="true" title="{{ trans('general.remove_customfield_association') }}"><i class="fa fa-minus icon-white" aria-hidden="true"></i></button>
|
||||
</form>
|
||||
@endcan
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
@can('update', $custom_fieldset)
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="8">
|
||||
<form method="POST" action="{{ route('fieldsets.associate', $custom_fieldset->id) }}" accept-charset="UTF-8" class="form-inline" id="ordering">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
<label for="field_id" class="sr-only">
|
||||
{{ trans('admin/custom-field/general.add_field_to_fieldset')}}
|
||||
</label>
|
||||
<x-input.select
|
||||
name="field_id"
|
||||
:options="$custom_fields_list"
|
||||
style="min-width:400px"
|
||||
aria-label="field_id"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="display: none;">
|
||||
<input aria-label="order" maxlength="3" size="3" name="order" type="text" value="{{ $maxid }}">
|
||||
<label for="order">{{ trans('admin/custom_fields/general.order') }}</label>
|
||||
</div>
|
||||
|
||||
<div class="checkbox-inline">
|
||||
<label>
|
||||
<input type="checkbox" name="required" value="on" @checked(old('required'))>
|
||||
<span style="padding-left: 10px;">{{ trans('admin/custom_fields/general.required') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<span style="padding-left: 10px;">
|
||||
<button type="submit" class="btn btn-primary"> {{ trans('general.save') }}</button>
|
||||
</span>
|
||||
|
||||
</form>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
@endcan
|
||||
</table>
|
||||
|
||||
@endif
|
||||
|
||||
|
||||
</x-box>
|
||||
</x-container>
|
||||
|
||||
@stop
|
||||
|
||||
@push('js')
|
||||
@can('update', $custom_fieldset)
|
||||
@if((isset($custom_fieldset)) && ($custom_fieldset->id!=''))
|
||||
<script nonce="{{ csrf_token() }}">
|
||||
var fixHelperModified = function(e, tr) {
|
||||
var $originals = tr.children();
|
||||
var $helper = tr.clone();
|
||||
$helper.children().each(function(index) {
|
||||
$(this).width($originals.eq(index).width())
|
||||
});
|
||||
return $helper;
|
||||
},
|
||||
updateIndex = function(e, ui) {
|
||||
$('td.index', ui.item.parent()).each(function (i) {
|
||||
$(this).html(i + 1);
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "{{ route('api.customfields.order', $custom_fieldset->id) }}",
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
data: $("#sort tbody").sortable('serialize', {
|
||||
}),
|
||||
|
||||
<script nonce="{{ csrf_token() }}">
|
||||
var fixHelperModified = function(e, tr) {
|
||||
var $originals = tr.children();
|
||||
var $helper = tr.clone();
|
||||
$helper.children().each(function(index) {
|
||||
$(this).width($originals.eq(index).width())
|
||||
});
|
||||
return $helper;
|
||||
},
|
||||
updateIndex = function(e, ui) {
|
||||
$('td.index', ui.item.parent()).each(function (i) {
|
||||
$(this).html(i + 1);
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "{{ route('api.customfields.order', $custom_fieldset->id) }}",
|
||||
headers: {
|
||||
"X-Requested-With": 'XMLHttpRequest',
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
|
||||
},
|
||||
data: $("#sort tbody").sortable('serialize', {
|
||||
}),
|
||||
|
||||
success: function(data) {
|
||||
//console.log('ajax fired');
|
||||
// do some stuff here
|
||||
success: function(data) {
|
||||
//console.log('ajax fired');
|
||||
// do some stuff here
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// this uses the jquery UI sortable method, NOT the query-dragtable library
|
||||
$("#sort tbody").sortable({
|
||||
helper: fixHelperModified,
|
||||
stop: updateIndex
|
||||
}).disableSelection();
|
||||
</script>
|
||||
// this uses the jquery UI sortable method, NOT the query-dragtable library
|
||||
$("#sort tbody").sortable({
|
||||
helper: fixHelperModified,
|
||||
stop: updateIndex
|
||||
}).disableSelection();
|
||||
</script>
|
||||
@endif
|
||||
@endcan
|
||||
@endpush
|
||||
|
||||
@@ -19,11 +19,6 @@
|
||||
|
||||
<div class="box-header with-border">
|
||||
<h2 class="box-title">{{ trans('admin/custom_fields/general.fieldsets') }}</h2>
|
||||
<div class="box-tools pull-right">
|
||||
@can('create', \App\Models\CustomFieldset::class)
|
||||
<a href="{{ route('fieldsets.create') }}" class="btn btn-sm btn-theme" data-tooltip="true" title="{{ trans('admin/custom_fields/general.create_fieldset_title') }}">{{ trans('admin/custom_fields/general.create_fieldset') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
</div><!-- /.box-header -->
|
||||
|
||||
<div class="box-body">
|
||||
@@ -73,13 +68,8 @@
|
||||
|
||||
@can('update', $fieldset)
|
||||
|
||||
<a href="{{ route('fieldsets.show', ['fieldset' => $fieldset->id]) }}" data-tooltip="true" title="{{ trans('general.edit_fieldset') }}">
|
||||
<button type="submit" class="btn btn-info btn-sm">
|
||||
<i class="fa-regular fa-rectangle-list"></i>
|
||||
</button>
|
||||
</a>
|
||||
|
||||
<a href="{{ route('fieldsets.edit', $fieldset->id) }}" class="btn btn-warning btn-sm" data-tooltip="true" title="{{ trans('general.update') }}">
|
||||
<a href="{{ route('fieldsets.show', $fieldset->id) }}" class="btn btn-warning btn-sm" data-tooltip="true" title="{{ trans('general.update') }}">
|
||||
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
|
||||
<span class="sr-only">{{ trans('button.edit') }}</span>
|
||||
</a>
|
||||
@@ -114,12 +104,6 @@
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h2 class="box-title">{{ trans('admin/custom_fields/general.custom_fields') }}</h2>
|
||||
<div class="box-tools pull-right">
|
||||
@can('create', \App\Models\CustomField::class)
|
||||
<a href="{{ route('fields.create') }}" class="btn btn-sm btn-theme" data-tooltip="true" title="{{ trans('admin/custom_fields/general.create_field_title') }}">{{ trans('admin/custom_fields/general.create_field') }}</a>
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
</div><!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
|
||||
|
||||
@@ -32,18 +32,25 @@ Route::group([ 'prefix' => 'fields','middleware' => ['auth'] ], function () {
|
||||
[CustomFieldsetsController::class, 'associate']
|
||||
)->name('fieldsets.associate');
|
||||
|
||||
|
||||
|
||||
Route::resource('fieldsets', CustomFieldsetsController::class, [
|
||||
'parameters' => [
|
||||
'fieldset' => 'fieldset',
|
||||
'field' => 'field_id'
|
||||
]
|
||||
],
|
||||
'except' => ['show', 'view']
|
||||
]);
|
||||
|
||||
Route::get(
|
||||
'fieldsets/{fieldset}/edit',
|
||||
[CustomFieldsetsController::class, 'show']
|
||||
)->name('fieldsets.show');
|
||||
|
||||
});
|
||||
|
||||
Route::resource('fields', CustomFieldsController::class,
|
||||
['middleware' => ['auth'],
|
||||
'except' => ['show']
|
||||
'except' => ['show', 'view']
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user