Your IP : 52.15.222.71


Current Path : /home/bitrix/ext_www/easy-comfort.com.ua/local/modules/webprofy.importer/js/
Upload File :
Current File : /home/bitrix/ext_www/easy-comfort.com.ua/local/modules/webprofy.importer/js/script.js

$(document).ready(function () {
    //Загрузка селектов для выбранного конфила
    $('select#template').on('change', function (event) {
        var ajaxUrl = $('form#importForm').attr('action');
        var value = $(event.target).val();
        var data = {
            'step_two': true,
            'template': value
        };
        var sectionStepTwo = $('section#step_two');
        $(sectionStepTwo).empty();

        if((typeof value != "undefined") && (typeof ajaxUrl != "undefined")){
            $.post(ajaxUrl, data,  function( data ) {
                $(sectionStepTwo).append(data);
                changeSettingsSelector();
            });
        }
    });

    function changeSettingsSelector() {
        $('select.reference').on('change', function (event) {
            var allSelect = $('select.reference');
            var countValue = 0;
            var nextStepContainer = $('section#step_three');
            $.each(allSelect, function (i, item) {
                if($(item).val()){
                    countValue++;
                }
            });

            if(countValue == allSelect.length){
                $(nextStepContainer).removeClass('is_hidden');
            }else{
                $(nextStepContainer).addClass('is_hidden');
            }
        });
    }

    $('form#importForm').on('submit', function (event) {
        event.preventDefault();

        var ajaxUrl = $(event.target).attr('action');
        var data = $(event.target).serialize();

        checkStatus();
        $.post(ajaxUrl, data,  function( data ) {
            checkStatus();
        });

    });


    function checkStatus() {
        clearTimeout(window.reportWatcher);
        var logContainer = $('div.import-container__log');
        window.reportWatcher = setTimeout(function () {
            $.ajax({
                url: "/local/modules/webprofy.importer/tmp.log?clear_cache=Y",
                dataType: "html",
                success: function (data) {
                    if (data) {
                        $(logContainer).empty();
                        $(logContainer).html(data);
                    }else{
                        clearTimeout(window.reportWatcher);
                    }
                },
                error: function () {
                    clearTimeout(window.reportWatcher);
                }
            });
        }, 1000);
    }

});