var dtLang = {
    "sProcessing" : "处理中...",
    "lengthMenu" : '显示 <select>' + '<option value="5">5</option>'
        + '<option value="20">20</option>'
        + '<option value="100">100</option>'
        + '<option value="-1">全部</option>' + '</select> 项结果',
    "sZeroRecords" : "没有匹配结果",
    "sInfo" : "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
    "sInfoEmpty" : "显示第 0 至 0 项结果，共 0 项",
    "sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
    "sInfoPostFix" : "",
    "sSearch" : "搜索:",
    "sUrl" : "",
    "sEmptyTable" : "表中数据为空",
    "sLoadingRecords" : "载入中...",
    "sInfoThousands" : ",",
    "oPaginate" : {
        "sFirst" : "首页",
        "sPrevious" : "上页",
        "sNext" : "下页",
        "sLast" : "末页"
    },
    "oAria" : {
        "sSortAscending" : ": 以升序排列此列",
        "sSortDescending" : ": 以降序排列此列"
    }
};

var initDoAndRepoCount = function(){
    console.log("initDoAndRepoCount");
    var str = getUrl() + "/view?action=count";
    console.log(str);

    $.ajax({
        url : str,
        type: "GET",
        dataType : "json"
    }).done(function(result) {
        showDoAndRepoCount(result);
    });
};

var showDoAndRepoCount = function(data){
    console.log(data);
    document.getElementById("DOCount").value = data.doCount;
    document.getElementById("RepoCount").value = data.repoCount;

    console.log("showDoAndRepoCount");

    //DO
    var tableHead = "<table id='DODivTab' class='table display row-border'><thead><tr><th>序号</th><th>条目</th></tr></thead><tbody>";
    var tableTail = "</tbody></table>";
    var html = tableHead;
    for (var i = 0; i < data.doIDList.length; i++) {
        html += "<tr><td>";
        html += (i + 1);
        html += ("</td><td>");
        html += data.doIDList[i];
        html += "</td></tr>";
    }
    html += tableTail;
    $("#DODiv").html(html);
    $("#DODivTab").DataTable(
        {
            "language" : dtLang,
            "rowCallback" : function(row, data, displayNum, displayIndex,
                                     dataIndex) {

            },
            "headerCallback" : function(thead, data, start, end, display) {
                $(thead).css("background", primaryColor);
                $(thead).css("color", "white");
                $(thead).children().css("background", primaryColor);
                $(thead).children().css("color", "white");
            },
            scrollCollapse : false,
            paging : true,
            pageLength : 5,
            order : [ [ 0, 'desc' ] ],
            "columnDefs" : [
                {
                    "targets" : 1,
                    "render" : function(data, type, row, meta) {
                        if (data.length > 35)
                            return "<span title='" + data + "'>"
                                + data.substring(0, 35)
                                + "  ...</span>";
                        else
                            return data;
                    }
                },
            ]
        });

    //Repo
    var tableHeadRepo = "<table id='RepoDivTab' class='table display row-border'><thead><tr><th>序号</th><th>条目</th></tr></thead><tbody>";
    var tableTailRepo = "</tbody></table>";
    var htmlRepo = tableHeadRepo;
    for (var i = 0; i < data.repoIDList.length; i++) {
        htmlRepo += "<tr><td>";
        htmlRepo += (i + 1);
        htmlRepo += ("</td><td>");
        htmlRepo += data.repoIDList[i];
        htmlRepo += "</td></tr>";
    }
    htmlRepo += tableTailRepo;
    $("#RepoDiv").html(htmlRepo);
    $("#RepoDivTab").DataTable(
        {
            "language" : dtLang,
            "rowCallback" : function(row, data, displayNum, displayIndex,
                                     dataIndex) {

            },
            "headerCallback" : function(thead, data, start, end, display) {
                $(thead).css("background", primaryColor);
                $(thead).css("color", "white");
                $(thead).children().css("background", primaryColor);
                $(thead).children().css("color", "white");
            },
            scrollCollapse : false,
            paging : true,
            pageLength : 5,
            order : [ [ 0, 'desc' ] ],
            "columnDefs" : [
                {
                    "targets" : 1,
                    "render" : function(data, type, row, meta) {
                        if (data.length > 35)
                            return "<span title='" + data + "'>"
                                + data.substring(0, 35)
                                + "  ...</span>";
                        else
                            return data;
                    }
                },
            ]
        });

};