Untitled

Anonymous
plain_text
02/09/2026 7:27 PM
12.4 KB
14
Indexable


    if ($('[name="caching[caching_system]"]').length) {
        if ($('[name="caching[caching_system]"]:checked').val() == 'Redis') {
            getConfigurationTable($('[name="caching[caching_system]"]:checked'))
        }

        $('[name="caching[caching_system]"]').change(function () {
            removeContentInPerformanceTab('[name="caching[caching_system]"][value="Redis"]')

            if ($(this).val() == 'Redis') {
                getConfigurationTable($(this))
            }
        })
    }

    $('body').on('click', '#addNextAdminRedisConfigurationRow', function (e) {
        e.preventDefault();
        addNextAdminRedisConfigurationRow($(this));
    })

    $('body').on('click', '#saveAdminRedisConfigurationRow', function (e) {
        e.preventDefault();
        saveAdminRedisConfigurationRow($(this));
    })

    $('body').on('click', '[data-action="testAdminRedisConfigurationHost"]', function (e) {
        e.preventDefault();
        testAdminRedisConfigurationHost($(this));
    })

    $('body').on('click', '[data-action="removeAdminRedisConfigurationRow"]', function (e) {
        e.preventDefault();
        if (confirm(tw_redis_langs[0])) {
            let tr =  $(this).closest('tr');
            tr.prev().prev().remove();
            tr.prev().remove();
            tr.next().remove();
            tr.remove();
        }
    })

    $('body').on('click', '[data-action="adminRedisShowMore"]', function (e) {
        e.preventDefault();
        let element = $(this).closest('tr').next();
        if (element.hasClass('showmorerow') == true){
            element.removeClass('showmorerow');
            element.addClass('d-none');
            $(this).text($(this).data('textstart'));
        }else {
            element.addClass('showmorerow');
            element.removeClass('d-none');
            $(this).text($(this).data('textstop'));
        }
    })

    if (document.querySelector('#multiplecontrollertagpicker')) {
        $('#multiplecontrollertagpicker').select2({
            tags: true,
            tokenSeparators: [',', ' ']
        })
    }

    if (document.querySelector('#multiplecontrollertagpicker2')) {
        $('#multiplecontrollertagpicker2').select2({
            tags: true,
            tokenSeparators: [',', ' ']
        })
    }

    if (document.querySelector('#multiplecontrollertagpicker3')) {
        $('#multiplecontrollertagpicker3').select2({
            tags: true,
            tokenSeparators: [',', ' ']
        })
    }

    $('body').on('mouseenter', '.redis-socket-tooltip-wrapper i', function() {
        $(this).siblings('.redis-socket-tooltip').fadeIn(150);
    });

    $('body').on('mouseleave', '.redis-socket-tooltip-wrapper', function() {
        $(this).find('.redis-socket-tooltip').fadeOut(150);
    });

function removeContentInPerformanceTab(input) {
    // $(input).parent().parent().find('.html').remove();
    document.querySelectorAll('.teamwant_redis_table_container').forEach(element => element.remove());
}

function getUrl(){
    let url = ''
    if (typeof baseAdminDir !== 'undefined') {
        url = `${baseAdminDir}index.php`
    } else {
        url = window.location.origin
        let pathname = window.location.pathname
        url = url + pathname.split('/').slice(0, 2).join('/') + '/';
    }

    return url
}

function getConfigurationTable(input) {
    $(".card-footer .btn-primary").off('click');

    let postdata = {
        ajax: 1,
        controller: 'AdminRedisConfiguration',
        action: 'getConfigurationTable',
        token: token_AdminRedisConfiguration,
    };

    $.ajax({
        type: 'GET',
        url: getUrl(),
        dataType: "json",
        data: postdata,
        success: function (r) {
            if (r.success == 0 && r.type == 'alert') {
                alert(r.data)
                removeContentInPerformanceTab(input);
                return;
            }

            if (r.success == 0 && r.type == 'html') {
                $(input).closest('.form-group').append(
                    $('<div class="html teamwant_redis_table_container"></div>').append(
                        $(r.data)
                    )
                );
            }

            if (r.success == 1) {
                $(input).closest('.form-group').append(
                    $('<div class="html teamwant_redis_table_container"></div>').append(
                        $(r.data)
                    )
                );
            }

            preventUnsaveRedisConfiguration();
        }
    });
}

function addNextAdminRedisConfigurationRow(input) {
    let postdata = {
        ajax: 1,
        controller: 'AdminRedisConfiguration',
        action: 'getConfigurationTableRow',
        token: token_AdminRedisConfiguration,
    };

    $.ajax({
        type: 'GET',
        url: getUrl(),
        dataType: "json",
        data: postdata,
        success: function (r) {
            if (r.success == 0 && r.type == 'alert') {
                alert(r.data)
                return;
            }

            if (r.success == 1) {
                $(input).closest('tr').before(
                    $(r.data)
                );
            }
        }
    });
}

function saveAdminRedisConfigurationRow(input) {
    input.find('.loader').show();

    let postdata = {
        ajax: 1,
        controller: 'AdminRedisConfiguration',
        action: 'saveConfigurationTable',
        token: token_AdminRedisConfiguration,
        data: input.closest('form').serialize()
    };

    //uzupelniamy brakujace pola na requestach
    let usedFields = {}
    input.closest('form').serializeArray().forEach(function(a, b) {
        usedFields[a.name] = 1;
    })

    if (!usedFields['form[twredis][use_cache_admin]']) {
        postdata.data += '&' + 'form[twredis][use_cache_admin]' + '=' + 0;
    }

    if (!usedFields['form[twredis][use_prefix]']) {
        postdata.data += '&' + 'form[twredis][use_prefix]' + '=' + 0;
    }

    if (!usedFields['form[twredis][use_multistore]']) {
        postdata.data += '&' + 'form[twredis][use_multistore]' + '=' + 0;
    }

    $.ajax({
        type: 'POST',
        url: getUrl(),
        dataType: "json",
        data: postdata,
        complete: function () {
            input.find('.loader').hide();
        },
        success: function (r) {
            if (r.success == 0 && r.type == 'alert') {
                let stopProcess = 0;
                alert(r.data)

                if (r.stopProcess) {
                    stopProcess = 1;
                    input.find('.loader').hide();
                }

                if (!stopProcess) {
                    $(input).closest('.form-group').find('.html.teamwant_redis_table_container').remove();
                }
                return;
            }

            if (r.success == 0 && r.type == 'html') {
                $(input).closest('.form-group').find('.html.teamwant_redis_table_container').html(
                    $(r.data)
                );
            }

            if (r.success == 1) {
                $(input).closest('.form-group').find('.html.teamwant_redis_table_container').html(
                    $(r.data)
                );
            }
        }
    });
}

function testAdminRedisConfigurationHost(input) {
    let table_tr = input.closest('tr');
    let table_inputs = table_tr.find('input');
    let table_inputs2 = table_tr.next().next().find('input');

    input.find('.loader').show();

    let postdata = {
        ajax: 1,
        controller: 'AdminRedisConfiguration',
        action: 'testAdminRedisConfigurationHost',
        token: token_AdminRedisConfiguration,
        data: {
            'scheme': table_inputs[0].value,
            'host': table_inputs[1].value,
            'port': table_inputs[2].value,
            'alias': table_inputs2[0].value,
            'username': table_inputs2[1].value,
            'password': table_inputs2[2].value,
            'database': table_inputs2[3].value
        }
    };

    $.ajax({
        type: 'POST',
        url: getUrl(),
        dataType: "json",
        data: postdata,
        success: function (r) {
            alert(r.data)
            input.find('.loader').hide();
        }
    });
}

function preventUnsaveRedisConfiguration() {
    if (
        $(".teamwant-redis-table input").length
        && $(".card-footer .btn-primary").length
        && $("#saveAdminRedisConfigurationRow").length
    ) {
        let anyChangeInRedis = 0;

        $(".teamwant-redis-table input").on("change", function () {
            anyChangeInRedis = 1;
        });

        $("#twredis_prefix").on("change", function () {
            anyChangeInRedis = 1;
        });

        $(
            "#form_twredis_use_cache_admin_0, #form_twredis_use_cache_admin_1" +
            ", #form_twredis_use_prefix_0, #form_twredis_use_prefix_1" +
            ", #form_twredis_use_multistore_0, #form_twredis_use_multistore_1"
        ).on("click", function () {
            anyChangeInRedis = 1;
        });

        $(".card-footer .btn-primary").click(function (e) {
            if (anyChangeInRedis) {
                var c = confirm(
                    tw_redis_lang_save_change_on_performance
                );
                if (!c) {
                    e.preventDefault();
                    return;
                }
            }
        });

        $("#saveAdminRedisConfigurationRow").click(function (e) {
            anyChangeInRedis = 0;
        });
    }
}
Editor is loading...
Leave a Comment