mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
APIified custom fields reorder
This commit is contained in:
parent
db7b1b586c
commit
297034c037
38
app/Http/Controllers/Api/CustomFieldsController.php
Normal file
38
app/Http/Controllers/Api/CustomFieldsController.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CustomFieldset;
|
||||
|
||||
class CustomFieldsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Reorder the custom fields within a fieldset
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @param int $id
|
||||
* @since [v3.0]
|
||||
* @return Array
|
||||
*/
|
||||
public function postReorder(Request $request, $id)
|
||||
{
|
||||
$fieldset = CustomFieldset::find($id);
|
||||
$fields = array();
|
||||
$order_array = array();
|
||||
|
||||
$items = $request->input('item');
|
||||
|
||||
foreach ($items as $order => $field_id) {
|
||||
$order_array[$field_id] = $order;
|
||||
}
|
||||
|
||||
foreach ($fieldset->fields as $field) {
|
||||
$fields[$field->id] = ['required' => $field->pivot->required, 'order' => $order_array[$field->id]];
|
||||
}
|
||||
|
||||
return $fieldset->fields()->sync($fields);
|
||||
|
||||
}
|
||||
}
|
|
@ -171,31 +171,5 @@ class CustomFieldsController extends Controller
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reorder the custom fields within a fieldset
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @param int $id
|
||||
* @since [v3.0]
|
||||
* @return Array
|
||||
*/
|
||||
public function postReorder(Request $request, $id)
|
||||
{
|
||||
$fieldset = CustomFieldset::find($id);
|
||||
$fields = array();
|
||||
$order_array = array();
|
||||
|
||||
$items = $request->input('item');
|
||||
|
||||
foreach ($items as $order => $field_id) {
|
||||
$order_array[$field_id] = $order;
|
||||
}
|
||||
|
||||
foreach ($fieldset->fields as $field) {
|
||||
$fields[$field->id] = ['required' => $field->pivot->required, 'order' => $order_array[$field->id]];
|
||||
}
|
||||
|
||||
return $fieldset->fields()->sync($fields);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
</div><!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
<table
|
||||
name="fieldsets"
|
||||
id="sort" class="table table-responsive todo-list"
|
||||
>
|
||||
name="fieldsets" id="sort" class="table table-responsive todo-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-md-1"></th>
|
||||
|
@ -99,6 +97,10 @@
|
|||
$.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', {
|
||||
}),
|
||||
|
||||
|
|
|
@ -243,14 +243,6 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*---Accessories API---*/
|
||||
Route::group([ 'prefix' => 'accessories' ], function () {
|
||||
|
||||
|
@ -307,6 +299,17 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
});
|
||||
|
||||
|
||||
Route::group([ 'prefix' => 'fields' ], function () {
|
||||
|
||||
Route::post(
|
||||
'fieldsets/{id}/order',
|
||||
[ 'as' => 'api.customfields.order', 'uses' => 'CustomFieldsController@postReorder' ]
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue