@{
    ViewData["MainNum"] = "7";
    ViewData["SubNum"] = "4";
    ViewData["Title"] = "系統更新管理";
}
@using SolarPower.Models.Role
@model RoleLayerEnum

<ol class="breadcrumb page-breadcrumb">
    <li class="breadcrumb-item"><a href="javascript:void(0);">系統管理</a></li>
    <li class="breadcrumb-item active">@ViewData["Title"]</li>
    <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
</ol>

<div class="subheader">
    <h1 class="subheader-title">
        <i class='subheader-icon fal fa-globe'></i> @ViewData["Title"]
    </h1>
</div>
<!-- Your main content goes below here: -->

<div class="d-flex justify-content-center text-secondary" style="top: 10%; transform: translateY(50%); z-index: 100; position: relative;">
    <div class="spinner-border" role="status" style="width: 3rem; height: 3rem; display:none;" id="loading"></div>
</div>

<div class="row">
    <div class="col-xl-12">
        <div id="panel-5" class="panel">
            <div class="panel-container show">
                <div class="panel-content">
                    @*只有平台人員可以新增公司*@
                    @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformUser)
                    {
                        <button type="button" class="btn btn-success waves-effect waves-themed mb-3" onclick="AddNotice()">
                            <span class="fal fa-plus mr-1"></span>
                            新增通知
                        </button>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="SystemUpdateNotice-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    系統更新通知 - 新增
                </h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true"><i class="fal fa-times"></i></span>
                </button>
            </div>
            <div class="modal-body">
                <form class="SystemUpdateNotice-form" id="SystemUpdateNotice-form">

                    <div class="row">
                        <div class="form-group col-lg-6">
                            <label class="form-label" for="Subject_modal"><span class="text-danger">*</span>主旨</label>
                            <input type="text" id="Subject_modal" name="Subject_modal" class="form-control">
                        </div>
                        <div class="form-group col-lg-6">
                            <label class="form-label" for="Content_modal"><span class="text-danger">*</span>通知內容</label>
                            <input type="text" id="Content_modal" name="Content_modal" class="form-control">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="SendNotice()">送出</button>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>

        //#region 新增 系統更新通知
        function AddNotice() {
            $("#SystemUpdateNotice-modal .modal-title").html("系統更新通知 - 新增");
            $("#SystemUpdateNotice-form").trigger("reset");
            $("#SystemUpdateNotice-modal").modal();
        }
        //#endregion

        function showLoading() {
            var i = document.getElementById("loading");
            i.style.display = "block";
        }

        function hideLoading() {
            var i = document.getElementById("loading");
            i.style.display = "none";
        }

        //#region 送出通知
        function SendNotice() {
            showLoading();
            var url = "/SystemUpdate/SendNotice";
            if ($("#SystemUpdateNotice-form").valid()) {
                var send_data = {
                    Subject: $("#Subject_modal").val(),
                    Content: $("#Content_modal").val(),
                    EmailType: 5
                }
                $.post(url, send_data, function (rel) {
                    if (rel.code != "0000") {
                        hideLoading();
                        toast_error(rel.msg);
                        return;
                    }
                    else {
                        hideLoading();
                        toast_ok(rel.msg);
                        $('#SystemUpdateNotice-modal').modal('hide');
                        return;
                    }
                }, 'json');
            }
        }
        //#endregion
    </script>
}