<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectOrgz.aspx.cs" Inherits="Contact_SelectOrgz" meta:resourcekey="Page" %>
<%@ Import Namespace="TABS.MailCarrier.WebSDK.Contact" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../libs/fontawesome/css/all.min.css" >
    <script type="text/javascript" src="../libs/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../libs/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        $(document).ready(function () {           
        });

        function GetRecipientsType() {
            recType = "To";
            var search = window.location.search.substring(1);
            var query = search.split('&');
            for (var i = 0; i < query.length; i++) {
                var keyValue = query[i].split('=');
                var key = keyValue[0];
                var value = keyValue[1];
                if (key == "RcptType") recType = value;
            }
            return recType;
        }

        function AddList(text, value, rcpts) {
            if (!rcpts.Add(new Recipient(text, RcptOrgz, value), false)) {
                //alert('중복된 계정 정보는 추가하지 않습니다.');
            }
        }

        function ReturnRecipients() {
            var rcpts = new Recipients();
            var orgzItemName = $get("OrgzItemName").value;
            var orgzItemId = $get("OrgzItemID").value;
            if (orgzItemId != '') {
                rcpts.Add(new Recipient(orgzItemName, RcptOrgz, orgzItemId), false);
                try {
                    var jsonParam = Recipients.ToJsonString(rcpts);
                    var wnd = window.opener;
                    window.setTimeout(function () {
                        var recType = GetRecipientsType();
                        if (recType == "to" && wnd.ReturnToRecipients != null) wnd.ReturnToRecipients(jsonParam);
                        if (recType == "cc" && wnd.ReturnCcRecipients != null) wnd.ReturnCcRecipients(jsonParam);
                        if (recType == "bcc" && wnd.ReturnBccRecipients != null) wnd.ReturnBccRecipients(jsonParam);
                        self.close();
                    }, 100);
                }
                catch (e) {
                    self.close();
                }
            }
        }

        function Close() {
            window.close();
        }
    </script>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <CompositeScript>
                <Scripts>
                    <asp:ScriptReference Path="~/libs/tabs/Recipients.js" />
                </Scripts>
            </CompositeScript>
        </asp:ScriptManager>

        <div class="container-fluid">
            <div class="row" id="toolBar" data-spy="affix">
                <div class="col-xs-12" style="padding-top:2px;padding-bottom:2px;">
                    <button type="button" id="selectToolButton" class="btn btn-primary" onclick="ReturnRecipients()"><span class="fa-solid fa-address-card"></span> <asp:Localize ID="Localize1" runat="server" meta:resourcekey="L01">수신자 선택</asp:Localize></button>              
                    <span>&nbsp;</span>
                    <button type="button" id="Button2" class="btn btn-primary" onclick="Close();"><span class="fa-solid fa-xmark"></span></button>
                </div>
            </div>
        </div>

        <div class="container-fluid" style="padding-top:40px">
            <div class="form-group">
                <label for="OrgzList"><asp:Localize ID="Localize2" runat="server" meta:resourcekey="L02">조직도 목록</asp:Localize>:</label>
                <asp:DropDownList ID="OrgzList" runat="server" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="OrgzList_SelectedIndexChanged">
                </asp:DropDownList>
            </div>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:TreeView ID="OrgzTree" runat="server" EnableClientScript="false" ExpandDepth="0"
                        OnSelectedNodeChanged="OrgzTree_SelectedNodeChanged" OnTreeNodePopulate="OrgzTree_TreeNodePopulate">
                        <ParentNodeStyle Font-Bold="False" />
                        <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                        <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" VerticalPadding="0px" />
                        <NodeStyle ForeColor="Black" NodeSpacing="0px" VerticalPadding="1px" />
                    </asp:TreeView>
                    <asp:HiddenField ID="OrgzItemName" runat="server" />
                    <asp:HiddenField ID="OrgzItemID" runat="server" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="OrgzTree" EventName="TreeNodePopulate" />
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>
