feat: [bending] 기초자료 복사 버튼 추가 — 복사 후 수정 화면으로 이동

This commit is contained in:
김보곤
2026-03-21 11:49:07 +09:00
parent a8899d48e5
commit 036e346f2c
3 changed files with 28 additions and 0 deletions

View File

@@ -203,6 +203,21 @@ public function update(Request $request, int $id)
return redirect()->route('bending.base.show', $id)->with('success', '절곡품이 수정되었습니다.');
}
public function duplicate(int $id)
{
$response = $this->api()->post("/api/v1/bending-items/{$id}/duplicate");
if (! $response->successful()) {
return back()->withErrors(['api' => $response->json('message', '복사 실패')]);
}
$newId = $response->json('data.id');
$newCode = $response->json('data.code');
return redirect()->route('bending.base.edit', $newId)
->with('success', "복사 완료 — 새 코드: {$newCode}");
}
public function destroy(int $id)
{
$this->api()->delete("/api/v1/bending-items/{$id}");

View File

@@ -34,6 +34,7 @@
<a href="{{ route('bending.base.edit', $itemId) }}" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 text-sm">수정</a>
@endif
@if(!$isCreate)
<button type="button" onclick="duplicateItem()" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 text-sm">복사</button>
<form method="POST" action="{{ route('bending.base.destroy', $itemId) }}" onsubmit="return confirm('삭제하시겠습니까?')">
@csrf @method('DELETE')
<button type="submit" class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm">삭제</button>
@@ -482,6 +483,17 @@ function serializeBendingData() {
document.getElementById('bendingDataInput').value = JSON.stringify(data);
}
// 복사
function duplicateItem() {
if (!confirm('이 절곡품을 복사하시겠습니까?\n같은 분류의 다음 번호가 자동 채번됩니다.')) return;
const form = document.createElement('form');
form.method = 'POST';
form.action = '{{ !$isCreate ? route("bending.base.duplicate", $itemId) : "" }}';
form.innerHTML = '@csrf';
document.body.appendChild(form);
form.submit();
}
// 이미지 미리보기
function previewImage(input) {
const file = input.files[0];

View File

@@ -508,6 +508,7 @@
Route::get('/base/{id}', [\App\Http\Controllers\BendingBaseController::class, 'show'])->whereNumber('id')->name('base.show');
Route::get('/base/{id}/edit', [\App\Http\Controllers\BendingBaseController::class, 'edit'])->whereNumber('id')->name('base.edit');
Route::put('/base/{id}', [\App\Http\Controllers\BendingBaseController::class, 'update'])->whereNumber('id')->name('base.update');
Route::post('/base/{id}/duplicate', [\App\Http\Controllers\BendingBaseController::class, 'duplicate'])->whereNumber('id')->name('base.duplicate');
Route::delete('/base/{id}', [\App\Http\Controllers\BendingBaseController::class, 'destroy'])->whereNumber('id')->name('base.destroy');
// 기초관리 부품 검색 (모달용 AJAX)