@model PantheonRA.BackOffice.Models.SetCalEntryTypesViewModel
@using PantheonRA.WebApi.Contracts.Enums
@{
    ViewBag.Title = @Loc.WorkHourSettings;
}

<div class="wrapper wrapper-content">
    <div class="tabs-container">
        @Html.Partial("~/Views/Company/_CompanySettingsTabNavigation.cshtml")

        @Html.Hidden("UrlSave", Url.Action("Save", "SetCalendarEntryTypes"))
        @Html.Hidden("UrlDelete", Url.Action("Delete", "SetCalendarEntryTypes"))
        @Html.Hidden("UrlSaveOrder", Url.Action("SaveOrder", "SetCalendarEntryTypes"))
        @Html.Hidden("TxtConfirm", Loc.Confirm)
        @Html.Hidden("TxtDeleteQuestion", Model.Type == WorkHourEntryType.EntryTypes ? Loc.DeleteEntryTypeQuestion :
            (Model.Type == WorkHourEntryType.Absences ? Loc.DeleteEntryTypeAbsenceQuestion : Loc.DeleteEntryTypeEmployeesQuestion))
        @Html.Hidden("TxtCancel", Loc.Cancel)
        @Html.Hidden("TxtConfirmation", Loc.Confirmation)
        @Html.Hidden("TxtDelNotPossible", Loc.DeleteEntryTypeNotPossible)
        @Html.Hidden("TxtInputFields", Loc.FieldIsRequired)
        @Html.Hidden("TxtAlreadyExists", Loc.AlreadyExists)
        @Html.Hidden("PrimaryKeyExists", Loc.PrimaryKeyExists)

        <div class="tab-content set-wh-content">
            <div class="divided-content">
                <div class="divided-content-main">
                    <div class="tab-content setwh-100-h">
                        <div class="row document-head">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="control-label">@Loc.SearchFilter</label>
                                    @Html.TextBoxFor(model => model.Keywords, new { @id = "Keywords", @class = "form-control search-input", @placeholder = Loc.Search, autocomplete = "off" })
                                </div>
                            </div>
                            <div class="col-md-8"></div>
                        </div>
                        <div class="row setwh-100-h">
                            <div class="col-md-12 setwh-100-h containerSetCalEntryTypes">
                                <table id="tblSetCalEntryTypes" 
                                       data-grid-id="SetCalEntryTypes-@Model.Type" 
                                       class="table table-bordered dailyallow-table custom-ddw-mobile-table showhidecolumns" 
                                       style="margin-bottom: 0;" role="grid">
                                    <thead>
                                        <tr>
                                            <th data-column-id="Positions"></th>
                                            <th data-column-id="Code">@Loc.Code</th>
                                            <th data-column-id="Name">@Loc.Name</th>
                                            <th data-column-id="SalaryTypeShort">@Loc.SalaryTypeShort</th>
                                            @if (Model.Type == WorkHourEntryType.EntryTypes)
                                            {
                                                <th data-column-id="Operation">@Loc.Operation</th>
                                                <th data-column-id="SetIsWorkFromHome">@Loc.SetIsWorkFromHome</th>
                                            }
                                            <th data-column-id="Icon">@Loc.Icon</th>
                                            <th colspan="2" data-column-id="MainColor">@Loc.MainColor</th>
                                            @*<th colspan="2" data-column-id="BackColor">@Loc.BackColor</th>*@
                                        </tr>
                                    </thead>
                                    <tbody id="sortable-body">

                                        @{
                                            var nameWidth = Model.Type == WorkHourEntryType.EntryTypes ? "25%" : "50%";
                                        }

                                        <tr id="set-et-first-row">
                                            <td style="width:2%"></td>
                                            <!-- Code -->
                                            <td label="@Loc.Code" style="width: 12%">
                                                <input id="input-code" maxlength="3" type="text" class="form-control" autocomplete="off" placeholder="@Loc.Code" />
                                            </td>
                                            <!-- Name -->
                                            <td label="@Loc.Name" style="width:@nameWidth;">
                                                <input id="input-name" maxlength="40" type="text" class="form-control" autocomplete="off" placeholder="@Loc.Name" />
                                            </td>
                                            <!-- Salary Type -->
                                            <td label="@Loc.SalaryTypeShort" style="width: 15%">
                                                <div class="ddw-full-width select2HideColumns">
                                                    <select id="input-salary-type"
                                                            data-placeholder="@Loc.SalaryTypeShort"
                                                            class="form-control select2withAPI"
                                                            data-column-names="@Loc.Code,@Loc.Name"
                                                            data-url=@Url.Action("GetSalaryTypes", "SetCalendarEntryTypes")
                                                            data-allow-clear="true"
                                                            data-search-width="350"
                                                            data-mobile-width="200"
                                                            onchange="setSalaryTypeVal()"
                                                            data-bootstrap-columns="col-md-3,col-md-9">
                                                    </select>
                                                </div>
                                            </td>
                                            @if (Model.Type == WorkHourEntryType.EntryTypes)
                                            {
                                                <!-- Operation -->
                                                <td label="@Loc.Operation" style="width: 15%">
                                                    <div class="ddw-full-width select2HideColumns">
                                                        <select id="input-operation"
                                                                data-placeholder="@Loc.Operation"
                                                                class="form-control select2withAPI"
                                                                data-mobile-width="200"
                                                                data-column-names="@Loc.Name"
                                                                data-url=@Url.Action("GetOperations", "SetCalendarEntryTypes")
                                                                data-bootstrap-columns="col-md-12">
                                                        </select>
                                                    </div>
                                                </td>
                                                <!-- IsWorkFromHome -->
                                                <td label="@Loc.SetIsWorkFromHome" style="width:8%;padding-top: 5px;">
                                                    <input id="input-work-from-home" type="checkbox" class="form-control checkbox-left" />
                                                </td>
                                            }
                                            <!-- Icon -->
                                            <td label="@Loc.Icon" style="width: 8%">
                                                <div class="dropdown d-inline-block" data-toggle="dropdown">
                                                    <p class="dropdown-toggle no-caret" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                        <i id="input-icon" class="picker-icon picker-icon-small fa fa-search" aria-hidden="true">
                                                            <span id="input-icon-val" class="hidden"></span>
                                                        </i>
                                                    </p>
                                                    <div class="custom-ddw icon-ddw-container dropdown-menu dropdown-menu-right rounded-0 box-shadow">
                                                        <div class="row">
                                                            @foreach (var icon in Model.Icons)
                                                            {
                                                                <div class="col-md-2 custom-ddw-item">
                                                                    <span onclick="setIcon('@icon.Key.ToString()')" class="picker-icon picker-icon-medium fa @icon.Key.ToString()"></span>
                                                                </div>
                                                            }
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>
                                            <!-- Main Color -->
                                            <td label="@Loc.MainColor" style="width: 13%" id="td-input-main-color">
                                                <div class="dropdown d-inline-block margin-top-7" data-toggle="dropdown">
                                                    <p class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                        <div class="dropdown color-picker-box" id="input-main-color-box"></div>
                                                        <span class="hidden" id="input-main-color-val"></span>
                                                    </p>
                                                    <div class="custom-ddw custom-ddw-no-x custom-ddw-h-500 dropdown-menu dropdown-menu-right rounded-0 box-shadow">
                                                        <div class="row">
                                                            @foreach (var color in Model.MainColors)
                                                            {
                                                                <div class="col-md-12 custom-ddw-item"
                                                                     onclick="setMainColor('@color.Key.ToString()', '@color.Name')">
                                                                    <div class='color-picker-box' style="background-color: @color.Key.ToString()"></div>
                                                                    <p> @color.Name</p>
                                                                </div>
                                                            }
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>
                                            <!-- Text color-->
                                            @*<td label="@Loc.BackColor" style="width: 12%" id="td-input-text-color" class="last-column">
                                                <div class="dropdown d-inline-block margin-top-7" data-toggle="dropdown">
                                                    <p class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                        <div class="dropdown color-picker-box" id="input-text-color-box"></div>
                                                        <span class="hidden" id="input-text-color-val"></span>
                                                    </p>
                                                    <div class="custom-ddw custom-ddw-no-x custom-ddw-h-500 dropdown-menu dropdown-menu-right rounded-0 box-shadow">
                                                        <div class="row">
                                                            @foreach (var color in Model.MainColors)
                                                            {
                                                                <div class="col-md-12 custom-ddw-item"
                                                                     onclick="setTextColor('@color.Key.ToString()', '@color.Name')">
                                                                    <div class='color-picker-box' style="background-color: @color.Key.ToString()"></div>
                                                                    <p> @color.Name</p>
                                                                </div>
                                                            }
                                                        </div>
                                                    </div>
                                                </div>
                                            </td>*@
                                            <!-- Action -->
                                            <td style="width: 12%" class="td-action">
                                                <p class="btn btn btn-success" onclick="saveEntryType()">
                                                    <span class="far fa-plus cursor-pointer" aria-hidden="true"></span>
                                                </p>
                                            </td>
                                        </tr>
                                        @foreach (var item in Model.Items)
                                        {
                                            @Html.Hidden("AnQid-" + item.AnQid)

                                            <tr id="tr-@item.AnQid" class="sortable-row" data-id="@item.AnQid">
                                                <td>
                                                    <i class="fa fa-arrows-v m-t-sm"></i>
                                                </td>
                                                <!-- Code -->
                                                <td label="@Loc.Code">
                                                    <input id="input-code-@item.AnQid"
                                                           value="@item.SetOf"
                                                           maxlength="3"
                                                           type="text"
                                                           class="form-control"
                                                           autocomplete="off"
                                                           placeholder="@Loc.Code"
                                                           onmousedown="return false"
                                                           onchange="saveEntryType(@item.AnQid)" />
                                                </td>
                                                <!-- Name -->
                                                <td label="@Loc.Name">
                                                    <input id="input-name-@item.AnQid"
                                                           value="@item.Name"
                                                           maxlength="40"
                                                           type="text"
                                                           class="form-control"
                                                           autocomplete="off"
                                                           placeholder="@Loc.Name"
                                                           onmousedown="return false"
                                                           onchange="saveEntryType(@item.AnQid)" />
                                                </td>
                                                <!-- Salary Type -->
                                                <td label="@Loc.SalaryTypeShort">
                                                    <div class="ddw-full-width select2HideColumns">
                                                        <select id="input-salary-type-@item.AnQid"
                                                                data-placeholder="@Loc.SalaryTypeShort"
                                                                class="form-control select2withAPI"
                                                                data-column-names="@Loc.Code,@Loc.Name"
                                                                data-bootstrap-columns="col-md-3,col-md-9"
                                                                data-search-width="350"
                                                                data-mobile-width="200"
                                                                data-url=@Url.Action("GetSalaryTypes", "SetCalendarEntryTypes")
                                                                onchange="setSalaryTypeVal(@item.AnQid)">
                                                            <option selected="selected" value="@item.Et">@item.Et</option>
                                                        </select>
                                                    </div>
                                                </td>
                                                @{
                                                    var operation = item.Operation;

                                                    if (string.IsNullOrEmpty(item.Operation))
                                                    {
                                                        operation = "n";
                                                    }
                                                }
                                                @if (Model.Type == WorkHourEntryType.EntryTypes)
                                                {
                                                    <!-- Operation -->
                                                    <td label="@Loc.Operation">
                                                        <div class="ddw-full-width select2HideColumns">
                                                            <select id="input-operation-@item.AnQid"
                                                                    data-placeholder="@Loc.Operation"
                                                                    class="form-control select2withAPI"
                                                                    data-search-width="100"
                                                                    data-mobile-width="200"
                                                                    data-column-names="@Loc.Name"
                                                                    data-url=@Url.Action("GetOperations", "SetCalendarEntryTypes")
                                                                    data-bootstrap-columns="col-md-12"
                                                                    onchange="saveEntryType(@item.AnQid)">
                                                                <option selected="selected" value="@operation">@item.OperationText</option>
                                                            </select>
                                                        </div>
                                                    </td>
                                                    <!-- IsWorkFromHome -->
                                                    <td label="@Loc.SetIsWorkFromHome" style="padding-top: 5px;">
                                                        <input id="input-work-from-home-@item.AnQid" type="checkbox" class="form-control checkbox-left" checked="@item.IsWorkFromHome" onchange="saveEntryType(@item.AnQid)" />
                                                    </td>
                                                }
                                                <!-- Icon -->
                                                <td label="@Loc.Icon">
                                                    <div class="dropdown d-inline-block" data-toggle="dropdown">
                                                        @{
                                                            var faIcon = string.IsNullOrEmpty(item.Icon) ? "fa-search" : item.Icon;
                                                        }
                                                        <p class="dropdown-toggle no-caret" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                            <i id="input-icon-@item.AnQid" class="picker-icon picker-icon-small fa @faIcon" aria-hidden="true">
                                                                <span class="hidden" id="input-icon-val-@item.AnQid">@item.Icon</span>
                                                            </i>
                                                        </p>
                                                        <div class="custom-ddw icon-ddw-container dropdown-menu dropdown-menu-right rounded-0 box-shadow">
                                                            <div class="row">
                                                                @foreach (var icon in Model.Icons)
                                                                {
                                                                    <div class="col-md-2 custom-ddw-item">
                                                                        <span onclick="setIcon('@icon.Key.ToString()', @item.AnQid)" class="picker-icon picker-icon-medium fa @icon.Key.ToString()"></span>
                                                                    </div>
                                                                }
                                                            </div>
                                                        </div>
                                                    </div>
                                                </td>
                                                <!-- Main Color -->
                                                <td label="@Loc.MainColor" id="td-input-main-color-@item.AnQid">
                                                    <div class="dropdown d-inline-block margin-top-7" data-toggle="dropdown">
                                                        <p class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                            <div class="dropdown color-picker-box" style="background-color: @item.BackgroundColor" id="input-main-color-box-@item.AnQid"></div>
                                                            <span class="hidden" id="input-main-color-val-@item.AnQid">@item.BackgroundColor</span>
                                                        </p>
                                                        <div class="custom-ddw custom-ddw-no-x custom-ddw-h-500 dropdown-menu dropdown-menu-right rounded-0 box-shadow">
                                                            <div class="row">
                                                                @foreach (var color in Model.MainColors)
                                                                {
                                                                    <div class="col-md-12 custom-ddw-item"
                                                                         onclick="setMainColor('@color.Key.ToString()', '@color.Name', @item.AnQid)">
                                                                        <div class='color-picker-box' style="background-color: @color.Key.ToString()"></div>
                                                                        <p> @color.Name</p>
                                                                    </div>
                                                                }
                                                            </div>
                                                        </div>
                                                    </div>
                                                </td>
                                                <!-- Text color-->
                                                @*<td label="@Loc.BackColor" id="td-input-text-color-@item.AnQid" class="last-column">
                                                    <div class="dropdown d-inline-block margin-top-7" data-toggle="dropdown">
                                                        <p class="dropdown-toggle fa fa-chevron-down" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                            <div class="dropdown color-picker-box" style="background-color: @item.TextColor" id="input-text-color-box-@item.AnQid"></div>
                                                            <span class="hidden" id="input-text-color-val-@item.AnQid">@item.TextColor</span>
                                                        </p>
                                                        <div class="custom-ddw custom-ddw-no-x custom-ddw-h-500 dropdown-menu dropdown-menu-right rounded-0 box-shadow">
                                                            <div class="row">
                                                                @foreach (var color in Model.MainColors)
                                                                {
                                                                    <div class="col-md-12 custom-ddw-item"
                                                                         onclick="setTextColor('@color.Key.ToString()', '@color.Name', @item.AnQid)">
                                                                        <div class='color-picker-box' style="background-color: @color.Key.ToString()"></div>
                                                                        <p> @color.Name</p>
                                                                    </div>
                                                                }
                                                            </div>
                                                        </div>
                                                    </div>
                                                </td>*@
                                                <!-- Action -->
                                                <td class="td-action">
                                                    <p class="text-center" title="@Loc.Delete">
                                                        <span onclick="deleteEntryType(@item.AnQid)" style="margin-top: 12px" class="far fa-trash-alt cursor-pointer" aria-hidden="true"></span>
                                                    </p>
                                                </td>
                                            </tr>
                                        }
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="divided-content-side" style="min-height: 88vh">
                    @{Html.RenderAction("SideMenu", "SetWorkHours", new { activeId = Model.Id }); }
                </div>

                @Html.Hidden("AcType", Model.Type)
            </div>
        </div>
    </div>
