partial update create mutations workflow

This commit is contained in:
2025-06-12 15:10:51 +07:00
parent a5e1348436
commit 1a01efb1b5
33 changed files with 560 additions and 12994 deletions

View File

@@ -1,5 +1,6 @@
$(document).ready(function () {
let productIndex = 1;
let originalProductOptions = ""; // Store original product options
// Initialize Select2
$(".select2").select2({
@@ -7,6 +8,12 @@ $(document).ready(function () {
allowClear: true,
});
// Store original product options on page load
const firstSelect = $(".product-select").first();
if (firstSelect.length > 0) {
originalProductOptions = firstSelect.html();
}
// Prevent same dealer selection
$("#from_dealer_id, #to_dealer_id").on("change", function () {
const fromDealerId = $("#from_dealer_id").val();
@@ -26,12 +33,12 @@ $(document).ready(function () {
const newRow = createProductRow(productIndex);
$("#products-tbody").append(newRow);
// Initialize Select2 for new row
// Initialize Select2 for new row after it's added to DOM
const newSelect = $(
`#products-tbody tr[data-index="${productIndex}"] .product-select`
);
newSelect.select2({
placeholder: "Pilih Produk...",
placeholder: "Pilih...",
allowClear: true,
});
@@ -100,18 +107,14 @@ $(document).ready(function () {
});
function createProductRow(index) {
// Get product options from the existing select
const existingSelect = $(".product-select").first();
const productOptions = existingSelect.html();
return `
<tr class="product-row" data-index="${index}">
<td>
<select name="products[${index}][product_id]" class="form-control select2 product-select" required>
${productOptions}
<select name="products[${index}][product_id]" class="form-control product-select" required>
${originalProductOptions}
</select>
</td>
<td>
<td class="text-center">
<span class="available-stock text-muted">-</span>
</td>
<td>
@@ -123,12 +126,7 @@ $(document).ready(function () {
placeholder="0"
required>
</td>
<td>
<input type="text"
name="products[${index}][notes]"
class="form-control"
placeholder="Catatan produk (opsional)">
</td>
<td>
<button type="button" class="btn btn-danger btn-sm remove-product">
<i class="la la-trash"></i>
@@ -152,9 +150,6 @@ $(document).ready(function () {
$(this)
.find('input[name*="quantity_requested"]')
.attr("name", `products[${index}][quantity_requested]`);
$(this)
.find('input[name*="notes"]')
.attr("name", `products[${index}][notes]`);
});
productIndex = $(".product-row").length;
}