<!-- Main Content -->

<div class="page-wrapper">

<div class="container-fluid pt-25">

   <div class="row">

      <div class="col-md-12">

         <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >

            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>

            <?php echo $this->session->flashdata('message'); ?>

         </div>

      </div>

   </div>

   <!-- Row -->

   <div class="row">

      <div class="col-sm-12">

         <div class="panel panel-default card-view">

            <div class="panel-heading">

               <div class="pull-left">

                  <h6 class="panel-title txt-dark">Category List </h6>

               </div>

               <div class="pull-right">
                  <?php if($this->admin_type=='superadmin' || (in_array('5.2', $this->authority))){ ?>
                     <a  data-toggle="modal" data-target="#addAdmin" class="btn btn-primary"> Add Category </a>
                  <?php } ?>

               </div>

               <div class="clearfix"></div>

            </div>

            <div class="panel-wrapper collapse in">

               <div class="panel-body">

                  <div class="table-wrap">

                     <div class="table-responsive">

                        <table id="datable_1" class="table table-hover">

                           <thead>

                              <tr>

                                 <th>Sr. No.</th>

                                 <!-- <th>Image</th> -->
                                 <th>Category</th>

                                 <th>Action</th>

                              </tr>

                           </thead>

                           <tbody class="tbody">

                              <?php 

                                 if($cat){ foreach ($cat as $key => $value) : 

                              ?>

                              <tr class="orderby" id="<?php echo "gallery_category_".$value['id']; ?>" data-order="<?php echo $value['id']; ?>">

                                 <td><?php echo ($key+1); ?></td>
                                 <?php /* ?>
                                 <td>
                                    <?php if($value['image']!=''){ ?>
                                      <img src="<?php echo base_url($value['image']); ?>" style="width:100px" alt="img">
                                    <?php } ?>
                                 </td>
                                 <?php */ ?>
                                 <td><?php echo $value['category']; ?></td>

                                 <td>
                                    <?php if($this->admin_type=='superadmin' || (in_array('5.3', $this->authority))){ ?>
                                       <a href="<?php echo base_url(A.'/edit-gallery-category/'.$value['id']); ?>" class="text-inverse pr-10"  title="Edit Category">
                                         <button class="btn btn-info btn-icon-anim btn-square"><i class="fa fa-pencil fa-lg"></i></button>
                                       </a>
                                    <?php } ?>
                                    <?php if($this->admin_type=='superadmin' || (in_array('5.4', $this->authority))){ ?>
                                       <a href="javascript:void(0)" class="cat_delete" data-table="gallery_category" data-value="<?php echo "id_".$value['id']; ?>" data-image='' data-id="<?php echo $value['id']; ?>">

                                          <button class="btn btn-danger btn-icon-anim btn-square"><i class="fa fa-trash fa-lg"></i></button>

                                       </a>
                                    <?php } ?>

                                    

                                    </td>

                              </tr>

                              <?php endforeach; } ?>

                           </tbody>

                        </table>

                     </div>

                  </div>

               </div>

            </div>

         </div>

      </div>

   </div>

   <!-- /Row -->

</div>





<div class="modal fade" id="addAdmin" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add Category</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form id="addUserForm" action="<?php echo base_url(A.'/addGalleryCategory'); ?>" method="post" enctype="multipart/form-data">
        <div class="modal-body">          
          <div class="form-group">
            <label>Category Name</label>
            <input type="text" name="category" class="form-control" placeholder="Enter Category" />
          </div>       
          <!-- <div class="form-group">
            <label>Image</label>
            <input type="file" name="image" class="form-control"/>
            <p>image size 1606x433 px</p>
          </div> -->
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-primary">Submit</button>
        </div>
    </form>    
  </div>
  </div>
</div>

<script type="text/javascript">
  var site_url = "<?php echo base_url(); ?>";
  var urlLink = "<?php echo A; ?>";

  $(".cat_delete").on("click",function(){

      var table = $(this).attr('data-table');

      var id = $(this).attr('data-id');

      var pimage = $(this).attr('data-image');

      var ok = confirm("Are you sure to Delete this Category?");

      if (ok) {

          $.ajax({

              url: site_url+urlLink+'/ajaxDelete',

              type:'POST',

              data:'id='+id+'&pimage='+pimage+'&table='+table,

              success: function(data){

                  location.reload();

              },

          });

      }

    });

</script>
<script>
   $(function() {
      $('.tbody').sortable({
        delay: 150,
        stop: function() {
          var div = [];
          $('.orderby').each(function() {
            var id = $(this).attr('data-order');
            if(id!='undefined'){
              div.push(id);
            }
          });
            var site_url = '<?php echo base_url(); ?>';
            $.ajax({
              url: site_url+urlLink+"/updateListItemOrder",
              type: "POST",
              dataType:"json",
              data: "div="+div+'&table=gallery_category',
              success: function(result){
                
              }
            });
        }
      });
   });
</script>