$(function()
{
    if(v.mode == 'browse') $('#menu li').removeClass('active').find('[href*=' + v.status + ']').parent().addClass('active');
    $('#category' + v.category).parent('li').addClass('active');

    $('#productList').on('sort.sortable', function(e, data)
    {
        const orderStart = v.pageID > 1 ? (v.recPerPage * (v.pageID - 1)) + 1 : 1;
        Object.keys(data.orders).forEach(function(key){
            data.orders[key] += orderStart;
        });
        $.post(createLink('product', 'sort'), {products: data.orders}, function(response)
        {
            if(response.result == 'success')
            {
                return location.reload();
            }
            else
            {
                bootbox.alert(response.message);
            }
        }, 'json');
    });

    /* expand active tree. */
    $('.tree').tree('expandSelect', '.active');
})
