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

<!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.8.3.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>
    <script src="/scripts/ui/js/plugins/ligerTextBox.js" type="text/javascript"></script>
    <script src="/scripts/ui/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="/scripts/function.js" type="text/javascript"></script>
    <script src="/scripts/utils.js" type="text/javascript"></script>
    <script src="/scripts/ui/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <link href="/scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <link href="/images/style.css" rel="stylesheet" type="text/css" />
    <link href="/scripts/ui/skins/Tab/css/grid.css" rel="stylesheet" type="text/css" />
    <link href="/scripts/ui/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .l-toolbar
        {
            background: none;
            height: 23px;
            border: 0px solid #9CBAE7;
            border-top: 0px solid #EFF7F7;
        }
        .tools_box
        {
            border: 1px solid #D6D6D6;
            border-bottom: 0px;
        }
    </style>
    <script type="text/javascript">
        var sort = 0;
        var itemcount = 0;
        var itemslist;
        var selectlist;
        function CloseThis() {
            parent.SaveRes();
        }
        $(function () {
            var a = $("#navtab1").ligerTab({
                showSwitch: false,
                contextmenu: false,
                onAfterSelectTabItem: function (targettabid) {
                }
            });
            LoadItemsList();
            LoadSelectList();
            $("#pageloading_bg,#pageloading").hide();
        });
        function LoadItemsList() {
            var fwidth = $("#form1").width() * 0.5;
            var dbtype = document.getElementById("dropDBType").value;
            var id = document.getElementById("txtId").value;
            itemslist = $("#divItemsList").ligerGrid({
                height: 310,
                width: fwidth,
                checkbox: true,
                columns: [
                { display: '操作', width: '35', frozen: true, name: '_f_attributeid', render: function (rowdata, rowindex, value) {
                    return "<img src='../scripts/ui/skins/icons/right.png' onclick='SelectInItem(\"" + rowdata._f_attributeid + "\");' style='width:20px;cursor:hand;' title='选入' />";
                }
                },
                { display: '属性名称', frozen: true, name: '_f_name', width: 70 },
                { display: '长度', name: '_f_length', width: 60, render: function (rowdata, rowindex) {
                    if (rowdata._f_length == 0) { return ''; }
                    else if (rowdata._f_length == -1) { return '超长文本'; }
                    else { return rowdata._f_length; }
                }
                },
                { display: '数据类型', name: '_f_dbtypename', width: 60, render: function (rowdata, rowindex) {
                    if (rowdata._f_dbtypename == 'nvarchar') { return '文本'; }
                    else if (rowdata._f_dbtypename == 'int') { return '整数'; }
                    else if (rowdata._f_dbtypename == 'datetime') { return '日期'; }
                    else { return rowdata._f_dbtypename; }
                }
                },
                { display: '数据字段', align: 'left', name: '_f_dbfieldlname', width: 100 }
                ],
                toolbar: {
                    items: [
                    { text: '选入', click: itemclick2, icon: 'rightall' }
                    ]
                },
                url: 'ajax/callplanwebset.ashx?action=getitemlist&taskid=' + id + '&&dbtype='+dbtype, pageSize: 50, pageSizeOptions: [10, 20, 50], rownumbers: true,
                
            });
            $("#pageloading").hide();
        }
        function itemclick2(item) {
            switch (item.icon) {
                case "help":
                    break;
                case "rightall":
                    SelectAllInItem();
                    break;
                case "leftall":
                    SelectAllOutItem();
                    break;
            }
        }
        function LoadSelectList() {
            var id = document.getElementById("txtId").value;
            var fwidth = $("#form1").width() * 0.5-20;
            selectlist = $("#divSelectList").ligerGrid({
                height: 310,
                width: fwidth,
                checkbox: true,
                enabledEdit: true,
                onBeforeEdit: f_onBeforeEdit,
                onAfterEdit: f_onAfterEdit,
                columns: [
                { display: '操作', width: '35', name: '_f_id', render: function (rowdata, rowindex, value) {
                    return "<img src='../scripts/ui/skins/icons/left.png' onclick='SelectOutItem(\"" + rowdata._f_id + "\");' style='width:20px;cursor:hand;' title='移除' />";
                }
                },
                { display: '排序', width: '50', align: 'left', name: '_f_sort', render: function (rowdata, rowindex, value) {
                    if (value > sort) {
                        sort = value;
                    }
                    if (rowindex == 0)
                        return "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img id='xy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_id + "\",\"" + value + "\",\"1\");' src='../images/icon_desc.gif' title='下移' style='width:12px; cursor:hand;' />";
                    else
                        return "&nbsp;<img id='sy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_id + "\",\"" + value + "\",\"-1\");' src='../images/icon_asc.gif' title='上移' style='width:12px; cursor:hand;' />&nbsp;&nbsp;<img id='xy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_id + "\",\"" + value + "\",\"1\");' src='../images/icon_desc.gif' title='下移' style='width:12px; cursor:hand;' />";
                }
                },
                { display: '属性名称', name: '_f_name', editor: { type: 'text' }, width: 70 },
                { display: '长度', name: '_f_length', width: 60, render: function (rowdata, rowindex) {
                    if (rowdata._f_length == 0) { return ''; }
                    else if (rowdata._f_length == -1) { return '超长文本'; }
                    else { return rowdata._f_length; }
                }
                },
                { display: '数据类型', name: '_f_dbtypename', width: 60, render: function (rowdata, rowindex) {
                    if (rowdata._f_dbtypename == 'nvarchar') { return '文本'; }
                    else if (rowdata._f_dbtypename == 'int') { return '整数'; }
                    else if (rowdata._f_dbtypename == 'datetime') { return '日期'; }
                    else { return rowdata._f_dbtypename; }
                }
                },
                { display: '数据字段', align: 'left', name: '_f_dbfieldlname', width: 100 }
                ],
                toolbar: {
                    items: [
                    { text: '选出', click: itemclick2, icon: 'leftall' }
                    ]
                },
                url: 'ajax/callplanwebset.ashx?action=getselectitemlist&taskid=' + id, pageSize: 50, pageSizeOptions: [10, 20, 50, 100], rownumbers: true,
                onAfterShowData: function (data) {
                    itemcount = data.Total;
                    var imgindex = itemcount - 1;
                    try {
                        var imgid = "xy_" + imgindex;
                        document.getElementById("xy_" + imgindex).style.display = "none";
                    }
                    catch (e) {
                    }
                }
            });
            $("#pageloading").hide();
        }
        //编辑后事件
        function f_onAfterEdit(e) {
            var imgindex = itemcount - 1;
            try {
                var imgid = "xy_" + imgindex;
                document.getElementById("xy_" + imgindex).style.display = "none";
            }
            catch (ex) {
            }
            //更新数据
            var id = document.getElementById("txtId").value;
            var dataObj = selectlist.getRow(e.rowindex);
            if (dataObj) {
                var itemid = dataObj._f_id;
                var itemvalue = escape(dataObj._f_name);
                var optaction = "modifytemp";
                if (id != "") {
                    optaction = "modify";
                }
                try {
                    $.ajax({
                        type: "get",
                        url: "ajax/callplanwebset.ashx?action=" + optaction + "&taskid=" + id + "&itemid=" + itemid + "&itemvalue=" + itemvalue,
                        dataType: "html",
                        success: function (res) {
                            if (res == "success") {
                            //LoadSelectList();
                            } else {
                                $.ligerDialog.error("修改选项失败");
                            }
                        }
                    });
                }
                catch (e) {
                }
            }
            else {
                $.ligerDialog.error("没有选择要修改的项");
            }            
        }

        //编辑前事件
        function f_onBeforeEdit(e) {
            return true;
        }
        function SelectInItem(itemid) {
            var id = document.getElementById("txtId").value;
            var optaction = "addtemp";
            if (id != "") {
                optaction = "add";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/callplanwebset.ashx?action=" + optaction + "&taskid=" + id + "&itemid=" + itemid + "&sort=" + sort,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            LoadItemsList();
                            LoadSelectList();
                        } else {
                            $.ligerDialog.error("选入失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function SelectOutItem(itemid) {
            var id = document.getElementById("txtId").value;
            var optaction = "deletetemp";
            if (id != "") {
                optaction = "delete";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/callplanwebset.ashx?action=" + optaction + "&id=" + id + "&itemid=" + itemid + "&sort=" + sort,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            LoadItemsList();
                            LoadSelectList();
                        } else {
                            $.ligerDialog.error("选出失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function SelectAllInItem() {
            var id = document.getElementById("txtId").value;
            var optaction = "addalltemp";
            if (id != "") {
                optaction = "addall";
            }
            try {
                var rows = itemslist.getSelectedRows();
                if (rows.length > 0) {
                    var arr = new Array();
                    var i = 0;
                    for (var i = 0; i < rows.length; i++) {
                        arr[i] = rows[i]._f_attributeid;
                    }
                    $.ajax({
                        type: "get",
                        url: "ajax/callplanwebset.ashx?action=" + optaction + "&taskid=" + id + "&arrid=" + arr.toString() + "&sort=" + sort,
                        dataType: "html",
                        success: function (res) {
                            if (res == "success") {
                                LoadItemsList();
                                LoadSelectList();
                            } else {
                                $.ligerDialog.error("选入失败");
                            }
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要选入的试题');
                }
            }
            catch (e) {
            }
        }
        function SelectAllOutItem() {
            var id = document.getElementById("txtId").value;
            var optaction = "deletealltemp";
            if (id != "") {
                optaction = "deleteall";
            }
            try {
                var rows = selectlist.getSelectedRows();
                if (rows.length > 0) {
                    var arr = new Array();
                    var i = 0;
                    for (var i = 0; i < rows.length; i++) {
                        arr[i] = rows[i]._f_id;
                    }
                    $.ajax({
                        type: "get",
                        url: "ajax/callplanwebset.ashx?action=" + optaction + "&taskid=" + id + "&arrid=" + arr.toString() + "&sort=" + sort,
                        dataType: "html",
                        success: function (res) {
                            if (res == "success") {
                                LoadItemsList();
                                LoadSelectList();
                            } else {
                                $.ligerDialog.error("选出失败");
                            }
                        }
                    });
                }
                else {
                    $.ligerDialog.error('没有选择要选出的试题');
                }
            }
            catch (e) {
            }
        }
        function MoveItem(itemid, sort, type) {
            var id = document.getElementById("txtId").value;
            var optaction = "movetemp";
            if (id != "") {
                optaction = "move";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/callplanwebset.ashx?action=" + optaction + "&taskid=" + id + "&itemid=" + itemid + "&sort=" + sort + "&movetype=" + type,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            LoadSelectList();
                        } else {
                            $.ligerDialog.error("移动排序失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:HiddenField ID="txtId" runat="server" Value="" />
    <div id="pageloading">
        数据加载中，请稍等...
    </div>
    <div id="trSelect" style="width: 99%; text-align: center;">
        <div id="navtab1" style="width: 100%; height: 375px; border: 1px solid #D3D3d3;">
            <div title="自定义页面设置" tabid="tab1">
                <table id="tableMessage" cellpadding="3" cellspacing="3" border="0" style="width: 100%;">
                    <tr>
                        <td style="height: 30px; padding-left: 10px;" colspan="2" align="left">
                            类型：<asp:DropDownList ID="dropDBType" runat="server" onchange="LoadItemsList();"
                                CssClass="selectBox" Width="80px">
                                <asp:ListItem Value="" Text="所有类型"></asp:ListItem>
                                <asp:ListItem Value="nvarchar" Text="文本"></asp:ListItem>
                                <asp:ListItem Value="int" Text="整数"></asp:ListItem>
                                <asp:ListItem Value="datetime" Text="日期"></asp:ListItem>
                            </asp:DropDownList>&nbsp;
                            <input id="btnSearch" type="button" value="搜 索" class="btnSearch" onclick="LoadItemsList();" />
                        </td>
                    </tr>
                    <tr>
                        <td id="tdLeft" valign="top" style="width:50%; padding: 0px 2px 5px 2px;">
                            <div id="divItemsList">
                            </div>
                        </td>
                        <td valign="top" style="width:50%;padding: 0px 2px 5px 2px;">
                            <div id="divSelectList">
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <br />
    </form>
</body>
</html>
