
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="role-mode" id="add_Branch" aria-hidden="true" style="display: none;     width: 40%;
     margin: 0 auto;">
    <div class="modal-dialog">
        <div class="modal-content">
            <?php echo Forms::ModalLoader('BranchIsBusy') ?>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel"> <?php print CommonLanguage::getMessage('add_department'); ?></h4>
                <br>
            </div>
            <div class="modal-body">
                <div id="BranchValidation"></div>
                <div class="form-group col-md-12">
                    <div  class=" col-md-12 form-group">
                        <label><?php print CommonLanguage::getMessage('department_name'); ?></label><span class="red-star">*</span>
                        <input type="text" name="Branch_Name"  id="Branch_Name" placeholder="<?php print CommonLanguage::getMessage('department_name'); ?>" class="form-control input-rounded" required>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" id="CloseBranch" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button type="submit" class="btn btn-success " id="SubmitBranch"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
        </div>
    </div>
</div>
<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>;
    var CurrentID;
    $(function () {

        $("#tableWithSearch").on("click", ".Action .Edit", function (e) {
            $('#add_Branch').modal('show')
            window.CurrentID = $(this).parents("tr").find('.Action').attr("data-id");
            $('#myModalLabel').empty().html('Edit Department');
            $("#Branch_Name").val($(this).parents('tr').find('td:eq(0)').html());
        })
        $("#SubmitBranch").on("click", function () {
            if ($("#Branch_Name").val() == '') {
                $("#BranchValidation").attr("class", "alert alert-danger").html(Required_Fields)
                return;
            }
            $("#BranchIsBusy").removeClass('hidden');
            var Data = {
                Branch_Name: $("#Branch_Name").val(),
                Branch_ID: CurrentID
            }

            $.ajax({
                url: "HRMAjax/ViewDepartmentRequest",
                method: "POST",
                data: Data,
                complete: function (v1, v2) {
                    if (v2 == 'success') {
                        if (v1.responseText == 'ok') {
                            RebuildDataTable('Department', [0], 'HRMAjax/ViewDepartmentRequest', 1)
                            $("#BranchValidation").attr("class", "alert alert-success").empty().html(Submitted_Successfully);

                        } else {
                            $("#BranchValidation").attr("class", "alert alert-danger").empty().html(v1.responseText);
                        }

                    } else {
                        $("#BranchValidation").attr("class", "alert alert-danger").empty().html(Failed_Submit);
                    }
                    setTimeout(function () {
                        $("#add_Branch").modal('hide')
                        $("#BranchValidation").addClass("hidden")
                        $("#add_Branch input").val("");
                    }, 1000)
                    $("#BranchIsBusy").addClass('hidden');
                }

            });


        });
    })


</script>