jQuery(document).ready(function () {
    initLcSortableProductsList();
});

function initLcSortableProductsList() {
    if ($('.lc-sortable-products').length > 0) {
        $('.lc-sortable-products tbody').sortable({
            placeholder: "ui-state-highlight"
        });
        $('.lc-sortable-products tbody').on("sortupdate", function (event, ui) {
            updateSortableProducts();
        });
    }
}


function updateSortableProducts() {
    if ($('.lc-sortable-products').length > 0) {
        $('.lc-sortable-products tr.lc-draggable').each(function (index, li) {
            $(li).find('.field-position').val(index);
        });
    }
}
