mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
[Feature] Re-order custom fields (drag and drop)
This commit is contained in:
parent
72d54bdb88
commit
f4490b14f8
|
@ -250,4 +250,27 @@ class CustomFieldsController extends Controller
|
|||
return redirect()->route("admin.custom_fields.index")->with("error", trans('admin/custom_fields/message.fieldset.delete.in_use')); //->with("models",$models);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reorder the custom fields within a fieldset
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @param int $id
|
||||
* @since [v3.0]
|
||||
* @return Array
|
||||
*/
|
||||
public function postReorder($id) {
|
||||
$fieldset=CustomFieldset::find($id);
|
||||
$fields = array();
|
||||
|
||||
$items = Input::get('item');
|
||||
foreach ($fieldset->fields as $field) {
|
||||
$value = array_shift($items);
|
||||
$fields[$field->id] = ['required' => $field->pivot->required, 'order' => $value];
|
||||
}
|
||||
return $fieldset->fields()->sync($fields);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,6 +148,16 @@ Route::group([ 'prefix' => 'api', 'middleware' => 'auth' ], function () {
|
|||
|
||||
Route::resource('/', 'SuppliersController');
|
||||
});
|
||||
|
||||
/*-- Custom fields API --*/
|
||||
Route::group([ 'prefix' => 'custom_fields' ], function () {
|
||||
Route::post(
|
||||
'{fieldsetID}/order',
|
||||
[ 'as' => 'api.customfields.order', 'uses' => 'CustomFieldsController@postReorder' ]
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5" class="text-right">
|
||||
{{ Form::open(['route' => ["admin.custom_fields.associate",$custom_fieldset->id], 'class'=>'form-horizontal']) }}
|
||||
{{ Form::open(['route' => ["admin.custom_fields.associate",$custom_fieldset->id], 'class'=>'form-horizontal', 'id' => 'ordering']) }}
|
||||
{{ Form::checkbox("required","on") }}
|
||||
{{ trans('admin/custom_fields/general.required') }}
|
||||
{{ Form::text("order",$maxid)}}
|
||||
|
@ -52,8 +52,8 @@
|
|||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
@foreach($custom_fieldset->fields AS $field)
|
||||
<tr class="cansort" data-index="{{ $field->pivot->custom_field_id }}">
|
||||
@foreach($custom_fieldset->fields as $field)
|
||||
<tr class="cansort" data-index="{{ $field->pivot->custom_field_id }}" id="item_{{ $field->pivot->custom_field_id }}">
|
||||
<td>
|
||||
<!-- drag handle -->
|
||||
<span class="handle">
|
||||
|
@ -94,11 +94,17 @@
|
|||
$('td.index', ui.item.parent()).each(function (i) {
|
||||
$(this).html(i + 1);
|
||||
$.ajax({
|
||||
url: "{{config('app.url') }}/api/custom_fields/order",
|
||||
success: function(data) {
|
||||
// do some stuff here
|
||||
method: "POST",
|
||||
url: "{{ route('api.customfields.order', $custom_fieldset->id) }}",
|
||||
data: $("#sort tbody").sortable('serialize', {
|
||||
// key:
|
||||
}),
|
||||
|
||||
}
|
||||
success: function(data) {
|
||||
//console.log('ajax fired');
|
||||
// do some stuff here
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue