<!DOCTYPE html>
<html>

<head>
<!-- TABLES CSS CODE -->
<?php include"comman/code_css_datatable.php"; ?>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- Left side column. contains the logo and sidebar -->
  
  <?php include"sidebar.php"; ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <?=$page_title;?>
        <small>View/Search Items Category</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo $base_url; ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active"><?=$page_title;?></li>
      </ol>
    </section>

    <!-- Main content -->
    <?= form_open('#', array('class' => '', 'id' => 'table_form')); ?>
    <input type="hidden" id='base_url' value="<?=$base_url;?>">
    <section class="content">
      <div class="row">
        <!-- ********** ALERT MESSAGE START******* -->
        <?php include"comman/code_flashdata.php"; ?>
        <!-- ********** ALERT MESSAGE END******* -->
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header with-border">
              <h3 class="box-title"><?=$page_title;?></h3>
              <?php if($CI->permissions('items_category_add')) { ?>
              <div class="box-tools">
                <a class="btn btn-block btn-info" href="<?php echo $base_url; ?>category/add">
                <i class="fa fa-plus"></i> <?= $this->lang->line('add_category'); ?></a>
              </div>
              <?php } ?>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example2" class="table table-bordered table-striped" width="100%">
                <thead class="bg-primary ">
                <tr>
                  <th class="text-center">
                    <input type="checkbox" class="group_check checkbox" >
                  </th>
                  <th><?= $this->lang->line('category_code'); ?></th>
                  <th><?= $this->lang->line('category_name'); ?></th>
                  <th><?= $this->lang->line('description'); ?></th>
                  <th><?= $this->lang->line('status'); ?></th>
                  <th><?= $this->lang->line('action'); ?></th>
                </tr>
                </thead>
                <tbody>
				
                </tbody>

                <div class="modal fade " id="category_modal">
                  <?= form_open('#', array('class' => '', 'id' => 'category_form')); ?>
                  <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                      <div class="modal-header header-custom">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title text-center"><?= $this->lang->line('add_category'); ?></h4>
                      </div>
                      <div class="modal-body">
                          <div class="row">
                            <div class="col-md-12">
                              <div class="box-body">
                                <div class="form-group">
                                  <label for="category"><?= $this->lang->line('category_name'); ?>*</label>
                                  <span id="category_msg" class="text-danger text-right pull-right"></span>
                                  <input type="text" class="form-control" id="category" name="category" placeholder="" >
                                  <input type="hidden" class="form-control" id="category_id" name="category_id" placeholder="" >
                                </div>
                              </div>
                            </div>
                            
                            <div class="col-md-12">
                              <div class="box-body">
                                <div class="form-group">
                                  <label for="description"><?= $this->lang->line('description'); ?></label>
                                  <span id="description_msg" class="text-danger text-right pull-right"></span>
                                  <textarea type="text" class="form-control" id="description" name="description" placeholder="">-</textarea>
                                </div>
                              </div>
                            </div>

                          </div>
                        
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
                        <button type="button" id="edit_category" class="btn btn-primary">Update</button>
                      </div>
                    </div>
                    <!-- /.modal-content -->
                  </div>
                  <!-- /.modal-dialog -->
                <?= form_close();?>
                </div>
                <!-- /.modal -->
               
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
    <?= form_close();?>
  </div>
  <!-- /.content-wrapper -->
  <?php include"footer.php"; ?>
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- SOUND CODE -->
<?php include"comman/code_js_sound.php"; ?>
<!-- TABLES CODE -->
<?php include"comman/code_js_datatable.php"; ?>