</div>

@section pageScripts{
    @* TODO: remove after refactor *@
    @Scripts.Render("~/bundles/validation")
    <script src="~/Scripts/global-script.js"></script>
    <script src="~/Scripts/jquery.ui.touch-punch.js"></script>
}

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- This will be moved into js on the task finish -->
<script>

    $("#sortable-body").sortable({
        items: 'tr:not(tr:first-child)',
        cursor: "move",
        placeholder: "sortable-placeholder",
        helper: function (e, tr) {
            var $originals = tr.children();
            var $helper = tr.clone();
            $helper.children().each(function (index) {
                // Set helper cell sizes to match the original sizes
                $(this).width($originals.eq(index).width());
                $(this).find("input").css("background-color", "transparent");
                $(this).find(".select2-selection").css("background-color", "transparent");
                $(this).addClass("sortable-color");
            });
            return $helper;
        },
        update: function (event, ui) {

            var data = new Array();
            $('.sortable-row').each(function () {
                data.push($(this).data("id"));
            });

            $.ajax({
                data: { anQIds: data },
                type: 'POST',
                url: $("#UrlSaveOrder").val()
            });
        }
    }).disableSelection();

    $(document).ready(function () {
        $(this).find('input[type="checkbox"]').customCheckbox();

        $("#Keywords").on("keyup", function () {
            var filter = $(this).val().toLowerCase();

            $('#tblSetCalEntryTypes tr').each(function (i, row) {
                if (i <= 1
                    || row.innerHTML.toLowerCase().indexOf('value="' + filter) > -1
                    || row.innerHTML.toLowerCase().indexOf('>' + filter) > -1) {
                    row.style.display = "";
                }
                else {
                    row.style.display = "none";
                }
            });

        });
    });

    $(document).ajaxError(function () {
        location.reload();
    });

    function setSalaryTypeVal(anQid) {
        let id = "input-salary-type";

        if (anQid) {
            id += ("-" + anQid);
        }

        let typeVal = $("#" + id).val();

        let closeContent = anQid ? '' : ' <span onclick="clearSalaryType()">×</span> ';

        setTimeout(function () { $("#select2-" + id + "-container").html(closeContent + typeVal); }, 30);

        if (anQid) {
            saveEntryType(anQid);
        }
    }

    function clearSalaryType() {
        setTimeout(function () { $("#select2-input-salary-type-container").html(""); }, 100);

        var data = new Option(null, null, false, false);
        $('#input-salary-type').append(data).trigger('change');
    }

    function setIcon(icon, anQid) {
        let inputId = "#input-icon";
        let inputValId = "#input-icon-val";

        if (anQid != 0) {
            inputId += ("-" + anQid);
            inputValId += ("-" + anQid);
        }

        $(inputId)
            .removeClass()
            .addClass("picker-icon picker-icon-small fa " + icon);

        $(inputValId).text(icon);

        if (anQid != 0) {
            saveEntryType(anQid);
        }
    }

    function setMainColor(color, name, anQid) {
        let colorId = "#input-main-color-box";
        let colorNameId = "#input-main-color-name";
        let colorValId = "#input-main-color-val";

        if (anQid > 0) {
            colorId += ("-" + anQid);
            colorNameId += ("-" + anQid);
            colorValId += ("-" + anQid);
        }

        $(colorId).css("background-color", color);
        $(colorNameId).text(name);
        $(colorValId).text(color);

        if (anQid > 0) {
            saveEntryType(anQid);
        }
    }

    function setTextColor(color, name, anQid) {
        let colorId = "#input-text-color-box";
        let colorNameId = "#input-text-color-name";
        let colorValId = "#input-text-color-val";

        if (anQid > 0) {
            colorId += ("-" + anQid);
            colorNameId += ("-" + anQid);
            colorValId += ("-" + anQid);
        }

        $(colorId).css("background-color", color);
        $(colorNameId).text(name);
        $(colorValId).text(color);

        if (anQid > 0) {
            saveEntryType(anQid);
        }
    }

    function deleteEntryType(anQid) {
        var deleteText = $("#TxtDeleteQuestion").val();
        var deleteTitle = $("#TxtConfirmation").val();
        var confirmText = $("#TxtConfirm").val();
        var cancelText = $("#TxtCancel").val();

        $(document).ready(function () {
            $().customModal({
                destroyOnClose: true,
                title: deleteTitle,
                showCloseButton: true,
                help: function () {

                },
                id: "modalDeleteEntryType",
                type: "question",
                text: deleteText,
                buttons: [{
                    icon: 'fa fa-times',
                    text: cancelText,
                    action: function () {

                    },
                    closeOnAction: true,
                    type: 'ghost'
                },
                {
                    icon: 'fa fa-check',
                    text: confirmText,
                    closeOnAction: true,
                    action: async function () {
                        await new Promise((resolve, reject) => setTimeout(function () {
                            removeEntryType(anQid);
                            resolve();
                        }, 1500));
                    },
                    closeOnAction: true,
                    type: 'primary'
                }]
            });
        });
    }

    function removeEntryType(anQid) {
        $.ajax({
            url: $("#UrlDelete").val() + '?anQId=' + anQid,
            type: 'GET',
            success: function (data) {
                if (data && data.Status) {
                    $("#tr-" + anQid).remove();
                }
                else {
                    $(document).ready(function () {
                        $().customModal({
                            destroyOnClose: true,
                            title: '',
                            showCloseButton: true,
                            help: function () {

                            },
                            id: "modalDeleteEntryTypeNotPossible",
                            type: "alert",
                            text: $("#TxtDelNotPossible").val(),
                            buttons: [
                                {
                                    icon: 'fa fa-check',
                                    text: $("#TxtConfirm").val(),
                                    closeOnAction: true,
                                    type: 'primary'
                                }]
                        });
                    });
                }
            }
        });
    }

    function saveEntryType(anQid) {
        let sufix = (anQid && anQid != 0) ? "-" + anQid : "";
        let operation = $("#input-operation" + sufix).val();
        if (operation == "n") {
            operation = " ";
        }

        let data = {
            AnQid: anQid ? anQid : 0,
            Code: $("#input-code" + sufix).val(),
            Name: $("#input-name" + sufix).val(),
            IsWorkFromHome: $("#input-work-from-home" + sufix).is(":checked") ? true : false,
            Type: $("#AcType").val(),
            SalaryType: $("#input-salary-type" + sufix).val(),
            Operation: operation,
            Icon: $("#input-icon-val" + sufix).text(),
            MainColor: $("#input-main-color-val" + sufix).text(),
            TextColor: $("#input-text-color-val" + sufix).text(),
        };

        if (!data.Code || !data.Name) {
            $(document).ready(function () {
                $().customModal({
                    destroyOnClose: true,
                    title: '',
                    showCloseButton: true,
                    help: function () {

                    },
                    id: "modalSaveEntryTypeInfo",
                    type: "alert",
                    text: $("#TxtInputFields").val(),
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: $("#TxtConfirm").val(),
                            closeOnAction: true,
                            type: 'primary'
                        }]
                });
            });
        }
        else {
            postEntryType(data);
        }
    }

    function postEntryType(data) {
        $.ajax({
            url: $("#UrlSave").val(),
            type: 'POST',
            data: data,
            success: function (data) {
                if (data.Message == "Code") {
                    $(document).ready(function () {
                        $().customModal({
                            destroyOnClose: true,
                            title: '',
                            showCloseButton: true,
                            help: function () {

                            },
                            id: "modalAlreadyExists",
                            type: "alert",
                            text: $("#PrimaryKeyExists").val(),
                            buttons: [
                                {
                                    icon: 'fa fa-check',
                                    text: $("#TxtConfirm").val(),
                                    closeOnAction: true,
                                    type: 'primary'
                                }]
                        });
                    });
                }
                else if (!data.AnQid) {
                    location.reload();
                }
            }
        });
    }
</script>