<%inherit file="base.html"/>

<%def name="head()">
<script>
function dumpdb(){
    $.get("/backup/dump", {}, function (ev) {
        console.log(ev);
        console.log(ev.msg);
        window.location.reload();
        alert(ev.msg);
    }, "json");
}

function restoredb(bakfs){
    if (!confirm("确认恢复操作吗？")) {
        return;
    }
    $.post("/backup/restore", {bakfs:bakfs}, function (ev) {
        console.log(ev);
        console.log(ev.msg);
        window.location.reload();
        alert(ev.msg);
    }, "json");
}

function deletefs(bakfs){
    if (!confirm("确认删除操作吗，此操作不可恢复？")) {
        return;
    }
    $.post("/backup/delete", {bakfs:bakfs}, function (ev) {
        console.log(ev);
        console.log(ev.msg);
        window.location.reload();
        alert(ev.msg);
    }, "json");
}
</script>
</%def>

<%def name="body()">
<div class="panel panel-default">
    <div class="panel-heading"><span class="glyphicon glyphicon-th"></span> 数据库备份管理</div>
    <div class="panel-body">
        <form id="query_form" class="form-horizontal form-well" role="form" action="/ops/opslog" method="post">
            <div class="form-group">
                <label for="operator_name" class="col-md-4 control-label">备份目录</label>
                <div class="col-md-4">
                    <input type="text" id="backup_path" name="backup_path" class="form-control" value="${backup_path}" readonly="readonly">
                </div>           
                <div class="col-md-4">
                    <button type="button" onclick="dumpdb();" class="btn btn-primary">立即备份</button>
                </div>
            </div>   
        </form>

        <table class="table table-hover">
            <thead>
            <tr>
                <th width="60%">备份名称</th>
                <th width="40%">操作</th>
            </tr>
            </thead>
            <tbody>
            % for backup in backups:
            <tr>
                <td>${backup}</td>
                <td>
                    <a href="javascript:deletefs('${backup}')">删除</a> | 
                    <a href="/backup/download/${backup}">下载</a> | 
                    <a href="javascript:restoredb('${backup}')">恢复</a>
                </td>
            </tr>
            % endfor
            </tbody>
        </table>
    </div>
</div>


</%def>
