Skip to content

Commit 9d52ff8

Browse files
committed
5446 apply duplicate modal to confirm audit button
1 parent 48842ae commit 9d52ff8

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

app/javascript/utils/audit_duplicates.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import $ from 'jquery';
22

33
$(() => {
4-
$("button[name='save_progress']").on('click', function (e) {
5-
4+
function checkForDuplicates(e, buttonName) {
65
const form = $(this).closest('form');
76
const itemCounts = {}; // Will look like: { "2": 3, "5": 1, "12": 2 }
87
const itemNames = {}; // Will look like: { "2": "Item A", "5": "Item B", "12": "Item C" }
@@ -44,15 +43,23 @@ $(() => {
4443

4544
if (duplicates.length > 0) {
4645
// Show modal with duplicate items
47-
showDuplicateModal(duplicates, itemQuantities, form);
46+
showDuplicateModal(duplicates, itemQuantities, form, buttonName);
4847
e.preventDefault();
4948
} else {
50-
// No duplicates, let the form submit normally with the save_progress button
49+
// No duplicates, let the form submit normally
5150
// Don't prevent default - let the button's natural submit behavior work
5251
}
52+
}
53+
54+
$("button[name='save_progress']").on('click', function (e) {
55+
checkForDuplicates.call(this, e, 'save_progress');
56+
});
57+
58+
$("button[name='confirm_audit']").on('click', function (e) {
59+
checkForDuplicates.call(this, e, 'confirm_audit');
5360
});
5461

55-
function showDuplicateModal(duplicateItems, duplicateQuantities, form) {
62+
function showDuplicateModal(duplicateItems, duplicateQuantities, form, buttonName) {
5663
const itemRows = duplicateItems.map(item => {
5764
const entries = duplicateQuantities[item.id] || [];
5865
const total = entries.reduce((sum, entry) => sum + entry.qty, 0);
@@ -114,11 +121,11 @@ $(() => {
114121
// Merge duplicate items before submitting
115122
mergeDuplicateItems(form);
116123

117-
// Create a hidden button with save_progress name to ensure proper parameter submission
118-
const hiddenBtn = $('<button type="submit" name="save_progress" style="display:none;">Save Progress</button>');
124+
// Create a hidden button with the appropriate name to ensure proper parameter submission
125+
const hiddenBtn = $(`<button type="submit" name="${buttonName}" style="display:none;"></button>`);
119126
form.append(hiddenBtn);
120127

121-
// Click the hidden button to submit with save_progress parameter
128+
// Click the hidden button to submit with the correct parameter
122129
hiddenBtn.click();
123130
});
124131
}

app/views/audits/edit.html.erb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,3 @@
6060
</div>
6161
</div>
6262
</div>
63-
64-

app/views/audits/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
</div>
4141
</section>
4242

43-
<%= render partial: "audits/form" %>
43+
<%= render partial: "audits/form" %>

0 commit comments

Comments
 (0)