<div class="switch-btn {if $one_module.status eq '0'}switch-on{/if}" data-id="#1csync_module-1" id="1csync__switch-btn"><div></div></div>
<input type="checkbox" hidden="hidden" name="1csync_module_status" id="1csync_module_status" value="{if $one_module.status eq '0'}1{else}0{/if}"/>
<script>
    $(function () {
        var OneCsyncCheckStatus = $('#1csync_module_status');
        var OneCsyncModuleLink = $('#module__1csync');
        $('#1csync__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');
            }
        });
        $('#1csync__switch-btn').on('on.switch', function () {
            // Посылаем запрос на включение модуля
            $.ajax({
                url: '{$config.site_url}/edit_modules.php?module=1csync',
                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');
                }
            });
        });
        $('#1csync__switch-btn').on('off.switch', function () {
            // Посылаем запрос на выключение модуля
            $.ajax({
                url: '{$config.site_url}/edit_modules.php?module=1csync',
                type: 'post',
                data: 'activate=1&csrf={$csrf}',
                beforeSend: function() {
                    makePreloader();
                },
                success: function (resp) {
                    destroyPreloader();
                    OneCsyncCheckStatus.val('0');
                    OneCsyncModuleLink.addClass('disabled');
                }
            });
        });
    });
</script>