
@extends('layouts.theme')
@section('pageTitle', 'Vega Soft')
@section('page-content')



<style>

#t_tbl tr td{
  padding:1px;

}

</style>


<div id="form-div">
<input type="hidden" id="hidden_status" value="0">
<input type="hidden" id="row_id" value="0">


<div class="page-header form-header" >
  <h4 class="page-title text-white"> Time </h4>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      
        <li class="breadcrumb-item text-white  icon-md " aria-current="page"> </li>
      </ol>
    </nav>
    

 
</div>
<div class="card">
    <div class="card-body">


  
    <div class="row">


<div class="col-lg-6">

<div class="form-outline mb-1">
<label class="form-label" for="form3Example3">Name</label>
  <input type="text" id="name" class="form-control caps" />
 
</div>

<div class="row">

<div class="col-lg-5">
<label class="form-label" for="form3Example3">From Time</label>
  <input type="text" id="from_time" class="form-control time-picker " />
</div>



<div class="col-lg-5">
<label class="form-label" for="form3Example3">To Time</label>
  <input type="text" id="to_time" class="form-control time-picker" />
</div>


<div class="col-lg-5">
<label class="form-label" for="form3Example3">Multi Food</label>
  <select  id="multi" class="form-control form-select">


<option value="0" selected>No</option>
<option value="1">Yes</option>


  </select>
</div>

</div>
<div class="template-demo">
                        
                        <button id="save_btn" type="button" class="btn btn-success btn-icon-text save_btn btn-sm"  onclick="submit_save_form();">
                               <i class="icon-doc btn-icon-prepend"></i> Submit </button>
                           
                               <button id="edit_btn" type="button" class="btn btn-primary btn-icon-text save_btn btn-sm" onclick="submit_save_form();" >
                               <i class="icon-doc btn-icon-prepend" ></i> Edit </button>
   
   
                         <button type="reset" class="btn btn-danger btn-icon-text reset_btn btn-sm"  >
                               <i class="icon-reload btn-icon-prepend"></i> Reset </button>
                               <input type="hidden" id="row_id" value="0">
                             </div>
</div>
<div class="col-lg-6">


<div class="col-lg-12 col-sm-12 col-md-12 p-2" >



<table class="table table-responsive " id="t_tbl">

<thead>

<tr>

<th>Sl No</th>
<th>Name</th>
<th>From Time</th>
<th>To Time</th>

<th>&nbsp;</th>
<th>&nbsp;</th>





</tr>

</thead>

<tbody id="list_tbdy">


</tbody>


</table>
                                
                                </div>





</div>





    

        <div class="col-lg-6">




<!-- 2 column grid layout with text inputs for the first and last names -->


</div>



                     
                   
    </div>
</div>
</div>
</div>
<div id="table-div">
<div class="page-header form-header" >
  <h3 class="page-title text-white">  Time List <i class="fa fa-plus slide2" style="float:right;"></i></h3>
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
      
        <li class="breadcrumb-item text-white  icon-md " aria-current="page"> </li>
      </ol>
    </nav>
</div>

  

<div class="card">
  

<div class="col-lg-12 col-sm-12 col-md-12 p-2" >




                                        
                                        </div>


    
    
</div>
</div>



<script src="{{ asset('js/vega_scripts.js') }}"></script>

<script type="text/javascript">







function submit_save_form(){

    status=0;
    
   if($("#name").val()==""){
    alert("Name is mandatory");
    $("#name").focus().click();
    status=1;
    return;
   }
   if(status==0){
    Save_form(); 
   }
}


  function  show_form(){
    
    $("#form-div").show(500);
$("#table-div").hide();
}

 
function set_edit_form(row_id){
  show_form();
$('#hidden_status' ).val("1");
$('#row_id' ).val(row_id);
$("#edit_btn").show();
$("#save_btn").hide();
$.ajax({
          url: "/edit_time",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
              row_id:row_id
          },
          error: function(response) {
          },
          success:function(response){
          

            $('#name').val(response.name);
              $('#from_time').val(response.from_time);
              $('#to_time').val(response.to_time);
              $('#multi').val(response.multi);

          }
         });



}




  function Save_form() {

           $.ajax({
          url: "/op_time",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}",
             hidden_status:$.trim($('#hidden_status').val()),
             row_id:$.trim($('#row_id').val()),
              name:$.trim($('#name').val()),
              from_time:$.trim($('#from_time').val()),
              to_time:$.trim($('#to_time').val()),

              multi:$.trim($('#multi').val())
              
          },
          success:function(response){
          
            if (response) {
              alert(response.msg);
        
        $("#name").val('');
        $("#multi").val(0);
        $("#hidden_status").val(0);
      
      $("#row_id").val(0);
      
       
      $('#t_tbl').dataTable().fnDestroy();
                  load_list();
            }else{

            }
          },
          error: function(response) {
          }
         });
  }



  load_list();
function load_list(){
 

    $.ajax({
          url: "/get_time_list",
          type: "POST",
          data:{
             '_token': "{{ csrf_token() }}"
          },
          error: function(response) {
          },
          success:function(response){
          
          var data = response['times'];



html='';
i=1;
          $(data).each(function(key,val){

            html+='<tr>';
html+='<td>'+i+'</td>';
html+='<td>'+val['name']+'</td>';

html+='<td>'+val['from_time']+'</td>';
html+='<td>'+val['to_time']+'</td>';

html+='<td><button type="button" class="btn btn-sm btn-primary"   onclick="set_edit_form('+val['id']+')"  ><i class="fa fa-edit"></i></button></td>';

html+='<td><button type="button" class="btn btn-sm btn-danger"   onclick="set_del_form('+val['id']+')"  ><i class="fa fa-trash" aria-hidden="true"></i></button></td>';


html+='</tr>';


i++;

          });
      $("#list_tbdy").html(html);
         
          }
         });


         var table = $('#t_tbl').DataTable({
        dom: 'lBfrtip',
        "searching": false,
        'autoWidth':false,
        buttons: [
            
        ],
        "bLengthChange": true,
        "bSort" : true,
         "lengthMenu": [[ 20, 50,75,100, -1], [ 20, 50,75,100, "All"]],
         "pagingType": "full_numbers",
        columnDefs: [ {
            visible: false
        } ]
        
        
    });


}


function set_del_form(id){

$('#hidden_status' ).val("2");
$('#row_id' ).val(id);
Save_form();
location.reload(); 

}



</script>
@endsection