<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="functionmanage.aspx.cs" Inherits="HySoft.BaseCallCenter.Web.sysmanage.functionmanage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>字典管理</title>
     <link href="../scripts/ui/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="../scripts/ui/json2.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/core/base.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/ligerui.min.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/Tab/css/tab.css" rel="stylesheet" type="text/css" />
    <link href="../scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/ui/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerLayout.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="../scripts/ui/js/plugins/ligerMenu.js" type="text/javascript"></script>
    <script src="../scripts/CustomersData.js" type="text/javascript"></script>
    <link href="../scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="../images/style.css" rel="stylesheet" type="text/css" />
    <script src="../scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        var menu;
        var menucategory;
        var actionNode;
        var actionRow;
        var categorytree = null;
        var gridlist = null;
        var singleClick;
        var iconcls;
        var treeClick;
        $(function () {
            $("#layout1").ligerLayout({
                leftWidth: 200
            });
            InitMenu();
            InitCategory();
            InitList("","");
        });
        function InitMenu() {
            menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '增加', click: itemclick, icon: 'add' },
            { text: '修改', click: itemclick, icon: 'modify' },
            { line: true },
            { text: '删除', click: itemclick, icon: 'delete' }
            ]
            });
            menucategory = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '增加同级功能', click: itemcategoryclick, icon: 'add' },
            { text: '增加子级功能', click: itemcategoryclick, icon: 'add' },
            { text: '修改', click: itemcategoryclick, icon: 'modify' },
            { line: true },
            { text: '删除', click: itemcategoryclick, icon: 'delete' }
            ]
            });
        }
        function itemcategoryclick(item, i) {
            switch (i) {
                case 0:
                    AddCategory("0");
                    break;
                case 1:
                    AddCategory("1");
                    break;
                case 2:
                    ModifyCategory();
                    break;
                case 3:
                    DeleteCategory();
                    break;
                default:
                    break;
            }
        }
        function itemclick(item, i) {
            switch (i) {
                case 0:
                    Add();
                    break;
                case 1:
                    Modify();
                    break;
                case 2:
                    Delete();
                    break;
                default:
                    break;
            }
        }
        function InitCategory() {

            try {
                categorytree = $("#treecategory").ligerTree({
                    checkbox: false,
                    url: 'ajax/functionmanage.ashx?action=gettreelist',
                    isExpand: false,
                    onContextmenu: function (node, e) {
                        actionNode = node;
                        iconcls = node.data.IconCls;
                        categorytree.selectNode(actionNode.data.id);
                        menucategory.show({ top: e.pageY, left: e.pageX });
                        return false;
                    },
                    onClick: function (node, e) {
                        treeClick = node.data.IconCls;
                        if (node.data.IconCls == "4") {
                            InitList(node.data.id, "anniu");
                        } else {
                            InitList(node.data.id, "");
                        }
                    }
                });
            }
            catch (e) {
                alert(e.Message);
            }
        }
        function GetSql() {
            var sql = "";
//            if (document.getElementById("F_DictionaryFlag").value != "") {
//                sql += "&flag=" + escape(document.getElementById("F_DictionaryFlag").value);
//            }
//            if (document.getElementById("F_Name").value != "") {
//                sql += "&name=" + document.getElementById("F_Name").value;
//            }
            return sql;
        }
        function InitList(id,type) {
            var sql = GetSql();
            if (type == "anniu")
            {
                try {
                    gridlist = $("#divDataList").ligerGrid({
                        checkbox: true,
                        height: '95%',
                        columns: [
                { display: 'ID', name: '_f_id', width: '1%', hide: 'ID' },
                { display: '按钮代码', name: '_f_optcode', align: 'left', width: '25%' },
                { display: '按钮名称', name: '_f_optname', width: '25%' },
                { display: '备注', name: '_f_remark', width: '49%' }
                ],
                        onContextmenu: function (node, e) {
                            try {
                                actionRow = node;
                                menu.show({ top: e.pageY, left: e.pageX });
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                            return false;
                        },
                        url: 'ajax/functionmanage.ashx?action=getanniulist&id=' + id + sql, pageSize: 10, rownumbers: true,
                        onSelectRow: function (data, rowindex, rowobj) {
                            singleClick = data._f_id;
                        }
                    });
                }
                catch (e) {
                    alert(e.Message);
                } 
            } else {
                try {
                    gridlist = $("#divDataList").ligerGrid({
                        checkbox: true,
                        height: '95%',
                        columns: [
                { display: 'ID', name: '_f_functionid', width: '1%', hide: 'ID' },
                { display: '功能名称', name: '_f_name', align: 'left', width: '18%' },
                { display: '功能代码', name: '_f_functioncode', width: '15%' },
                { display: '功能地址', name: '_f_opturl', width: '25%' },
                { display: '功能状态', name: '_f_stateflag', width: '15%', render: function (rowdata, rowindex) {
                    if (rowdata._f_stateflag == "1") { return '已启用'; }
                    else { return '未启用'; }
                }
                },
                { display: '备注', name: '_f_remark', width: '16%' },
                { display: '排序编号', name: '_f_sort', width: '10%' }
                ],
                        onContextmenu: function (node, e) {
                            try {
                                actionRow = node;
                                //gridlist.select(node);
                                menu.show({ top: e.pageY, left: e.pageX });
                            }
                            catch (e) {
                                alert(e.Message);
                            }
                            return false;
                        },
                        url: 'ajax/functionmanage.ashx?action=getlist&id=' + id + sql, pageSize: 10, rownumbers: true,
                        onSelectRow: function (data, rowindex, rowobj) {
                            singleClick = data._f_functionid;
                        }
                    });
                }
                catch (e) {
                    alert(e.Message);
                } 
            }
            gridlist.changePage('first');
            $("#pageloading").hide();
        }
        function AddCategory(type) {
            if (iconcls != "4") {
                //获取选择的分类
                var node = categorytree.getSelected();
                if (node) {
                    $.ligerDialog.open({ url: 'functiontreeedit.aspx?getPuction=Add&iconcls=' + iconcls + '&type=' + type + '&id=' + node.data.id, title: '添加功能', height: 430, width: 450, isResize: true
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要添加项');
                }
            } else { $.ligerDialog.error('按钮功能不能在此添加'); }
        }
        function ModifyCategory() {
            if (iconcls != "4") {
                //获取选择的分类
                var node = categorytree.getSelected();
                if (node) {
                    $.ligerDialog.open({ url: 'functiontreeedit.aspx?getPuction=Edit&id=' + node.data.id, title: '修改[<font color="red">' + node.data.text + '</font>]功能', height: 430, width: 450, isResize: true
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要修改项');
                }
            } else { $.ligerDialog.error('按钮功能不能在此修改'); }
        }
        function DeleteCategory() {
            if (iconcls != "4") {
                //获取选择的分类
                var node = categorytree.getSelected();
                if (node) {
                    $.ligerDialog.confirm('确定要删除【<font color="red">' + node.data.text + '</font>】吗？', function (yes) {
                        if (yes) {
                            $.post("ajax/functionmanage.ashx?action=deletetree&id=" + node.data.id, function (data) {
                                if (data == "success") {
                                    $.ligerDialog.success('删除成功');
                                    InitCategory();
                                }
                                else {
                                    $.ligerDialog.error('删除失败');
                                }
                            });
                        }
                        else {
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要删除的项');
                }
            } else { $.ligerDialog.error('按钮不能在此删除'); }
        }
        function Add() {
            if (treeClick != "4") {
                //获取选择的分类
                var node = categorytree.getSelected();
                if (node) {
                    $.ligerDialog.open({ url: 'functionanniuedit.aspx?getPuction=Add&id=' + node.data.id, title: '添加按钮信息', height: 400, width: 700, isResize: true
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要添加的分类');
                }
            } else { $.ligerDialog.error('按钮功能不能在此添加'); }
        }
        function Modify() {
            if (treeClick == "4" && treeClick != "" && treeClick != undefined) {
                if (singleClick == "" || singleClick == undefined) {
                    alert("请选择修改行！");
                } else {
                    $.ligerDialog.open({ url: 'functionanniuedit.aspx?getPuction=Edit' + '&singleFlage=' + singleClick, title: '修改按钮信息', height: 400, width: 700, isResize: true
                    });
                }
            } else { $.ligerDialog.error('功能不能在此修改'); }
        }
        function Delete() {
            if (treeClick == "4" && treeClick != "" && treeClick != undefined) {
                try {
                    //获取选择的行
                    var rows = gridlist.getSelectedRows();
                    if (rows.length > 0) {
                        $.ligerDialog.confirm('确定要批量删除选择的记录吗？', function (yes) {
                            if (yes) {
                                try {
                                    var arr = new Array();
                                    var i = 0;
                                    for (var i = 0; i < rows.length; i++) {
                                        arr[i] = rows[i]._f_id;
                                    }
                                    $.post("ajax/functionmanage.ashx?action=deletelist&arrid=" + arr.toString(), function (data) {
                                        if (data == "success") {
                                            $.ligerDialog.success('删除成功');
                                            InitList("", "");
                                            InitCategory();
                                        }
                                        else {
                                            $.ligerDialog.error('删除失败');
                                        }
                                    });
                                }
                                catch (e) {
                                    alert(e.Message);
                                }
                            }
                            else {
                            }
                        });
                    }
                    else {
                        $.ligerDialog.error('没有选择要删除的行');
                    }
                }
                catch (e) {
                    $.ligerDialog.error(e.Message);
                }
            } else { $.ligerDialog.error('功能不能在此删除'); }
        }
        function ZiShiYing() {
            InitList("");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="tools_box">
        <div class="tools_bar">
            <a class="tools_btn" href="#" onclick="Add();"><span><b class="add">添加按钮</b></span>
            </a><a class="tools_btn" href="#" onclick="Modify();"><span><b class="modify">修改按钮</b></span>
            </a><a class="tools_btn" href="#" onclick="Delete();"><span>
                    <b class="delete">删除按钮</b></span> </a>
            <div class="search_box">
              <%--  字典标识：<asp:TextBox ID="F_DictionaryFlag" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                字典值：<asp:TextBox ID="F_Name" runat="server" CssClass="txtInput"></asp:TextBox>&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="InitList();" />--%>
            </div>
        </div>
    </div>
    <div id="layout1">
        <div position="left" title="功能类别" style="overflow:auto; height:95%;">
            <table cellpadding="0" cellspacing="0" border="0" height="95%">
              <%--  <tr height="30px">
                    <td>
                        <div class="tools_box" style="height:30px;">
                            <div class="tools_bar" style="text-align: left; padding-left:10px;">
                                    <input id="btnAddCategory" type="button" value="添加同级功能" class="btnSearch" onclick="AddCategory();" />&nbsp;&nbsp;
                                    <input id="Button1" type="button" value="添加子级功能" class="btnSearch" onclick="AddCategory();" />&nbsp;&nbsp;
                                    <input id="btnModifyCategory" type="button" value="修 改" class="btnSearch" onclick="ModifyCategory();" />&nbsp;&nbsp;
                                    <input id="btnDeleteCategory" type="button" value="删 除" class="btnSearch" onclick="DeleteCategory();" />
                            </div>
                        </div>
                    </td>
                </tr>--%>
                <tr height="95%" valign="top">
                    <td>
                        <ul id="treecategory">
                            
                        </ul>
                    </td>
                </tr>
            </table>
        </div>
        <div position="center" title="功能列表" onresize="ZiShiYing();">
            <div id="divDataList">
            </div>
        </div>
    </div>
    </form>
</body>
</html>
