<%@ page language="C#" autoeventwireup="true" inherits="phone_Meeting_MeetingEdit, ALL" enableEventValidation="false" %>

<%@ Register Src="~/user/phone/MyFooter.ascx" TagPrefix="uc1" TagName="MyFooter" %>
<%@ Register Src="~/user/phone/MyHeader.ascx" TagPrefix="uc1" TagName="MyHeader" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>会议室预约系统</title>
    <link href="/control/plugin/bootstrap3/css/bootstrap.min.css" rel="stylesheet">
    <link href="/user/phone/css/style.css?v=201723" rel="stylesheet">

    <script src="/control/js/jquery.js"></script>
    <script src="/control/plugin/bootstrap3/js/bootstrap.min.js"></script>

    <script src="/control/plugin/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script src="/control/plugin/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script>
    <link href="/control/plugin/bootstrap-datepicker/css/datepicker3.css" rel="stylesheet" />
    <script src="/control/plugin/autocomplete/jquery.autocomplete.js"></script>

    <style>
        .dt {
            color: grey;
            font-size: 13px;
        }
    </style>
</head>
<body>
    <uc1:MyHeader runat="server" ID="MyHeader" />

    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12 cont">
                <div class="panel">
                    <div class="panel-body">
                        <form id="from1" runat="server">
                            <!-- Add.aspx -->
                            <div class="form-group">
                                <label class=" control-label">会议名称<span class='rd'>*</span>：</label>
                                <asp:TextBox ID="txtm_MeetingName" runat="server" MaxLength="50" CssClass="form-control"></asp:TextBox>
                                <p class="help-block">
                                    <asp:RequiredFieldValidator ID="rfvm_MeetingName" runat="server" ForeColor="Red" ErrorMessage="请填写会议名称" Display="Dynamic" ControlToValidate="txtm_MeetingName"></asp:RequiredFieldValidator>
                                </p>
                            </div>

                            <div class="form-group">
                                <label class="control-label">会议室：</label>
                                <asp:DropDownList ID="ddlRoom" runat="server" CssClass="form-control"></asp:DropDownList>
                            </div>

                            <div class="form-group">
                                <label class="control-label">
                                    开始日期<span class='rd'>*</span> ：
                                </label>
                                <asp:TextBox ID="txtStartDate" runat="server" CssClass="form-control"></asp:TextBox>
                                <script type="text/javascript">
                                    $(function () {
                                        $("#txtStartDate").datepicker({
                                            language: "zh-CN",
                                            format: "yyyy-mm-dd",
                                            todayBtn: "linked",
                                            todayHighlight: true,
                                            autoclose: true
                                        });
                                        $("#txtRptEndDate").datepicker({
                                            language: "zh-CN",
                                            format: "yyyy-mm-dd",
                                            autoclose: true,
                                            todayBtn: "linked",
                                            todayHighlight: true
                                        });
                                        $("#txtRptEndMonth").datepicker({
                                            language: "zh-CN",
                                            format: "yyyy-mm",
                                            startView: 1,
                                            minViewMode: 1,
                                            maxViewMode: 1,
                                            autoclose: true,
                                            todayBtn: "linked",
                                            todayHighlight: true
                                        });

                                    });
                                </script>
                                <p class="help-block">
                                    <asp:RequiredFieldValidator ID="rfvtxtStartDate" runat="server" ErrorMessage="请填写起始日期"
                                        ForeColor="Red" Display="Dynamic" ControlToValidate="txtStartDate">
                                    </asp:RequiredFieldValidator>
                                </p>
                            </div>

                            <div class="form-group">

                                <div class="row">

                                    <div class="col-xs-6">
                                        <label class="control-label">
                                            开始时间<span class='rd'>*</span> ：
                                        </label>
                                        <asp:DropDownList runat="server" ID="ddlStartTime" CssClass="form-control">
                                        </asp:DropDownList>
                                        <p class="help-block">
                                            <asp:RequiredFieldValidator ID="rfvm_startDate" runat="server" ErrorMessage="请填写起始时间" ForeColor="Red" Display="Dynamic" ControlToValidate="ddlStartTime"></asp:RequiredFieldValidator>
                                        </p>
                                    </div>
                                    <div class="col-xs-6">
                                        <label class=" control-label">时长<span class='rd'>*</span> ：</label>
                                        <asp:DropDownList ID="ddlDuration" runat="server" CssClass="form-control"></asp:DropDownList>

                                    </div>
                                </div>

                            </div>

                            <div class="form-group">
                                <label class="control-label">参与人员<span class='rd'>*</span>：</label>
                                <div class="row">
                                    <div class="col-xs-4">
                                        <asp:DropDownList ID="ddlSearchType" runat="server" CssClass="form-control">
                                            <asp:ListItem Value="e">用户</asp:ListItem>
                                            <asp:ListItem Value="m">会议</asp:ListItem>
                                            <asp:ListItem Value="d">机构</asp:ListItem>
                                        </asp:DropDownList>
                                    </div>

                                    <div class="col-xs-8">
                                        <asp:TextBox ID="txtEmployeeSearch" runat="server" MaxLength="255" Rows="4" CssClass="form-control"></asp:TextBox>
                                    </div>

                                </div>
                                <p class=" help-block">支持拼音首字母缩写，选择(人员,会议,机构)可限定搜索范围</p>
                            </div>

                            <div class="form-group">
                                <div id="emplist">


                                    <asp:Repeater ID="rptEmp" runat="server">

                                        <ItemTemplate>

                                            <span class="emp" id="<%#Eval("ee_id") %>">
                                                <input name="emp" value="<%#Eval("ee_id") %>" type="hidden"><%#Eval("ee_name") %>
                                                <button class="btn btn-xs btn-link" onclick="rb(this)" type="button">X </button>
                                            </span>

                                        </ItemTemplate>

                                    </asp:Repeater>
                                </div>
                            </div>
                                 <div class="form-group">
                            <label class=" control-label">外部人员<span class='rd'>*</span>：</label>
                            <div >
                                <asp:TextBox ID="txtExternalPerson" runat="server" MaxLength="255" Rows="4" CssClass="form-control" ></asp:TextBox>
                                <p class=" help-block">支持拼音首字母缩写快速查询</p>
                            </div>
                        </div> 

                        <div class="form-group">
                          <div id="eplist">
                                   <asp:Repeater ID="rptEPList" runat="server">
                                   <ItemTemplate>
                                       <span id="<%#Eval("mep_depid") %>" class="ep"> 
                                           <input name="ep" value="<%#Eval("mep_depid") %>" type="hidden" >
                                           <span><%#Eval("cy_name") %>/<%#Eval("dep_name") %></span>
                                           <button class="btn btn-xs btn-link" onclick="rb(this)" type="button">X </button>
                                       </span>
                                   </ItemTemplate>
                                </asp:Repeater>
                           </div>
                        </div>
                            <div class="form-group">
                                <label class="control-label">会议简要说明：</label>

                                <asp:TextBox ID="txtm_note" runat="server" MaxLength="255" Rows="4" TextMode="MultiLine" CssClass="form-control"></asp:TextBox>

                            </div>

                            <div class="form-group">

                                <asp:Button ID="btnSubmit" runat="server" Text="编辑会议" OnClientClick="return befSubmit()" CssClass="btn btn-primary btn-block" OnClick="btnSubmit_Click" />
                                <script type="text/javascript">

                                    function befSubmit() {
                                        if (Page_ClientValidate()) {
                                            var WeekRpt = $("#rbWeekRpt").get(0).checked;
                                            if (WeekRpt) {
                                                var rpted = $.trim($("#txtRptEndDate").val());
                                                if (rpted == "") {
                                                    $("#rfvm_EndDate").show();
                                                    return false;
                                                }
                                            } else {
                                                var monthRpt = $("#rbMonthRpt").get(0).checked;
                                                if (monthRpt) {
                                                    var rptedm = $.trim($("#txtRptEndMonth").val());
                                                    if (rptedm == "") {
                                                        $("#rfvm_EndMonth").show();
                                                        return false;
                                                    }
                                                }
                                            }

                                        } else {
                                            return false;
                                        }
                                        return true;
                                    }

                                </script>


                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>
  
    </div>

    <script type="text/javascript">

        $(function () {
            EmployeeAutoComplete();
            ExternalPersonAutoComplete();
        });

        function rb(obj) {
            $(obj).parent().remove();
        }
        function ExternalPersonAutoComplete() {
            $('#txtExternalPerson').autocomplete({
                multiple: true,
                serviceUrl: '/user/Booking/ExternalPerson.ashx',
                formatResult: function (suggestion, currentValue) {
                    var value = suggestion.company + "/" + suggestion.value;
                    var pattern = '(' + $.Autocomplete.utils.escapeRegExChars(currentValue) + ')';
                    return value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
                },
                lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
                    var re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi');
                    return re.test(suggestion.value);
                },
                onSelect: function (suggestion) {
                    if ($("#" + suggestion.data).size() == 0) {
                        addExternalPerson(suggestion.data, suggestion.value, suggestion.company);
                    }
                    $("#txtExternalPerson").val("");
                }
            });
        }
        function EmployeeAutoComplete() {
            $('#txtEmployeeSearch').autocomplete({
                multiple: true,
                params: { t: function () { return $('#ddlSearchType').val(); } },
                serviceUrl: '/user/Booking/EmployeeSearch.ashx',
                formatResult: function (suggestion, currentValue) {
                    var value = '用户：' + suggestion.value;
                    var pattern = '(' + $.Autocomplete.utils.escapeRegExChars(currentValue) + ')';
                    return value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
                },
                lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
                    var re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi');
                    return re.test(suggestion.value);
                },
                onSelect: function (suggestion) {

                    if (suggestion.t == "e") {
                        if ($("#" + suggestion.data).size() == 0) {
                            addEmp(suggestion.data, suggestion.value);
                        }
                    } else if (suggestion.t == "m") {

                        $.get('/user/Booking/EmployeeSearch.ashx', { mid: suggestion.data }, function (data) {
                            for (var i = 0; i < data.length; i++) {
                                var item = data[i];
                                if ($("#" + item.id).size() == 0) {
                                    addEmp(item.id, item.name);
                                }
                            }

                        }, "json");

                    } else if (suggestion.t == "d") {
                        $.get('/user/Booking/EmployeeSearch.ashx', { did: suggestion.data }, function (data) {
                            for (var i = 0; i < data.length; i++) {
                                var item = data[i];
                                if ($("#" + item.id).size() == 0) {
                                    addEmp(item.id, item.name);
                                }
                            }

                        }, "json");
                    }

                    $("#txtEmployeeSearch").val("");
                }
            });
        }

        function addEmp(value, name) {
            $("#emplist").append("<span class='emp' id='" + value + "'><input name='emp' value='" + value + "' type='hidden' />" + name + "  <button class='btn btn-xs btn-link' onclick='rb(this)' type='button'> X </button></span>")
        }
        function addExternalPerson(value, name, company) {
            $("#eplist").append("<span class='emp' id='" + value + "' title='" + company + "'><input name='ep' value='" + value + "' type='hidden' /><span>" + company + "/" + name + "</span><button class='btn btn-xs btn-link' onclick='rb(this)' type='button'> X </button></span>");
        }
    </script>

    <uc1:MyFooter runat="server" ID="MyFooter" />
</body>
</html>
