

<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
    <div class="top-header">
        <ol class="breadcrumb">
            <li><a href="#"><?php echo e(__('administrator.Dashboard')); ?></a></li>
        </ol>
    </div>
    <style>
        .jconfirm-content-pane input{
            margin-bottom: 10px;
        }
    </style>

    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3><?php echo e(__('administrator.blackout')); ?> </h3>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add">
                        <div class="pull-right">
                            <a href="javascript:void(0)"
                               class="button_primary create_blackout"><?php echo e(__('administrator.add_new')); ?></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body">
            <table id="datatable_products" width="100%" class="table table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.title')); ?></th>
                        <th><?php echo e(__('administrator.deduct')); ?></th>
                        <th><?php echo e(__('administrator.date')); ?></th>
                        <th><?php echo e(__('administrator.note')); ?></th>
                        <th style="width: 200px"><?php echo e(__('administrator.action')); ?></th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#datatable_products').DataTable({
                ordering: false,
                serverSide: true,
                ajax: "<?php echo e(route('blackout.index')); ?>",
                lengthMenu: [[20, 30, 50, 100, 1000], [20, 30, 50, 100, 1000]],
                columns:
                    [
                        {data: 'DT_RowIndex', orderable: false, searchable: false},
                        {data: 'title',},
                        {data: 'deduct'},
                        {data: 'date'},
                        {data: 'note'},
                        {data: 'action'},
                    ],
                "initComplete": function (settings, json) {
                }
            });

            $.fn.dataTable.ext.errMode = 'throw';
        });

        var $form_content = `
                <input type="text" name="title_blackout" class="form-control border-red" required placeholder="<?php echo e(__('administrator.title')); ?>" maxlength="50" >
                <input type="text" name="deduct" class="form-control border-red number-only" placeholder="<?php echo e(__('administrator.deduct')); ?>" maxlength="50" >
                <input type="date" name="date" class="form-control border-red" placeholder="<?php echo e(__('administrator.date')); ?>" maxlength="50" >
                <input type="text" name="duration" class="form-control" placeholder="<?php echo e(__('administrator.duration')); ?>" maxlength="50" >
                <textarea name="note" rows="3" maxlength="150" class="no-resize form-control" placeholder="<?php echo e(__('administrator.note')); ?>" ></textarea>
                `;

        $('.create_blackout').on('click', function () {
            form(
                $form_content,
                '<?php echo e(__("administrator.submit")); ?>',
                '<?php echo e(__("administrator.create")); ?>',
                '<?php echo e(route("blackout.store")); ?>'
                );
        });

        $(document).on('click','.edit_blackout', function () {

            var url = $(this).data('href');
            $.ajax({
                url: url,
                dataType: 'json',
                method: 'get'
            }).done(function (response) {

                form(
                    $form_content,
                    '<?php echo e(__("administrator.update")); ?>',
                    '<?php echo e(__("administrator.edit")); ?>',
                    '<?php echo e(route("blackout-update")); ?>',
                    response.title,
                    response.deduct,
                    response.date,
                    response.duration,
                    response.note,
                    response.id
                );

            }).fail(function (response) {
                console.log(response);
            });
        });

        function form($fcontent = '', btntext = '', title = '', route = '', title_blackout = '', deduct = '', date = '', duration = '', note='', id = '')
        {
            $.confirm({
                title: title + ' <?php echo e(__("administrator.blackout")); ?>',
                content: $fcontent,
                theme: 'modern',
                buttons: {
                    cancel: {
                        text: '<?php echo e(__("administrator.cancel")); ?>',
                        btnClass: 'button_warning',
                        action: function () {

                        }
                    },
                    submit: {
                        text: btntext,
                        btnClass: 'button_primary',
                        action: function () {
                            let self            = this;
                            let title_blackout  = self.$content.find('input[name=title_blackout]').val();
                            let deduct          = self.$content.find('input[name=deduct]').val();
                            let date            = self.$content.find('input[name=date]').val();
                            let duration        = self.$content.find('input[name=duration]').val();
                            let note            = self.$content.find('textarea[name=note]').val();
                            self.buttons.submit.disable();
                            $.ajax({
                                url: route,
                                dataType: 'json',
                                method: 'post',
                                data: {
                                    "_token": "<?php echo e(csrf_token()); ?>",
                                    title_blackout: title_blackout,
                                    deduct: deduct,
                                    date: date,
                                    duration: duration,
                                    note: note,
                                    id: id,
                                }
                            }).done(function (response) {
                                if (response === 'success') {
                                    window.location.reload();
                                }
                            }).fail(function (xhr) {
                                alertErrorFormController(xhr, self)
                            });

                            return false;
                        }
                    },
                }
            });

            if (id) {
                setTimeout(function () {
                    $(document).find('input[name=title_blackout]').val(title_blackout);
                    $(document).find('input[name=deduct]').val(deduct);
                    $(document).find('input[name=date]').val(date);
                    $(document).find('input[name=duration]').val(duration);
                    $(document).find('textarea[name=note]').text(note);
                    $(".focus").focus();
                }, 1);
            }
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app-hr', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/hr/blackout/index.blade.php ENDPATH**/ ?>