{template "header.html"}

<div class="note note-danger">
    <p>{dr_lang('更改系统配置之后需要重新生成一次缓存文件')}</p>
</div>

<div class="right-card-box">
<div class="table-scrollable">
<table class="table table-striped table-bordered table-hover table-checkable dataTable">
    <thead>
    <tr>
        <th width="55"> </th>
        <th width="350"> {dr_lang('更新项目')} </th>
        <th> </th>
    </tr>
    </thead>
    <tbody>
    {loop $list $id $t}
    <tr>
        <td>
            <span class="badge badge-success"> {$id+1} </span>
        </td>
        <td>
            {dr_lang($t[0])}
        </td>
        <td style="overflow:auto">
            <label>
                <a href="javascript:my_update_cache('{$id}', '{$t[1]}');" class="btn red btn-xs"><i class="fa fa-refresh"></i> {dr_lang('立即更新')} </a>
            </label>
            <label id="dr_{$id}_result" >

            </label>
        </td>
    </tr>
    {/loop}

    </tbody>
</table>
</div>
</div>

<script>
    function my_update_cache(id, m) {
        var obj = $('#dr_'+id+'_result');
        obj.html("<img style='height:17px' src='{THEME_PATH}assets/images/loading-0.gif' />");

        if (m == 'update_attachment') {
            my_update_attachment(id, 0);
        } else {
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "{SELF}?c=api&m=cache&id="+m,
                success: function (json) {
                    if (json.code == 0) {
                        obj.html('<font color="red">'+json.msg+'</font>');
                    } else {
                        obj.html('<font color="green">{dr_lang("更新完成")}</font>');
                    }
                },
                error: function(HttpRequest, ajaxOptions, thrownError) {
                    obj.html('<a href="javascript:dr_show_file_code(\'{dr_lang('查看日志')}\', \'{dr_url('error/log_show')}\');" style="color:red">{dr_lang("系统崩溃，请将错误日志发送给官方处理")}</a>');
                }
            });
        }


    }
    function my_update_attachment(id, page) {
        var obj = $('#dr_'+id+'_result');
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "{SELF}?c=api&m=cache&id=update_attachment&page="+page,
            success: function (json) {
                if (json.code == 0) {
                    obj.html('<font color="red">'+json.msg+'</font>');

                } else {
                    if (json.data == 0) {
                        obj.html('<font color="green">'+json.msg+'</font>');
                    } else {
                        my_update_attachment(id, json.data);
                        obj.html('<font color="blue">'+json.msg+'</font>');
                    }
                }
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                obj.html('<a href="javascript:dr_show_file_code(\'{dr_lang('查看日志')}\', \'{dr_url('error/log_show')}\');" style="color:red">{dr_lang("系统崩溃，请将错误日志发送给官方处理")}</a>');
            }
        });
    }
</script>
{template "footer.html"}