<script type="text/javascript">
$(document).ready(function() {
    //datatables
   var table = $('#example2').DataTable({ 

      /* FOR EXPORT BUTTONS START*/
  dom:'<"row margin-bottom-12"<"col-sm-12"<"pull-left"l><"pull-right"fr><"pull-right margin-left-10 "B>>>tip',
 /* dom:'<"row"<"col-sm-12"<"pull-left"B><"pull-right">>> <"row margin-bottom-12"<"col-sm-12"<"pull-left"l><"pull-right"fr>>>tip',*/
      buttons: {
        buttons: [
            {
                className: 'btn bg-red color-palette btn-flat hidden delete_btn pull-left',
                text: 'Delete',
                action: function ( e, dt, node, config ) {
                    multi_delete();
                }
            },
            { extend: 'copy', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4]} },
            { extend: 'excel', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4]} },
            { extend: 'pdf', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4]} },
            { extend: 'print', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4]} },
            { extend: 'csv', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4]} },
            { extend: 'colvis', className: 'btn bg-teal color-palette btn-flat',text:'Columns' },  

            ]
        },
        /* FOR EXPORT BUTTONS END */

        "processing": true, //Feature control the processing indicator.
        "serverSide": true, //Feature control DataTables' server-side processing mode.
        "order": [], //Initial no order.
        "responsive": true,
        language: {
            processing: '<div class="text-primary bg-primary" style="position: relative;z-index:100;overflow: visible;">Processing...</div>'
        },
        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "<?php echo site_url('category/ajax_list')?>",
            "type": "POST",
            
            complete: function (data) {
             $('.column_checkbox').iCheck({
                checkboxClass: 'icheckbox_square-orange',
                /*uncheckedClass: 'bg-white',*/
                radioClass: 'iradio_square-orange',
                increaseArea: '10%' // optional
              });
             call_code();
              //$(".delete_btn").hide();
             },

        },

        //Set column definition initialisation properties.
        "columnDefs": [
        { 
            "targets": [ 0,5 ], //first column / numbering column
            "orderable": false, //set not orderable
        },
        {
            "targets" :[0],
            "className": "text-center",
        },
        
        ],
    });
    new $.fn.dataTable.FixedHeader( table );
});
</script>
<script src="<?php echo $theme_link; ?>js/category.js"></script>
<!-- Make sidebar menu hughlighter/selector -->
<script>$(".<?php echo basename(__FILE__,'.php');?>-active-li").addClass("active");</script>

<script>
  function editCat(ctl) {
    var cat_id = $(ctl).attr("data-ID");
    var cat_name = $(ctl).attr("data-catName");
    var cat_description = $(ctl).attr("data-description");
    //alert(cat_name);
    $('#category').val(cat_name);
    $('#category_id').val(cat_id);
    $('#description').val(cat_description);
    $('#category_modal').modal('show');
  }
</script>

<script>
    $('#edit_category').on('click',function(){
      var category_id    = $('#category_id').val();
      var cat_name    = $('#category').val();
      var cat_description = $('#description').val();

      if((cat_name.length=="") || (category_id.length=="")){
        toastr["warning"]("Please fill category name !");
      }else{
        $.ajax({
          url: '<?php echo $base_url; ?>category/edit_cat_details',
          type: 'POST',
          data: {category_id:category_id,cat_name:cat_name,cat_description:cat_description},
          dataType: 'JSON',
          success: function(data) {
             //console.log(data);
             if (data=="success") {
                swal({
                    title: "Successfully",
                    type: "success",
                    icon: "success",
                    text: "Category Details Updated !!" ,
                  })
                  .then((willUpdate) => {
                    if (willUpdate) {
                      window.location="<?php echo $base_url; ?>category/view";
                    }
                });
                //toastr["success"]("Category Details Updated!!");
             }else if (data=="exist"){
                //swal("Sorry","This Color Already Exist !!","error");
                toastr["error"]("Sorry! This Category Name already Exist.Try again!");
             }else if (data=="failed"){
                //swal("Sorry","Error occured !!","error");
                toastr["error"]("Sorry! Something Wrong.Try again!");
             }
          }
        });
      }

    });
</script>

</body>
</html>
