/**
* 2007-2024 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    PrestaShop SA <contact@prestashop.com>
*  @copyright 2007-2024 PrestaShop SA
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*
* Don't forget to prefix your containers with your own identifier
* to avoid any conflicts with others containers.
*/
$(document).ready(function () {
    $('.pagination a.js-search-link:not(.disabled)').on('click', function(){
        window.location.href = $(this).attr('href');
    })
});

function goOnClick() {
    var url = listurl + "?p=" + (p <= 0 ? 1 : p) + "&n=" + n + "&orderBy=" + orderBy + "&orderWay=" + orderWay + getExtra();
    window.location.href = url;
}

function ResetOnClick() {
    $("[id^='filter_']").val("");
    goOnClick();

}

function CSVOnClick() {
    var url = listurl + "?export=CSV" + "&p=" + (p <= 0 ? 1 : p) + "&n=" + n + "&orderBy=" + orderBy + "&orderWay=" + orderWay + getExtra();
    window.location.href = url;
}

function getExtra() {
    var ex = "";
    var filter_customer = $("#filter_customer").val();
    var filter_reference = $("#filter_reference").val();
    var filter_id_order = $("#filter_id_order").val();
    var filter_id_order_state = $("#filter_id_order_state").val();
    var filter_total = $("#filter_total").val();
    var filter_payment = $("#filter_payment").val();
    var filter_date_add_from = $("#filter_date_add_from").val();
    var filter_date_add_to = $("#filter_date_add_to").val();

    if (filter_customer.length > 0) ex = ex + "&filter_customer=" + filter_customer;
    if (filter_reference.length > 0) ex = ex + "&filter_reference=" + filter_reference;
    if (filter_id_order && filter_id_order.length > 0) ex = ex + "&filter_id_order=" + filter_id_order;
    if (filter_id_order_state.length > 0) ex = ex + "&filter_id_order_state=" + filter_id_order_state;
    if (filter_total.length > 0) ex = ex + "&filter_total=" + filter_total;
    if (filter_payment.length > 0) ex = ex + "&filter_payment=" + filter_payment;
    if (filter_date_add_from.length > 0) ex = ex + "&filter_date_add_from=" + filter_date_add_from;
    if (filter_date_add_to.length > 0) ex = ex + "&filter_date_add_to=" + filter_date_add_to;

    return ex;
}

function orderByWay(by, way) {
    var url = listurl + "?p=" + (p <= 0 ? 1 : p) + "&n=" + n + "&orderBy=" + by + "&orderWay=" + way + getExtra();
    window.location.href = url;
    return false;
}
