<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MenuList.aspx.cs" Inherits="Medical.MSystem.SysMenu.MenuList" %>

<%@ Register Src="../../Controls/Condition.ascx" TagName="Condition" TagPrefix="ucCondition" %>
<%@ Register Src="../../Controls/QueryButton.ascx" TagName="QueryButton" TagPrefix="ucQueryButton" %>
<%@ Register Src="../../Controls/Pager.ascx" TagName="Pager" TagPrefix="ucPager" %>
<%@ Register Src="../../Controls/Grid.ascx" TagName="Grid" TagPrefix="ucGrid" %>
<!DOCTYPE html>
<html>
<head>
    <title><%=ModuleName%></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />

    <%--<script src="../../Scripts/jquery-1.11.1.min.js" type="text/javascript"></script>--%>

    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/myLib/jsHelper_Form.js" type="text/javascript"></script>
    <script src="../../js/myLib/Pager.js" type="text/javascript"></script>
    <script src="../../js/myLib/Grid.js" type="text/javascript"></script>

    <script>
        function Menu() {
            this.url = "MenuList.aspx";
            this.dialogUrl = "/MSystem/SysMenu/MenuForm.aspx";
            this.dialogFormName = "Menu_Form";
            this.grid = null;
            this.init();
        }
        Menu.prototype = {
            init: function() {
                var pager = new Pager("gridPager");
                this.grid = new Grid({ id: "grid", url: this.url, pager: pager, bindFun: this.bindData });
                this.grid.search();
                this.bindEvents();
            },
            bindEvents: function() {
                var self = this, title = '<%=ModuleName %>';
                $("#btnAdd").click(function() {
                    top.openDialog(self.dialogUrl, self.dialogFormName, title + ' - 添加', 700, 280, 50, 50);
                });
                $("#btnQuery").click(function() {
                    self.grid.search(true);
                });
                self.grid.control.click(function(e) {
                    var target = $(e.target);
                    if (target.is("input")) {
                        var data = target.parent().parent().data("data");
                        switch (target.val()) {
                            case "修改":
                                top.openDialog(self.dialogUrl + "?key=" + data.ID, self.dialogFormName, title + ' - 编辑', 700, 280, 50, 50);
                                break;
                            case "删除":
                                self.remove(data);
                                break;
                        }
                    }
                });
            },
            remove: function(data) {
                var self = this;
                top.showConfirmMsg(this.removeTip(data), function(r) {
                    if (r) {
                        $.get(this.url, { action: "remove", id: data.ID }, function(data) {
                            if (data == "success") {
                                top.showTipsMsg('删除成功!', 0, 5000);
                                self.grid.search();
                            } else {
                                top.showTipsMsg('删除成功!', 1, 5000);
                            }
                        });
                    }
                });
            },
            bindData: function(tr, data) {
            tr.append($("<td>").html("<input type='button' class='pt-button active' value='修改' /><input type='button' class='pt-button active' value='删除' />")).append($("<td>").html(data.ParentID))
                .append($("<td>").html(data.Name))
                .append($("<td>").html(data.Url))
                .append($("<td>").html(data.Level))
                .append($("<td>").html(data.NodePath))
                .append($("<td>").html(data.IsStart))
                .append($("<td>").html(data.IsUse));
            },
            removeTip: function(data) {
                return "确定要删除[菜单名称]为[" + data.Name + "]的菜单信息吗?";
            }
        };
        $(function() {
            new Menu();
        });
    </script>

</head>
<body>
    <div class="pt-panel">
        <strong><%=ModuleName%></strong>
        <form name="fCondition" class="pt-padding">
        <div class="pt-padding" >
            <ucQueryButton:QueryButton ID="btnAdd" Text="新增" runat="server" />
            <ucQueryButton:QueryButton ID="btnQuery" Text="查询" runat="server" />
        </div>
        <ucCondition:Condition ID="Condition1" Text="菜单名称" Name="name" runat="server" />
        </form>
    </div>
    <div class="pt-panel pt-below">
        <strong>查询一览</strong>
        <div class="pt-grid_frame">
            <ucGrid:Grid ID="grid" runat="server" />
        </div>
        <ucPager:Pager ID="gridPager" runat="server" />
    </div>
</body>
</html>
