{% if pagination and pagination.totalItemCount %}
<script src="{{ asset('ProductSort42/assets/jquery-ui.js', 'plugin') }}"></script>
<script>
$(function () {
$("#form_bulk table tbody").sortable({
item: 'tr',
axis: 'y',
update: function (event, ui) {
$('body').append($('<div class="modal-backdrop show"></div>'));
$.ajax({
type: 'PUT',
dataType: 'json',
url: '{{ path('admin_product_product_sort') }}',
data: {
order: $('#form_bulk table tbody').sortable('serialize')
}
}).done((data) => {
console.log(data.message);
}).fail((data) => {
console.log(data.responseJSON.message);
}).always((data) => {
window.location.href = '{{ path('admin_product') }}'
});
}
});
$('#form_bulk table thead tr').append('<th class="border-top-0 pt-2 pb-2" style="width: 150px">並び順</th>')
{% for Product in pagination %}
$("tr#ex-product-{{ Product.id }}").append('<td class="align-middle"><input type="text" class="form-control" style="width:50px;" value="{{ Product.plg_sort_no }}" data-move-url="{{ url('admin_product_product_move', { id: Product.id }) }}" /></td>');
{% endfor %}
$('#form_bulk table tr[id^="ex-product"] input[type="text"]').on('change', function () {
$('body').append($('<div class="modal-backdrop show"></div>'));
$.ajax({
type: 'PUT',
url: $(this).data('move-url'),
data: {
sort_no: $(this).val()
}
}).done((data) => {
console.log(data.message)
}).fail((data) => {
alert(data.responseJSON.message)
}).always((data) => {
window.location.href = '{{ path('admin_product') }}'
});
});
});
</script>
{% endif %}