text: $(document).ready(function() {
  
  	var table_name = "location_type";
  	
  
  /*---------insert data into timeslot_master start-----------------*/
      $(document).on("submit","#master_form",function(e){
  			e.preventDefault();
  
  			var name = $('#location_type').val();
  			var id = $('#save_update').val();
  			
  			$.ajax({
                  type : "POST",
  				url  : baseurl+"Master/save_master",
                  dataType : "JSON",
  		        async : false,
                  data : {id:id,
  						name:name,
  						table_name:table_name,
  						},
                  success: function(data){
  					console.log(data);
  					if(data==true){
  						if(id!=""){
  							successTost("Data Update Successfully");							
  						}else{
  						successTost("Data Save Successfully");							
  						}
  						form_clear();		//call function clear role_master form
  						show_master();	//call function show role_master table
  						$('.closehideshow').trigger('click');
  					}
  					else{
  						errorTost("Data Cannot Save");
  					}
                  }
              });
  	});
  /*---------insert data into timeslot_master end-----------------*/
  
  
  /*---------get data into timeslot_master start-----------------*/
  			
  
  	show_master();	//call function show data table
  		
  	
  		//	function show data table
  		function show_master(){
  		    $.ajax({
  		        type  : 'POST',
  				url  : baseurl+"Master/get_master",
  		        async : false,
                  data : {table_name:table_name,
  						},
  		        dataType : 'json',
  		        success : function(data){
  				var html = '';
  					html += '<table id="myTable" class="table table-striped">'+
                              '<thead>'+
                              '<tr>'+
                              '<th>#     	</th>'+
                              '<th>Time Slot</th>'+
                              '<th>Action</th>'+
                              '</tr>'+
                              '</thead>'+
                              '<tbody>';
  
  				for(i=0; i<data.length; i++){
  					var sr = i+1;
  	                html += '<tr>'+
  	                  		'<td>'+sr+'</td>'+
  	                        '<td id="name_'+data[i].id+'">'+data[i].name+'</td>'+
  							'<td><button  class="edit_data btn btn-sm btn-primary" id="'+data[i].id+'"  ><i class="fa fa-edit"></i></button>'+
  							'</tr>';
  		            }
  					
  					html += '</tbody></table>';
  		            $('#show_master').html(html);
  	    $('#myTable').DataTable({});
  		        }
  
  		    });
  		}
  		
  /*---------get data into timeslot_master end-----------------*/
  
    	$(document).on('click','.closehideshow',function(){
  			form_clear();
  		    });
  
  	function form_clear(){
  				$('#location_type').val('');
  				$('#save_update').val('');
  				
      }
  	
  	
  /*---------get  timeslot_master  start-----------------*/
  
    	$(document).on('click','.edit_data',function(){
  		var id1 = $(this).attr('id');		
  		var st = $(this).val();		
  		var name = $('#name_'+id1).html();
  //		var st = $('#status_'+id1).html();
  
  			$('#location_type').val(name);
  
  			$('#save_update').val(id1);
  			$('.btnhideshow').trigger('click');
  
          });
  	
  /*---------get  timeslot_master  end-----------------*/
  /*---------delete  timeslot_master  start-----------------*/
  
    	$(document).on('click','.delete_data',function(){
  		var id1 = $("#save_update").val();
  		if(id1 != ""){
      swal({
              title: "Are you sure to delete ?",
              text: "You will not be able to recover this Data !!",
              type: "warning",
              showCancelButton: true,
              confirmButtonColor: "#DD6B55",
              confirmButtonText: "Yes, delete it !!",
              closeOnConfirm: false
          },
          function(){	
  
  				$.ajax({
                  type : "POST",
  				url  : baseurl+"Master/delete_master",
                  dataType : "JSON",
                  data : { id:id1,
  						 table_name:table_name,	},
                  success: function(data){
  				if(data == true){
  			            swal("Deleted !!", "Hey, your Data has been deleted !!", "success");
  						$('.closehideshow').trigger('click');
  						show_master();	//call function show all product					
  					
  					}
  					else{
  					errorTost("Data Delete Failed");
  					}
  	
                  }
              });
              return false;
  			
          });
  			
  		}
  
         });
  	
  /*---------delete  timeslot_master  end-----------------*/
  
  	
  });