$(function () {
    //获取官方在线模板
    function showTemplateList() {
        $.ajax({
            type: "POST",
            url: "Ajax/TemplateDispose.ashx",
            data: { 'com': 'geteoyootemplate' },
            datatype: "json",
            beforeSend: function (data, textStatus) {
                $("#templateListBox").html("<div class=\"Q B text_centent\">模板正在远程获取中...</div>")
            },
            success: function (data, textStatus) {
                var JosnData = eval(data);
                $("#templateListBox").html("");
                var ShowHtml = "";
                if (JosnData != null) {
                    if (JosnData.length > 0) {
                        for (var i = 0; i < JosnData.length; i++) {
                            ShowHtml += "<li>";
                            ShowHtml += "<div class=\"pic\"><img src=\"" + JosnData[i].pic + "\" /></div>";
                            ShowHtml += "<div class=\"info\">";
                            ShowHtml += "名称：<span title=\"快速安装模板：" + JosnData[i].name + "\" class=\"D\">" + JosnData[i].name + "</span><br />";
                            ShowHtml += "分类：<span class=\"R\">" + JosnData[i].classname + "</span><br />";
                            ShowHtml += "版本：<span class=\"V\">" + JosnData[i].editionname + "</span><br />";
                            ShowHtml += "时间：<span class=\"R\">" + JosnData[i].updatetime + "</span>";
                            ShowHtml += "</div>";
                            ShowHtml += "<div class=\"helper\">";
                            ShowHtml += "<a class=\"lv\" rel=\"install\" filename=\"" + JosnData[i].filename + "\" title=\"在线安装模板：" + JosnData[i].name + "\" href=\"" + JosnData[i].url + "\">在线安装模板</a>";
                            ShowHtml += "</div>";
                            ShowHtml += "</li>";
                        }
                        //数量
                        $("#templateNumber").text(JosnData.length);
                    } else {
                        ShowHtml += "<li>暂无模板</li>";
                    }
                    $("#templateListBox").html(ShowHtml);
                }
            },
            error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
        })
    }

    showTemplateList();

    //在线安装模板
    $("a[rel='install']").live('click', function () {
        var $delObject = $(this);
        if (confirm("确定要" + $delObject.attr("title") + "吗？")) {
            $.ajax({
                type: "POST",
                url: "Ajax/TemplateDispose.ashx",
                data: { 'com': 'installtemplate', 'downloadurl': $delObject.attr("href"), 'filename': $delObject.attr("filename") },
                datatype: "json",
                beforeSend: function (data, textStatus) {
                    showMsg("[ " + $delObject.attr("title") + " ]... ", true);
                },
                success: function (data, textStatus) {
                    if (data != "0") {
                        location.href = "template_manage.aspx";
                    } else {
                        alert("下载失败!");
                    }
                    showMsg("", false);
                },
                error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
            })
        }
        return false;
    });

});