
<?php $__env->startSection('title','Testimoni'); ?>
<?php $__env->startSection('main'); ?>

<div class="main">
	<h2><strong>Testimoni</strong></h2>
	<hr>
	<button class="btn black mt-2" data-bs-toggle="modal" data-bs-target="#adddata">Tambah Data</button>
	<br><br>
	<div class="data-content">
		<div class=table-control>
			<table class="table table-home table-striped table-bordered" id="testimoni-table">
				<thead>
					<tr>
						<th>Foto</th>
						<th>Pesan</th>
						<th>Nama</th>
						<th>Title</th>
						<th>Aksi</th>
					</tr>
				</thead>
				<tbody>
					
				</tbody>
			</table>
		</div>
	</div>
</div>
<div class="modal fade" id="adddata" tabindex="-1" aria-labelledby="adddataLabel" aria-hidden="true">
    <div class="modal-dialog">
		<div class="modal-content">
   			<div class="modal-header">
   				<h1 class="modal-title fs-5" id="adddataLabel">Tambah Data</h1>
   				<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
   			</div>
	   		<div class="modal-body">
	   			<form action="<?php echo e(route('testimoniadd')); ?>" method="post" enctype="multipart/form-data">
	   			<?php echo csrf_field(); ?>
	   				<img name="imagechange" id="imgadd" class="w-25 mt-2">
	   				<div class="form-group">
	   					<label><strong>Foto</strong></label>
	   					<input type="file" id="foto" name="foto" required class="form-control">
	   				</div>
	   				<div class="form-group">
	   					<label><strong>Pesan</strong></label>
	   					<textarea rows="3" name="pesan" class="form-control" required></textarea>
	   				</div>
	   				<div class="form-group">
	   					<label><strong>Nama</strong></label>
	   					<input type="text" name="nama" class="form-control" required>
	   				</div>
	   				<div class="form-group">
	   					<label><strong>Gelar</strong></label>
	   					<input type="text" name="title" class="form-control" required>
	   				</div>
      			<div class="text-center mt-3"></div>
  				<button type="submit" class="btn black">Simpan</button>
  				<div class="btn oren" data-bs-dismiss="modal" aria-label="Close" >Close</div>
	   			</form>
  			</div>
  		</div>	
	</div>
</div>

<div class="modal fade" id="updateData" tabindex="-1" aria-labelledby="updateDataLabel" aria-hidden="true">
    <div class="modal-dialog">
		<div class="modal-content">
   			<div class="modal-header">
   				<h1 class="modal-title fs-5" id="updateDataLabel">Update Data</h1>
   				<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
   			</div>
	   		<div class="modal-body">
	   			<form id="updateDataTest" action="<?php echo e(route('testimoniupdate')); ?>" method="post" enctype="multipart/form-data">
	   			<?php echo csrf_field(); ?>
	   				<input type="hidden" name="id" >
	   				<img name="imagechange" id="imgchange" class="w-25 mt-2">
	   				<div class="form-group">
	   					<label><strong>Foto</strong></label>
	   					<input type="file" id="gambar" name="gambar" class="form-control">
	   				</div>
	   				<div class="form-group">
	   					<label><strong>Pesan</strong></label>
	   					<textarea rows="3" name="pesanupdate" class="form-control" required></textarea>
	   				</div>
	   				<div class="form-group">
	   					<label><strong>Nama</strong></label>
	   					<input type="text" name="namaupdate" class="form-control" required>
	   				</div>
	   				<div class="form-group">
	   					<label><strong>Gelar</strong></label>
	   					<input type="text" name="titleupdate" class="form-control" required>
	   				</div>
      			<div class="text-center mt-3"></div>
  				<button type="submit" class="btn black">Simpan</button>
  				<div class="btn oren" data-bs-dismiss="modal" aria-label="Close" >Close</div>
	   			</form>
  			</div>
  		</div>	
	</div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script type="text/javascript">
	let icon = document.getElementById('gambar')
	let imagefet = document.getElementById('imgchange')

	let ft = document.getElementById('foto')
	let imageadd = document.getElementById('imgadd')

	icon.addEventListener('change', function () {
        gambar(this);
    })
    ft.addEventListener('change', function () {
        image(this);
    })
    function gambar(a) {
        if (a.files && a.files[0]) {     
            var reader = new FileReader();    
            reader.onload = function (e) {
                imagefet.src=e.target.result;
            }    
            reader.readAsDataURL(a.files[0]);
        }
    }
    function image(t) {
        if (t.files && t.files[0]) {     
            var baca = new FileReader();    
            baca.onload = function (e) {
                imageadd.src=e.target.result;
            }    
            baca.readAsDataURL(t.files[0]);
        }
    }

    $(function(){
	    $('#testimoni-table').DataTable({
	      	processing : true,
	      	serverSide : true,
	      	responsive : true,
	      	ajax: "<?php echo e(route('testimonijson')); ?>",
	      	columns: [
		        {data: 'image', name: 'image'},
		        {data: 'pesan', name: 'pesan'},
		        {data: 'nama', name: 'nama'},
		        {data: 'title', name: 'title'},
		        {data: 'aksi', name: 'aksi'}
	        ]
	    });
  	});

  	$(document).on('click', '.update', function(){
    let id = $(this).attr('id');
    var url = '<?php echo e(route("testimoniedit")); ?>';
    	$.get(url, {id:id}, function(data){
      		var updateList = $('#updateData');
			$(updateList).find('form#updateDataTest').find('input[name="id"]').val(data.data.id);
			$(updateList).find('form#updateDataTest').find('textarea[name="pesanupdate"]').val(data.data.pesan);
			$(updateList).find('form#updateDataTest').find('input[name="namaupdate"]').val(data.data.nama);
			$(updateList).find('form#updateDataTest').find('input[name="titleupdate"]').val(data.data.title);
      		$('#updateData').modal('show');
    	//alert(id);
    	}, 'json');
  	});

  	$(document).on('click', '.hapus', function(){
      	let id = $(this).attr('id');
      	$.ajax({
        	url : "<?php echo e(route('testimonidelete')); ?>",
        	type : 'post',
        	data : {
          		id : id,
          		'_token' : "<?php echo e(csrf_token()); ?>"
        	},
        	success: function(params){
	          	alert(params.text);
	          	window.location = "<?php echo e(route('testimoni')); ?>"
	        },
        	error: function(xhr){
          		alert(xhr)
        	}
      	});
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('template.template', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\rezabackend\resources\views/admin/testimoni.blade.php ENDPATH**/ ?>