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

<!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 g;
        var arr1=new Array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20");
        var arr2 = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T");
        var sort = 0;
        var questionlist;
        function CloseThis() {
            var dialog = frameElement.dialog;
            parent.LoadQuestionList();
            dialog.close();
        }
        $(function () {
            var a = $("#navtab1").ligerTab({
                showSwitch: false,
                contextmenu: false,
                onAfterSelectTabItem: function (targettabid) {
                }
            });
            $("#toptoolbar1").ligerToolBar({ items: [
                    { text: '添加选项', click: itemclick, icon: 'add' }
                    ]
            });
            var id = document.getElementById("txtId").value;
            if (id != "") {
                action = "getlist";
            }
            var type = document.getElementById("dropQuestionType").value;
            if (type != "1") {
                selecttype();
            }
            $("#pageloading_bg,#pageloading").hide();
        });
        var itemcount = 0;
        var action = "gettemplist";
        function LoadItem() {
            itemcount = 0;
            var selecttype = document.getElementById("dropQuestionType").value;
            var userid = document.getElementById("txtUserId").value;
            var sorttype = document.getElementById("dropSortModel").value;
            var questionid = document.getElementById("txtId").value;
            questionlist = $("#divItemList").ligerGrid({
                height: 190,
                enabledEdit: true,
                onBeforeEdit: f_onBeforeEdit,
                onAfterEdit: f_onAfterEdit,
                columns: [
                { display: '序号', width: '50', name: '_f_itemid', render: function (rowdata, rowindex, value) {
                    var strres = "";
                    try {
                        if (sorttype == "1") {
                            strres = arr2[rowindex];
                        }
                        else {
                            strres = arr1[rowindex];
                        }
                    }
                    catch (e)
                    { }
                    return strres;
                }
                },
                { display: '选项', align: 'left', name: '_f_itemname', editor: { type: 'text' }, render: function (rowdata, rowindex, value) {
                    if (selecttype == "1")
                        return "&nbsp;&nbsp;<img src='../images/help_question_mark_24.png' style='width:18px' />&nbsp;&nbsp;<font color='red'>" + value + "</font>";
                    else if (selecttype == "2")
                        return "&nbsp;&nbsp;<img src='../images/radio_button_off_16.png' style='width:16px' />&nbsp;&nbsp;<font color='green'>" + value + "</font>";
                    else if (selecttype == "3")
                        return "&nbsp;&nbsp;<img src='../images/check_box_24.png' style='width:18px' />&nbsp;&nbsp;<font color='blue'>" + value + "</font>";
                    else
                        return "";
                }
                },
                //                { display: '是否答案', width: '80', name: '_f_questionid', render: function (rowdata, rowindex, value) {
                //                    if (value == "1")
                //                        return "<img src='../images/ico-2.png' style='width:16px' />";
                //                    else
                //                        return "";
                //                }
                //                },
                {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_itemid + "\",\"" + value + "\",\"1\");' src='../images/icon_desc.gif' title='下移' style='width:12px; cursor:hand;' />";
                    else
                        return "&nbsp;<img id='sy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_itemid + "\",\"" + value + "\",\"-1\");' src='../images/icon_asc.gif' title='上移' style='width:12px; cursor:hand;' />&nbsp;&nbsp;<img id='xy_" + rowindex + "' onclick='MoveItem(\"" + rowdata._f_itemid + "\",\"" + value + "\",\"1\");' src='../images/icon_desc.gif' title='下移' style='width:12px; cursor:hand;' />";
                }
            },
                { display: '操作', width: '60', name: '_f_itemid', render: function (rowdata, rowindex, value) {
                    return "<div style='padding-top:5px;'><img src='../images/icon_del.gif' onclick='DeleteItem(\"" + value + "\")' title='删除' style='width:12px; cursor:hand;' /></div>";
                }
                }
                ],
            url: 'ajax/questionitems.ashx?action=' + action + '&type=&questionid=' + questionid + '&userid=' + userid, pageSize: 50, pageSizeOptions: [10, 20, 50], rownumbers: false,
            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 userid = document.getElementById("txtUserId").value;
            var sorttype = document.getElementById("dropSortModel").value;
            var timeno = new Date().getTime();
            var dataObj = questionlist.getRow(e.rowindex);
            if (dataObj) {
                var itemid = dataObj._f_itemid;
                var itemvalue = escape(dataObj._f_itemname);
                var optaction = "modifytemp";
                if (id != "") {
                    optaction = "modify";
                }
                try {
                    $.ajax({
                        type: "get",
                        url: "ajax/questionitems.ashx?action=" + optaction + "&questionid=" + id + "&userid=" + userid + "&itemid=" + itemid + "&itemvalue=" + itemvalue + "&timeno=" + timeno,
                        dataType: "html",
                        success: function (res) {
                            if (res == "success") {
                                //selecttype();
                            } else {
                                $.ligerDialog.error("修改选项失败");
                            }
                        }
                    });
                }
                catch (e) {
                }
            }
            else {
                $.ligerDialog.error("没有选择要修改的项");
            }            
        }

        //编辑前事件
        function f_onBeforeEdit(e) {
            return true;
        }
        function itemclick(item) {
            switch (item.icon) {
                case "add":
                    if (itemcount < 20) {
                        AddItem();
                    }
                    else {
                        $.ligerDialog.error('选项不能超过20项');
                    }
                    break;
            }
        }
        function AddItem() {
            var id = document.getElementById("txtId").value;
            var userid = document.getElementById("txtUserId").value;
            var sorttype = document.getElementById("dropSortModel").value;
            var timeno = new Date().getTime();
            var optaction = "addtemp";
            if (id != "") {
                optaction = "add";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/questionitems.ashx?action=" + optaction + "&questionid=" + id + "&userid=" + userid + "&sorttype=" + sorttype + "&sort=" + sort + "&timeno=" + timeno,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            selecttype();
                        } else {
                            $.ligerDialog.error("添加选项失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function DeleteItem(itemid) {
            var id = document.getElementById("txtId").value;
            var timeno = new Date().getTime();
            var optaction = "deletetemp";
            if (id != "") {
                optaction = "delete";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/questionitems.ashx?action=" + optaction + "&questionid=" + id + "&itemid=" + itemid + "&timeno=" + timeno,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            selecttype();
                        } else {
                            $.ligerDialog.error("删除选项失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function MoveItem(itemid, sort,type) {
            var id = document.getElementById("txtId").value;
            var timeno = new Date().getTime();
            var optaction = "movetemp";
            if (id != "") {
                optaction = "move";
            }
            try {
                $.ajax({
                    type: "get",
                    url: "ajax/questionitems.ashx?action=" + optaction + "&questionid=" + id + "&itemid=" + itemid + "&sort=" + sort + "&movetype=" + type + "&timeno=" + timeno,
                    dataType: "html",
                    success: function (res) {
                        if (res == "success") {
                            selecttype();
                        } else {
                            $.ligerDialog.error("移动选项失败");
                        }
                    }
                });
            }
            catch (e) {
            }
        }
        function selecttype() {
            var selectid = document.getElementById("dropQuestionType").value;
            if (selectid == "1") {
                document.getElementById("trSelect").style.display = "none";
            }
            else {
                document.getElementById("trSelect").style.display = "block";
                LoadItem();
            }
        }
        function validate() {
            var i = 0;
            if (!validate1()) {
                i++;
            }
            if (!validate2()) {
                i++;
            }
            if (!validate3()) {
                i++;
            }

            if (i > 0) {
                return false;
            }
            return true;
        }
        function validate1() {
            if ($("#dropQuestionCategory").val() == "" || $("#dropQuestionCategory").val() == undefined) {
                document.getElementById("lbQuestionCategory").innerHTML = "* 未选择分类！";
                document.getElementById("lbQuestionCategory").style.color = "red";
                return false;
            }
            else {
                document.getElementById("lbQuestionCategory").innerHTML = "*";
                document.getElementById("lbQuestionCategory").style.color = "#414141";
                return true;
            }
        }
        function validate2() {
            if ($("#txtF_Title").val() == "" || $("#txtF_Title").val() == undefined) {
                document.getElementById("lbF_Title").innerHTML = "* 标题不能为空！";
                document.getElementById("lbF_Title").style.color = "red";
                return false;
            }
            else {
                document.getElementById("lbF_Title").innerHTML = "*";
                document.getElementById("lbF_Title").style.color = "#414141";
                return true;
            }
        }
        function validate3() {
            if (document.getElementById("dropQuestionType").value != "1") {
                if (itemcount<1) {
                    document.getElementById("lbQuestionType").innerHTML = "* 此题型下未选项！";
                    document.getElementById("lbQuestionType").style.color = "red";
                    return false;
                }
                else {
                    document.getElementById("lbQuestionType").innerHTML = "*";
                    document.getElementById("lbQuestionType").style.color = "#414141";
                    return true;
                }
            }
            else {
                document.getElementById("lbQuestionType").innerHTML = "*";
                document.getElementById("lbQuestionType").style.color = "#414141";
                return true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:HiddenField ID="hidF_CategoryId" runat="server" Value="" />
    <asp:HiddenField ID="txtUserId" runat="server" Value="0" />
    <asp:HiddenField ID="txtId" runat="server" Value="" />
    <div id="pageloading">
        数据加载中，请稍等...
    </div>
    <table class="form_table" style="width: 100%; height: 100%;">
        <colgroup>
            <col width="100" />
            <col />
            <col width="100" />
            <col />
        </colgroup>
        <tr style="height: 25px;">
            <th style="height: 25px; padding: 0px 8px 0px 0px;">
                试题分类：
            </th>
            <td style="height: 25px; padding: 2px 0px 0px 8px;">
                <asp:DropDownList ID="dropQuestionCategory" runat="server" CssClass="selectBox" Width="120px">
                </asp:DropDownList><label
                                id="lbQuestionCategory" for="dropQuestionCategory"></label>
            </td>
            <th style="height: 25px; padding: 0px 8px 0px 0px;">
                试题题型：
            </th>
            <td style="height: 25px; padding: 2px 0px 0px 8px;">
                <asp:DropDownList ID="dropQuestionType" runat="server" onchange="selecttype();" CssClass="selectBox"
                    Width="120px">
                    <asp:ListItem Value="1" Text="问答题" Selected></asp:ListItem>
                    <asp:ListItem Value="2" Text="单选题"></asp:ListItem>
                    <asp:ListItem Value="3" Text="多选题"></asp:ListItem>
                </asp:DropDownList><label
                                id="lbQuestionType" for="dropQuestionType"></label>
            </td>
        </tr>
        <tr style="height: 25px;">
            <th style="height: 25px; padding: 0px 8px 0px 0px;">
                试题标题：
            </th>
            <td colspan="3" style="height: 25px; padding: 5px 0px 5px 8px;">
                <textarea id="txtF_Title" cols="20" rows="4" runat="server" class="txtInput normal"
                    style="width: 455px; height: 60px;"></textarea><label
                                id="lbF_Title" for="txtF_Title"></label>
            </td>
        </tr>
    </table>
    <div id="trSelect" style="width: 99%; display: none; text-align: center;">
        <div id="navtab1" style="width: 100%; height: 250px; border: 1px solid #D3D3d3;">
            <div title="试题选项" tabid="tab1">
                <div class="tools_box" style="height: 30px;">
                    <div class="tools_bar">
                        <div style="float: left; padding-top: 3px; padding-left: 1px; font-weight: bold;
                            color: red;">
                            <img src="../images/check_list_16.png" />&nbsp;选项序列模式&nbsp;&nbsp;
                            <asp:DropDownList ID="dropSortModel" runat="server" onchange="selecttype();" CssClass="selectBox"
                                Width="120px">
                                <asp:ListItem Value="1" Text="A、B、C..." Selected></asp:ListItem>
                                <asp:ListItem Value="2" Text="1、2、3..."></asp:ListItem>
                            </asp:DropDownList>
                        </div>
                        <div id="toptoolbar1" style="float: right;">
                        </div>
                    </div>
                </div>
                <div id="divItemList">
                </div>
            </div>
        </div>
    </div>
    <br />
    <div style="width: 100%; text-align: center;">
        <asp:Button ID="btnSubmit" runat="server" Text="保&nbsp;&nbsp;存" CssClass="btnSubmit"
            OnClientClick="return validate();" OnClick="btnSubmit_Click" /></div><br />
    </form>
</body>
</html>
