<?global $config;?>
<!--show all products view Abdul SAMAD  START-->
<!--main content start-->
          <section class="wrapper">
              <!-- page start-->
              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              <?=ucfirst(str_replace("_", "",$this->router->class));?>
                          </header>
                          <div class="panel-body">
                                <div class="adv-table">
                                    <table  class="display table table-bordered table-striped" id="productsTable">
                                    </table>
                                </div>
                          </div>                          
                      </section>
                               <div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                              <h4 class="modal-title">Confirm Delete?</h4>
                                          </div>
                                          <div class="modal-body">
                                              Are you sure you want to delete this <?=ucfirst(str_replace("_", "",$this->router->class));?>?
                                          </div>
                                          <div class="modal-footer">
                                              <button data-dismiss="modal" class="btn btn-default" type="button">No</button>
                                              <button id="yes" class="btn btn-danger" type="button">Yes</button>
                                          </div>
                                      </div>
                                  </div>
                              </div>
                              <div class="modal fade" id="success" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <h4 class="modal-title">Success!</h4>
                                          </div>
                                          <div class="modal-body">
                                              
                                          </div>
                                          <div class="modal-footer">
                                              <button onclick="location.reload()"  class="btn btn-success" type="button">Ok</button>
                                          </div>
                                      </div>
                                  </div>
                              </div>
                                <div class="modal fade" id="error" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <h4 class="modal-title">Error!</h4>
                                          </div>
                                          <div class="modal-body">
                                              
                                          </div>
                                          <div class="modal-footer">
                                              <button data-dismiss="modal" class="btn btn-danger" type="button">Ok</button>
                                          </div>
                                      </div>
                                  </div>         
                                </div>
                                <div class="modal fade" id="msg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <h4 class="modal-title">Message!</h4>
                                          </div>
                                          <div class="modal-body">
                                              
                                          </div>
                                          <div class="modal-footer">
                                              <button data-dismiss="modal" class="btn btn-danger" type="button">Ok</button>
                                          </div>
                                      </div>
                                  </div>         
                                </div>
              </div>
          </section>
      
      <!--main content end-->
       <script type="text/javascript" charset="utf-8">
          $(document).ready(function() {
              msg = "<?= $this->uri->segment(7)==''?'':urldecode($this->uri->segment(7))?>";
              if(msg!=''){
                $('#msg .modal-body').html(msg);
                $('#msg').modal('show');
              }
              newTable = $('#productsTable').dataTable( { 

                          "sDom": 'T<"clear">lfrtpi',
                          "aaData":[<?php echo $products_data; ?>],
                          "bDestroy":true,
                           "oLanguage": {
                                  "sZeroRecords": 'No Record Found!'
                              },
                          "bAutoWidth": false,
                          "aoColumns": <?php echo $products_column ?>,
                         
                          "oTableTools": {
                          "aButtons": [
                                      {
                                          "sExtends": "csv",
                                          "sFileName": "Leads Funnel.csv"
                                      },
                                      {
                                          "sExtends": "pdf",
                                          "sFileName": "Leads Funnel.pdf"
                                      },
                                      "print"
                                      ]
                          },
                          "bPaginate": true,
                          "bLengthChange": true
          });
          
                  $(".switch").click(function(){
                    var params = {};
                    var switch_obj = $(this);
                    params.model = $(this).attr("data-model");
                    params.pk = $(this).attr("data-pk");
                    params.val = $(this).attr("data-value");
                    params.field = $(this).attr("data-field");
                    
                    jQuery.ajax({
                    type:"POST",
                    url:"<?=$config['admin_base_url'].$this->router->class;?>/update",
                    data:{params:params},
                    beforeSend : function(){ 
                         
                     },
                    success : function(response){
                         if(response==1){
                          switch_obj.attr("data-value",(params.val==1?0:1));
                          $('#success').modal('show');
                          $('#success .modal-body').html('<?=ucfirst(str_replace("_", "",$this->router->class));?> updated successfully!');
                        }
                        else{
                          $('#error').modal('show');
                          $('#error .modal-body').html('Error in updating <?=ucfirst(str_replace("_", "",$this->router->class));?>!');   
                        }
                    }
                    })
                  });

                  $(".btn_delete_product").click(function(){
                    $('#delete').modal();
                    var params = {};
                    params.model = $(this).attr("data-model");
                    params.pk = $(this).attr("data-pk");
                    $("#yes").click(function(){
                      jQuery.ajax({
                            type:"POST",
                            url:"<?=$config['admin_base_url'].$this->router->class;?>/delete",
                            data:{params:params},
                            beforeSend : function(){ 
                             },
                            success : function(response){
                                if(response==1){
                                  $('#delete').modal('hide');
                                  $('#success').modal('show');
                                  $('#success .modal-body').html('<?=ucfirst(str_replace("_", "",$this->router->class));?> deleted successfully!');
                                }
                                else{
                                  $('#error').modal('show');
                                  $('#error .modal-body').html('Error in deleting <?=ucfirst(str_replace("_", "",$this->router->class));?>!');   
                                }
                            }
                    })
                    })
                    
                  });   
                            
          } );
      </script>
      <!--show all products view Abdul SAMAD  START-->
