Current File : /var/www/vinorea/modules/ipexportimport/views/js/back.js
/**
 *
 * NOTICE OF LICENSE
 *
 *  @author    SmartPresta <tehran.alishov@gmail.com>
 *  @copyright 2024 SmartPresta
 *  @license   Commercial License
 */

$(document).ready(function () {
// Left item group click 
    $('.catalogEIATabs .list-group a.list-group-item').click(function (e) {
        e.preventDefault();
        $(this).siblings('.active').removeClass('active');
        $(this).addClass('active');
        $('.catalogEIA-tab-content').hide();
        var section = $(this).attr('id').replace('link-', '');
        $('#catalogEIA-tab-content-' + section).show();

        localStorage.setItem('catalogEIATabs_lastTab', section);
    });

    var lastSavedTab = localStorage.getItem('catalogEIATabs_lastTab');
    if (lastSavedTab) {
        $('.catalogEIATabs #link-' + lastSavedTab).click();
    }

//    $('.catalogEIA-tab-content a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
//        lastSavedTab = localStorage.getItem('catalogEIATabs_lastTab');
//        localStorage.setItem('catalogEIATabs_lastSubTab_of_' + lastSavedTab, $(e.target).attr('href'));
//    });
//
//    var lastSavedSubTab = localStorage.getItem('catalogEIATabs_lastSubTab_of_' + lastSavedTab);
//    if (lastSavedSubTab) {
//        $('.catalogEIA-tab-content a[data-toggle="tab"][href="' + lastSavedSubTab + '"]').tab('show');
//    }

    var x = document.querySelectorAll('input[type=range]');
    for (var i = 0; i < x.length; i++) {
        x[i].oninput = function () {
            var value = (this.value - this.min) / (this.max - this.min) * 100;
            this.style.background = 'linear-gradient(to right, #3586AE ' + value + '%, #3586AE ' + value + '%, #EFEFEF ' + value + '%, #EFEFEF 100%)';
        };
    }
    
    $('.module-block button.btn.btn-default').on('click', function (e) {
        e.preventDefault();
        open($(this).parent().attr('href'), '_blank');
    });

    $('.columns_search_for_filter').keyup(function (e) {
        var value = $(this).val().toLowerCase();
        if (value) {
            $(this).closest('.clearable').find('.clearable_clear_for_filter').show();
        } else {
            $(this).closest('.clearable').find('.clearable_clear_for_filter').hide();
        }

        $(this).closest(".filter-fields-container").find('.columns_for_filter > li').each(function () {
            if ($(this).text().toLowerCase().search(value) > -1) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    });
    
    $('.clearable_clear_for_filter').click(function () {
        $(this).closest('.clearable').find('.columns_search_for_filter').val('').trigger('keyup');
    });

    $('body').on('focus', ".datepicker_input", function () {
        $(this).datetimepicker({
            dateFormat: "yy-mm-dd",
            timeFormat: "hh:mm:ss",
            showSecond: true,
        });
    });

    $(document).on('click', '.filter_section_remove', function () {
        var filter_section = $(this).closest('.filter_section');
        var column = filter_section.attr('data-value');
        if ($('.filter_section[data-value="' + column + '"]').length === 1) {
            filter_section.closest(".filter-fields-container").find('li[data-value="' + column + '"]').removeClass('filter_added');
        }
        filter_section.remove();
    });

    $(document).on('change', 'select.date_filter', function () {
        var closest = $(this).closest('.filter_section_data');
        if (this.value !== 'last_n_hours') {
            closest.find('.n_hours').addClass('hide');
        } else {
            closest.find('.n_hours').removeClass('hide');
        }
        if (this.value !== 'last_n_days') {
            closest.find('.n_days').addClass('hide');
        } else {
            closest.find('.n_days').removeClass('hide');
        }
        if (this.value === 'select_date') {
            closest.find('.after_date').removeClass('hide');
            closest.find('.before_date').removeClass('hide');
        } else {
            if (this.value !== 'before_date') {
                closest.find('.before_date').addClass('hide');
            } else {
                closest.find('.before_date').removeClass('hide');
            }
            if (this.value !== 'after_date') {
                closest.find('.after_date').addClass('hide');
            } else {
                closest.find('.after_date').removeClass('hide');
            }
        }
    });
    
    $('select[name="csv_separator"]').change(function () {
        if ($(this).val() === 'other') {
            $(this).closest('.catalogEIA_form').find('.custom_separator').removeClass('hide');
        } else {
            $(this).closest('.catalogEIA_form').find('.custom_separator').addClass('hide');
        }
    });

});