@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="index.html"><i class="icon-home2 position-left"></i> Master</a></li>
			<li class="active">Komposisi Warna</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Komposisi Warna</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<a href="{{ url('komposisi/tambah') }}" class="btn btn-primary">Tambah</a>
	    </div>
	    <div class="table-responsive">
	    <table class="table datatable-basic table-striped table_barang2">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Nama Warna</th>
					<th>Inisial</th>
					<th>Jumlah</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
	    </table>
	    </div>
	</div>
</div>

<script type="text/javascript">
	var tb;

	$(document).ready(function(){
		tb = $(".table_barang2").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('komposisi/get_data') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, full, meta){
			  		return meta.row+1;
			  	}},
	            {data: 'nama', name: 'nama'},
	            {data: 'inisial', name: 'inisial'},
	            {data: 'jumlah', name: 'jumlah'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
		});
	})

	function hapus(id){
		swal({
			title: 'Anda yakin akan menghapus item ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
			if(result.value){
			 	$.ajax({
					url: "{{ url('komposisi/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						tb.ajax.reload();
					}
				})
			}
		})
	}
</script>
@endsection