<?php echo View::make('/../include/header'); ?>

<!-- <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css" rel="stylesheet"> -->
<!-- <link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet"> -->
<head>
    <title>Datatables Server Side Processing in Laravel</title>
 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>   
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js"></script>
</head>


    <section id="main-content">
      <section class="wrapper">
      <div class="row">
          <div class="col-lg-12 main-chart">
            <!--CUSTOM CHART START -->
            <div class="border-head">

              <h3>Update Product</h3>
            </div>

    <div align="right">
        <!-- <button type="button" name="add" id="add_data" class="btn btn-success btn-sm">Add Attribute</button> -->
        <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#studentModal" data-whatever="@getbootstrap">Add Attribute</button>

    </div>
    <br />
    <table id="example" class="table table-striped table-bordered" style="width:100%">
        <thead>
            <tr>
                <th>Product Name</th>
                <th>Attribute Name</th>
                <th>Attributes</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
        <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td><?php echo e($data->Attributeids->name); ?></td>
                <td><?php echo e($data->attname); ?></td>
                <td><?php echo e($data->attributes); ?></td>
                <td class="text-center">                            
                <button type="button" data-id="<?php echo e($data->id); ?>" data-name="<?php echo e($data->attname); ?>" data-proid="<?php echo e($data->proid); ?>" data-attname="<?php echo e($data->attributes); ?>" class="btn btn-info btn-xs" data-toggle="modal" data-target="#editordermodel">Edit</button>
                    <a class="btn btn-danger btn-xs" data-id="<?php echo e($data->id); ?>"  href=""><i class="fa fa-trash-o "></i></a>
                </td>
                
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
        </tbody>
        <tfoot>
            <tr>
                <th>Product Name</th>
                <th>Attribute Name</th>
                <th>Attributes</th>
                <th>Action</th>
            </tr>
        </tfoot>
    </table>


<div id="studentModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <form  action="/addattributes"  method="post" enctype="multipart/form-data">
            <?php echo e(csrf_field()); ?>

                <div class="modal-header">
                   <button type="button" class="close" data-dismiss="modal">&times;</button>
                   <h4 class="modal-title">Add Attribute</h4>
                </div>
                <div class="modal-body">
                    
                    <span id="form_output"></span>
                    
                    <div class="form-group">
                        <label>Product Name</label><a style="color:red;"></a> 
                        <select class="js-example-basic-single" name="nameproduct2" style="width:567px;">
                        <!-- <option selected disabled>Product Name</option> -->
                        <?php $__currentLoopData = $product; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($data->id); ?>"><?php echo e($data->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
                    </select>
                    <script>
                        $(document).ready(function() {
                            $('.js-example-basic-single').select2();
                        });
                    </script>                   
                    </div>
                    <div class="form-group">
                        <label>Attribute Name</label><a style="color:red;">*color</a> 
                        <input type="text" name="name" id="name" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label>Attributes</label> <a style="color:red;">*red,black,white</a> 
                        <input type="text" name="att" id="att" class="form-control" />
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="submit" name="submit" id="action" value="Add" class="btn btn-info" />
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </form>
        </div>
    </div>
</div>


<div class="modal fade" id="editordermodel" role="dialog">
        <div class="modal-dialog">
        
          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
                    <h4 class="modal-title">Update Attributes</h4>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              
            </div>
            
            <form  action="/updateaddattributes"  method="post" enctype="multipart/form-data">
            <?php echo e(csrf_field()); ?>

                <div class="modal-body">
                <input type="hidden" id="id" name="id">

                <div class="form-group">
                        <label>Product Name</label><a style="color:red;"></a> 
                        <select class="js-example-basic-single" id="nameproduct" name="nameproduct" style="width:567px;">
                        <!-- <option selected disabled>Product Name</option> -->
                        <?php $__currentLoopData = $product; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option id="<?php echo e($data->id); ?>" value="<?php echo e($data->id); ?>"><?php echo e($data->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
                    </select>
                    <script>
                        $(document).ready(function() {
                            $('.js-example-basic-single').select2();
                        });
                    </script>                   
                    </div>
                <div class="form-group">
                        <label>Attribute Name</label><a style="color:red;">*color</a> 
                        <input type="text" name="name" id="name" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label>Attributes</label> <a style="color:red;">*red,black,white</a> 
                        <input type="text" name="att" id="att" class="form-control" />
                    </div>
                    
                </div>
                  
            <div class="modal-footer">
            <input type="submit" name="btnform1" id="action" class="btn btn-primary right" value="Update Attributes"/>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            </form>
          </div>
          
        </div>

</div>
<script>
    $('#editordermodel').on('show.bs.modal', function (event) {

    var button = $(event.relatedTarget) // Button that triggered the modal

    var id = button.data('id') 
    var name = button.data('name') 
    var attname = button.data('attname') 
    var proid = button.data('proid') 

    var modal = $(this)
    //   modal.find('.modal-title').text('New message to ' + recipient)
    modal.find('.modal-body #id').val(id)
    modal.find('.modal-body #name').val(name)
    modal.find('.modal-body #att').val(attname)
    $("#nameproduct").val(proid).change();


    })
</script>

        </div>
        </div>
      </section>
    </section>


<script>
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>


<script>
$(document).on('click', '.btn-danger', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove Attribute",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/deletattribute')); ?>/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                swal("Done!", "It was successfully deleted!", "success");
                                $(ele).closest('tr').hide();
                                // $("#here").load(location.href + " #here");
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Treatment Removed", "error");
                }
            })
});
</script>

<!-- <footer class="site-footer">
      <div class="text-center">
        <p>
          &copy; Copyrights <strong>Dashio</strong>. All Rights Reserved
        </p>
        <div class="credits">

          Created with Dashio template by <a href="https://templatemag.com/">TemplateMag</a>
        </div>
        <a href="index.html#" class="go-top">
          <i class="fa fa-angle-up"></i>
          </a>
      </div>
    </footer> -->

<style>
    .site-footer {

    position: fixed;
   left: 0;
   z-index: -1;
   bottom: 0;
   width: 100%;
}
</style>
    <!--footer end-->
  </section>
  <!-- js placed at the end of the document so the pages load faster -->
  <!-- <script src="<?php echo e(asset('dash/lib/jquery/jquery.min.js')); ?>"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
   -->


  <script src="<?php echo e(asset('dash/lib/bootstrap/js/bootstrap.min.js')); ?>"></script>
  <script class="include" type="text/javascript" src="<?php echo e(asset('dash/lib/jquery.dcjqaccordion.2.7.js')); ?>"></script>
  <script src="<?php echo e(asset('dash/lib/jquery.scrollTo.min.js')); ?>"></script>
  <script src="<?php echo e(asset('dash/lib/jquery.nicescroll.js')); ?>" type="text/javascript"></script>
  <script src="<?php echo e(asset('dash/lib/jquery.sparkline.js')); ?>"></script>

<!--sweet alert-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.29.2/sweetalert2.all.js"></script>

  <!--common script for all pages-->
  <script src="<?php echo e(asset('dash/lib/common-scripts.js')); ?>"></script>
  <script type="text/javascript" src="<?php echo e(asset('dash/lib/gritter/js/jquery.gritter.js')); ?>"></script>
  <script type="<?php echo e(asset('dash/text/javascript" src="lib/gritter-conf.js')); ?>"></script>
  <!--script for this page-->
  <script src="<?php echo e(asset('dash/lib/sparkline-chart.js')); ?>"></script>
  <script src="<?php echo e(asset('dash/lib/zabuto_calendar.js')); ?>"></script>

</body>

</html>

