<tr class="body">
    <td class="list_td">{$lang.sc_compile_sass}</td>
    <td class="list_td" align="center">
        <input type="button" id="sc_compile" value="{$lang.sc_compile}" style="margin: 0;width: 100px;" />
    </td>
</tr>
<tr>
    <td style="height: 5px;" colspan="3"></td>
</tr>

<script>
    {literal}
    $(function(){
        "use strict";

        var unknownErrorMessage = "{/literal}{$lang.sc_contact_support}{literal}";
        var InitialData = function(){
            this.item = 'sc_compile';
            this.ignore_backup = false;
            this.ignore_changes = false;
        };

        var handleErrors = function(message, reason){
            var extraData = new InitialData();

            if (reason) {

                if(reason == 'backup') extraData.ignore_backup = true;
                if(reason == 'modified') extraData.ignore_changes = true;

                Ext.MessageBox.confirm(lang['confirm'], message, function(btn){
                    if ( btn == 'yes' ) {
                        handleClick(extraData)
                    } else {
                        buttonReset();
                        $.post(rlConfig['ajax_url'], {
                            item: 'sc_clear_tmp'
                        });
                    }
                });
            } else {

                printMessage('error', message);
                buttonReset();
                $.post(rlConfig['ajax_url'], {
                    item: 'sc_clear_tmp'
                });
            }
        };

        var handleSuccess = function(message){

            printMessage('notice', message);
            buttonReset();
        };

        var handleResponse = function(response){

            response = JSON.parse(response);

            if(!response) {
                printMessage('error', unknownErrorMessage);
                buttonReset();
                return false;
            }
            if(response.status == 'error') handleErrors(response.message, response.reason);
            if(response.status == 'ok') handleSuccess(response.message);
        };

        var handleClick = function(data){

            $.post(rlConfig['ajax_url'], data, handleResponse);
        };

        var $button = $('#sc_compile');

        var buttonReset = function(){

            $button.data('clicked', false);
            $button.val('{/literal}{$lang.sc_compile}{literal}')
        };
        $button.click(function(){

            if($button.data('clicked') == true) return false;

            $button.data('clicked', true);
            $button.val('{/literal}{$lang.loading}{literal}');

            handleClick(new InitialData());
        });
    });
    {/literal}
</script>