{% extends '../template.html' %}
{% block style %}
<link href="{% nav public %}css/infomodal.css" rel="stylesheet">
{% endblock %}
{% block subcontent %}

<!-- iModal -->
<div id="infoModal" class="imodal">
  <!-- iModal content -->
	<div class="imodal-content">
		<span class="close">&times;</span>
		<h2 id="modal-title">Tambah Pemasok</h2>
		<br/>
		<form method="post">
			<input type="hidden" id="id_pemasok" name="id_pemasok" value=""/>
			<table cellpadding="5" cellspacing="0" border="0">
				<tr>
					<td style="max-width:150px">Nama Pemasok</td>
					<td><input class="form-control" type="text" name="nama" id="nama" value="" style="max-width:250px"></td>
				</tr>
				<tr>
					<td style="max-width:150px">Kontak</td>
					<td><input class="form-control" type="text" name="kontak" id="kontak" value="" style="max-width:250px"></td>
				</tr>
				<tr>
					<td style="max-width:150px">Alamat</td>
					<td><textarea class="form-control" type="text" name="alamat" id="alamat" value="" style="max-width:500px"></textarea></td>
				</tr>
			</table>
			<table cellpadding="5" cellspacing="0" border="0">
				<tr>
					<td><span class="txtError" style="color:red"></span></td>
				</tr>
			</table>
			<br/><input type="submit" class="btn btn-success btnSimpan" value="Simpan"/> <span class="btn btn-danger btnBatal">Batal</span>
		</form>
		<br/>
	</div>
</div>

<h2>Data Pemasok</h2>
<br/>
<div>
	<div class="card shadow mb-4">
		<div class="card-header py-3">
			<button class="btn btn-primary btn-icon-split btnTambah">
				<span class="icon text-white-50">
					<i class="fas fa-plus"></i>
				</span>
				<span class="text">Tambah</span>
			</button>
		</div>
		<div class="card-body">
			<div class="table-responsive">
				<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
					<thead>
						<tr>
							<th>Nama Pemasok</th>
							<th>Kontak</th>
							<th>Alamat</th>
							<th>Control</th>
						</tr>
					</thead>
					<tbody>
						{% for row in data %}
						<tr>
							<td>{{row.nama}}</td>
							<td>{{row.kontak}}</td>
							<td>{{row.alamat}}</td>
							<td>
								<button class="btn btn-default text-info btnUbah" id_pemasok="{{row.id}}"><i class="far fa-edit"></i></button>
								<a onclick="return confirm('Apakah Anda Yakin Ingin Menghapus Data Ini ?');" class="btn btn-default text-danger" href="{% nav apotek_obat_rempemasok %}/{{ row.id }}"><i class="far fa-trash-alt"></i></a>
							</td>
						</tr>
						{% endfor %}
					</tbody>
				</table>
			</div>
		</div>
	</div>
	</br></br>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript" src="{% nav public %}js/infomodal.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		menuSelected("mData","smDataPemasok");
		$('.btnTambah').on("click", function(){
			$("#id_pemasok").val("");
			$('#infoModal').show();
			$('#modal-title').html('Tambah Pemasok');
			$('#nama').val('');
			$('#kontak').val('');
			$('#alamat').val('');
		});
		$(".btnBatal").on("click",function() {
			$("#infoModal").hide();
		});
	});
	function refreshEvent() {
		$('.btnUbah').on("click", function(){
			$('.imodal-content').hide();
			$('#infoModal').show();
			$('#modal-title').html('Sedang memproses...');
			
			var id_pemasok = $(this).attr('id_pemasok');
			$("#id_pemasok").val(id_pemasok);
			$.ajax({
				type: "GET",
				url: "{% nav apotek_obat_getpemasok %}?id="+id_pemasok,
				dataType: "json",
				async: true,
				cache: false,
				timeout:50000,
				success: function(data){
					$('#nama').val(data.nama);
					$('#kontak').val(data.kontak);
					$('#alamat').val(data.alamat);
					$('#modal-title').html('Edit Pemasok');
					$('.imodal-content').show();
				}
			});
		});
	}
</script>
{% endblock %}