<?php echo $__env->make('header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<div class="container-fluid flex-grow-1 container-p-y">


    <div class="row">
        <!-- customar project  start -->
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">
                    <div class="row align-items-center m-l-0">



                        <div class="col-sm-2 text-left">
                            <button class="btn btn-success btn-sm mb-3 btn-round" data-toggle="modal"
                                data-target="#modal-report" id="add_button"><i class="feather icon-plus"></i> Add
                                User</button>
                        </div>


                    </div>
                    <hr>
                    <div class="table-responsive" id="custresult">

                    </div>
                </div>
            </div>
        </div>
        <!-- customar project  end -->
    </div>
</div>

<div class="modal fade" id="modal-report" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" style="max-width: 70rem; ">
        <div class="modal-content">


            <div class="modal-header">
                <h5 class="modal-title">Add User</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="validation-form" method="POST">
                    <div class="row">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="action" id="action" value="Save">
                        <input type="hidden" name="id" id="id" />
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="Name">Name <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Name" name="Name" placeholder="" required>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="Name">User Name <span
                                        class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Username" name="Username" placeholder=""
                                    oninput="checkUsername()" required>
                                <span id="error_msg" style="color:red;display: none;">Username Already Exists!</span>
                            </div>

                        </div>

                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="Name">Password <span
                                        class="text-danger">*</span></label>
                                <input type="password" class="form-control" id="Password" name="Password" placeholder=""
                                    required>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="gender">Type <span
                                        class="text-danger">*</span></label>
                                <select class="form-control" id="Type" name="Type" required
                                    onchange="getType(this.value)">
                                    <option value=""></option>
                                    <option value="Admin">Admin</option>
                                    <option value="Consultant">Consultant</option>
                                    <option value="Optometrist">Optometrist</option>
                                    <option value="Reception">Reception</option>
                                </select>
                            </div>
                        </div>
                        <script type="text/javascript">
                        function getType(val) {
                            if (val == 'Consultant') {
                                $('.required_cls').attr('required', 'required');
                                $('.star').show();
                            } else {
                                $('.required_cls').attr('required', false);
                                $('.star').hide();
                            }
                        }
                        </script>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Mobile <span
                                        class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="Phone" name="Phone" placeholder=""
                                    onKeyPress="return isNumberKey(event)" required>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Registration No <span class="text-danger star"
                                        style="display:none;">*</span></label>
                                <input type="text" class="form-control required_cls" id="RegNo" name="RegNo"
                                    placeholder="">
                            </div>
                        </div>


                        <div class="col-sm-2">
                            <div class="form-group">
                                <label class="floating-label" for="Phone">Fees <span class="text-danger star"
                                        style="display:none;">*</span></label>
                                <input type="text" class="form-control required_cls" id="Fees" name="Fees"
                                    placeholder="" onKeyPress="return isNumberKey(event)" value="0">
                            </div>
                        </div>


                        <div class="col-sm-12">
                            <button class="btn btn-primary" type="submit" name="submit" id="submit">Submit</button>
                            <button class="btn btn-danger" type="reset">Clear</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php echo $__env->make('footerscript', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script type="text/javascript">
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function success_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.notice({
        title: 'Success',
        message: 'New User Added Successfully!',
        location: isRtl ? 'tl' : 'tr'
    });
}

function error_toast() {
    var isRtl = $('body').attr('dir') === 'rtl' || $('html').attr('dir') === 'rtl';
    $.growl.error({
        title: 'Error',
        message: 'Username Already Exists',
        location: isRtl ? 'tl' : 'tr'
    });
}

function user_lists() {
    $.ajax({
        type: "POST",
        url: "<?php echo e(url('usermasterlist')); ?>",
        data: {
            _token: '<?php echo e(csrf_token()); ?>'
        },
        success: function(data) {
            //console.log(data);
            $('#custresult').html(data);
        }
    });
}


$(document).ready(function() {
    user_lists();

    $('#add_button').click(function() {
        $('.modal-title').html("Add <span class='font-weight-light'>New User</span>");
        $('#action').val("Save");
        $('#id').val('');

        $('#Name').val('');
        $('#Username').val('').attr('readonly', false);
        $('#Type').val('').attr("selected", true);
        $('#Password').val('');
        $('#Phone').val('');
        $('#RegNo').val('');
        $('#Fees').val(0);
        $('#submit').text('Submit');

    })

    $('#validation-form').on('submit', function(e) {
        e.preventDefault();
        if ($('#validation-form').valid()) {
            $.ajax({
                url: "<?php echo e(url('usermastersave')); ?>",
                method: "POST",
                data: new FormData(this),
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#submit').attr('disabled', 'disabled');
                    $('#submit').text('Please Wait...');
                },
                success: function(data) {
                    //alert(data);
                    $('#submit').attr('disabled', false);
                    $('#submit').text('Submit');
                    //console.log(data);exit();
                    if (data == 1) {
                        $('#modal-report').modal('hide');
                        success_toast();
                        user_lists();

                    } else {
                        error_toast();
                        $('#modal-report').modal('show');
                    }

                }
            });
        }
    });

    $(document).on("click", ".update", function(event) {
        event.preventDefault();
        event.stopPropagation();
        var id = $(this).attr("data-id");
        var action = "fetch_record";
        $.ajax({
            url: "<?php echo e(url('showData')); ?>",
            method: "POST",
            data: {
                _token: '<?php echo e(csrf_token()); ?>',
                id: id
            },
            dataType: "json",
            success: function(data) {
                //console.log(data);exit();
                $('#Name').val(data.Name);
                $('#Username').val(data.Username).attr('readonly', 'readonly');
                $('#Type').val(data.Type).attr("selected", true);
                $('#Password').val(data.Password);
                $('#Phone').val(data.Phone);
                $('#RegNo').val(data.RegNo);
                $('#Fees').val(data.Fees);
                $('#action').val('Edit');

                $('#id').val(id);
                $('#submit').text("Update");
                $('#modal-report').modal('show');
                $('.modal-title').html(
                "Update <span class='font-weight-light'>User</span>");

            }
        });
    });

    $(document).on("click", ".delete", function(event) {
        event.preventDefault();
        var id = $(this).attr("data-id");
        var action = "delete";
        //alert(id);
        swal({
            title: "Are you sure?",
            text: "You will not be able to recover this User!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger",
            confirmButtonText: "Yes, delete",
            cancelButtonText: "No, cancel",
            closeOnConfirm: false,
            closeOnCancel: false
        }, function(isConfirm) {
            if (isConfirm) {
                $.ajax({
                    url: "<?php echo e(url('deleteuser')); ?>",
                    method: "POST",
                    data: {
                        _token: '<?php echo e(csrf_token()); ?>',
                        id: id
                    },

                    success: function(data) {
                        //console.log(data);exit();
                        swal("Deleted!", "User has been deleted.", "success");

                        user_lists();

                    }
                });

            } else {
                swal("Cancelled", "User is safe :)", "error");
            }
        });


    });

});
</script>
<?php /**PATH C:\laragon\www\parijathosp\resources\views/masters/usermaster.blade.php ENDPATH**/ ?>