<div class="switch-btn {if $one_module.status eq "0"}switch-on{/if}" data-id="#dadata_module-1" id="dadata__switch-btn"><div></div></div>
<input type="checkbox" hidden="hidden" name="dadata_module_status" id="dadata_module_status" value="{if $one_module.status eq "0"}1{else}0{/if}"/>
<script>
    $(function () {
        var OneCsyncCheckStatus = $('#dadata_module_status');
        var OneCsyncModuleLink = $('#module__dadata');
        $('#dadata__switch-btn').click(function () {
            var $this = $(this);
            if ($this.hasClass('switch-on')) {
                jconfirm('{$lang.disabled_module_alert}', function () {
                    $this.toggleClass('switch-on');
                    $this.trigger('off.switch');

                });
            } else {
                $this.toggleClass('switch-on');
                $this.trigger('on.switch');
            }
        });
        $('#dadata__switch-btn').on('on.switch', function () {
            // Посылаем запрос на включение модуля
            $.ajax({
                url: '{$config.site_url}/modules/dadata/request.php',
                type: 'POST',
                data: {
                    csrf: '{$csrf}',
                    activate: 0
                },
                beforeSend: function() {
                    makePreloader();
                },
                success: function (resp) {
                    destroyPreloader();
                    OneCsyncCheckStatus.val('1');
                    OneCsyncModuleLink.removeClass('disabled');
                    location.href = OneCsyncModuleLink.attr('href');
                }
            });
        });
        $('#dadata__switch-btn').on('off.switch', function () {
            // Посылаем запрос на выключение модуля
            $.ajax({
                url: '{$config.site_url}/modules/dadata/request.php',
                type: 'post',
                data: {
                    csrf: '{$csrf}',
                    activate: 1
                },
                beforeSend: function() {
                    makePreloader();
                },
                success: function (resp) {
                    destroyPreloader();
                    OneCsyncCheckStatus.val('0');
                    OneCsyncModuleLink.addClass('disabled');
                }
            });
        });
    });
</script>