MIF_E31221259/resources/views/admin/datakriteria.blade.php

170 lines
8.5 KiB
PHP

@extends('admin.layouts.app')
@section('header')
<!-- Page Header -->
<div class="bg-header text-white p-4 rounded-lg shadow-md flex justify-between items-center">
<h1 class="text-2xl font-medium">Data Kriteria</h1>
<span class="text-sm">Good morning, <span class="font-bold">{{ Auth::user()->name }}</span></span>
</div>
@endsection
@section('content')
<div class="mt-6 bg-white p-6 rounded-lg shadow">
<!-- Title and Subheading -->
<div class="mb-4">
<h3 class="text-lg font-bold">Data Kriteria</h3>
<p class="text-sm text-gray-500">View the existing Kriteria</p>
</div>
<!-- Search & Add Bar -->
<div class="flex justify-between items-center mb-4">
<div class="flex space-x-2">
<button class="text-gray-600 flex items-center hover:text-gray-800">
<i class="bi bi-funnel mr-1"></i> Filter
</button>
<button class="flex items-center text-gray-600 hover:text-gray-800">
<i class="bi bi-arrow-clockwise mr-1"></i> Refresh
</button>
</div>
<button id="btnTambah" class="bg-teal-500 text-white px-4 py-2 rounded-lg flex items-center hover:bg-teal-600">
<i class="bi bi-plus-lg mr-2"></i> Add
</button>
</div>
<!-- Data Table -->
<div class="overflow-x-auto">
<table class="min-w-full table-auto divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">No</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">ID Kriteria</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Deskripsi Kriteria</th>
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Aksi</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@forelse ($kriterias as $i => $k)
<tr class="hover:bg-gray-50 transition">
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-700">{{ $i + 1 }}</td>
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-700">{{ $k->id }}</td>
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-700">{{ $k->nama }}</td>
<td class="px-4 py-3 whitespace-nowrap text-sm text-gray-700 flex space-x-2">
<button onclick="openEditModal('{{ $k->id }}','{{ addslashes($k->nama) }}')"
class="bg-yellow-500 hover:bg-yellow-600 text-white px-3 py-1 rounded-lg flex items-center">
<i class="bi bi-pencil-square mr-1"></i> Edit
</button>
<form action="{{ route('kriteria.destroy', $k->id) }}" method="POST"
onsubmit="return confirm('Yakin ingin menghapus {{ $k->nama }}?')">
@csrf @method('DELETE')
<button
class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 rounded-lg flex items-center">
<i class="bi bi-trash-fill mr-1"></i> Delete
</button>
</form>
</td>
</tr>
@empty
<tr>
<td colspan="4" class="px-4 py-6 text-center text-gray-500">No criteria found.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Modal Form -->
<div id="modalForm" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-md p-6">
<h2 id="modalTitle" class="text-xl font-semibold mb-4">Tambah Kriteria</h2>
<form id="formKriteria" action="" method="POST" class="space-y-4">
@csrf
<input type="hidden" name="_method" id="methodInput" value="POST">
<div>
<label for="idField" class="block text-sm font-medium">ID Kriteria (4 karakter)</label>
<input type="text" name="id" id="idField"
class="mt-1 block w-full border rounded px-3 py-2" maxlength="4" required>
@error('id')
<p class="text-red-600 text-sm mt-1">{{ $message }}</p>
@enderror
</div>
<div>
<label for="namaField" class="block text-sm font-medium">Deskripsi Kriteria</label>
<input type="text" name="nama" id="namaField"
class="mt-1 block w-full border rounded px-3 py-2" required>
@error('nama')
<p class="text-red-600 text-sm mt-1">{{ $message }}</p>
@enderror
</div>
<div class="flex justify-end space-x-3 pt-4">
<button type="button" id="btnBatal"
class="px-4 py-2 rounded-lg font-medium hover:underline">Batal</button>
<button type="submit" id="modalBtn"
class="bg-blue hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center">
<i id="modalIcon" class="bi bi-check-lg mr-1"></i>
<span id="modalText">Simpan</span>
</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@push('scripts')
<script>
document.addEventListener('DOMContentLoaded', () => {
const btnTambah = document.getElementById('btnTambah');
const modal = document.getElementById('modalForm');
const btnBatal = document.getElementById('btnBatal');
const form = document.getElementById('formKriteria');
const methodInput = document.getElementById('methodInput');
const idField = document.getElementById('idField');
const namaField = document.getElementById('namaField');
const modalTitle = document.getElementById('modalTitle');
const modalIcon = document.getElementById('modalIcon');
const modalText = document.getElementById('modalText');
const storeUrl = '{{ route('kriteria.store') }}';
const updateUrlTemplate = '{{ route('kriteria.update', ':id') }}';
function openModal(isEdit = false, data = {}) {
if (isEdit) {
modalTitle.textContent = 'Edit Kriteria';
form.action = updateUrlTemplate.replace(':id', data.id);
methodInput.value = 'PUT';
idField.readOnly = true;
idField.value = data.id;
namaField.value = data.nama;
modalIcon.className = 'bi bi-pencil-fill mr-1';
modalText.textContent = 'Update';
} else {
modalTitle.textContent = 'Tambah Kriteria';
form.action = storeUrl;
methodInput.value = 'POST';
idField.readOnly = false;
idField.value = '';
namaField.value = '';
modalIcon.className = 'bi bi-check-lg mr-1';
modalText.textContent = 'Simpan';
}
modal.classList.remove('hidden');
}
btnTambah.addEventListener('click', () => openModal());
btnBatal.addEventListener('click', () => modal.classList.add('hidden'));
window.openEditModal = (id, nama) => openModal(true, {
id,
nama
});
@if ($errors->any())
openModal({{ old('id') ? true : false }}, {
id: '{{ old('id') }}',
nama: '{{ old('nama') }}'
});
@endif
});
</script>
@endpush