<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DecideSend.aspx.cs" Inherits="Mail_PermitSend_DecideSend" ValidateRequest="false" meta:resourcekey="Page" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<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 () {
            Dialog.setMessage('<asp:Literal runat="server" Text="<%$ Resources:Dialog, Title%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, OK%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, Cancel%>" />');
            Dialog.setUseBrowserConfirm(<%=AppSetting.UseBrowserConfirm%>);
        });

        function Approve() {
            Dialog.confirm({
                content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg01%>" />',
                ok: function () {
                    var param = {
                        clid: "<%= _clId %>",
                        delegateName: "<%= _delegateName %>",
                        comment: $("#CommentTextBox").val()
                    };
                    console.log(param);
                    $.ajax({
                        type: "POST",
                        url: "CallAjax.aspx/Confirm",
                        data: JSON.stringify(param),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            if (response.d == 0)
                                GotoList();
                            else
                                ShowErrorMessage(response.d);
                        },
                        failure: function (response) {
                            ShowErrorMessage(-1);
                        }
                    });
                }
            });
        }

        function Reject() {
            Dialog.confirm({
                content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg02%>" />',
                ok: function () {
                    var param = {
                        clid: "<%= _clId %>",
                        delegateName: "<%= _delegateName %>",
                        comment: $("#CommentTextBox").val()
                    };
                    console.log(param);
                    $.ajax({
                        type: "POST",
                        url: "CallAjax.aspx/Reject",
                        data: JSON.stringify(param),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            if (response.d == 0)
                                GotoList();
                            else
                                ShowErrorMessage(response.d);
                        },
                        failure: function (response) {
                            ShowErrorMessage(-1);
                        }
                    });
                }
            });
        }

        function GoBack() {
            history.back();
        }

        function GotoList() {
            location.href = "ConfirmerList.aspx?<%=_listPageParams%>";
        }

        function ShowErrorMessage(code) {
            switch (code) {
                case 1: Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg03%>" />'); break;    // 이미 처리된 메일입니다.
                case 2: Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg04%>" />'); break;    // 유지보수 라이선스 만료 시 메일 승인 기능을 사용할 수 없습니다.
                default: Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg05%>" />'); break;   // 메일 발송 승인/거부 처리에 실패했습니다.
            }
        }
    </script>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <CompositeScript>
                <Scripts>
                    <asp:ScriptReference Path="~/libs/tabs/common.js" />
                    <asp:ScriptReference Path="~/libs/tabs/dialog.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" runat="server" id="actionToolButton" class="btn btn-primary"><%=_actionButtonText%></button>
                    <span>&nbsp;</span>
                    <button type="button" id="gobackToolButton" class="btn btn-primary" onclick="GoBack();"><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="RejectTextBox">
                    <asp:Localize ID="Localize1" runat="server" meta:resourcekey="L01">코멘트</asp:Localize>:</label>
                <textarea class="form-control" rows="10" id="CommentTextBox" runat="server" maxlength="500"></textarea>
            </div>
        </div>
    </form>
</body>
</html>
