|
1 | 1 | //= require active_admin/base |
2 | 2 | //= require formula_builder |
| 3 | +//= require new_parameter |
3 | 4 |
|
4 | | -document.addEventListener("DOMContentLoaded", function () { |
5 | | - function toggleFields() { |
6 | | - const val = document.querySelector('input[name="parameter_type"]:checked'); |
7 | | - const type = val ? val.value : ""; |
8 | | - |
9 | | - document.getElementById("fixed_fields").style.display = type === "Fixed" ? "block" : "none"; |
10 | | - document.getElementById("open_fields").style.display = type === "Open" ? "block" : "none"; |
11 | | - document.getElementById("select_fields").style.display = type === "Select" ? "block" : "none"; |
12 | | - } |
13 | | - |
14 | | - const radios = document.querySelectorAll('input[name="parameter_type"]'); |
15 | | - radios.forEach((radio) => { |
16 | | - radio.addEventListener("change", toggleFields); |
17 | | - }); |
18 | | - |
19 | | - toggleFields(); |
20 | | -}); |
21 | | - |
22 | | - |
23 | | -document.addEventListener("DOMContentLoaded", function () { |
24 | | - const addParamLinks = document.querySelectorAll(".store-and-navigate"); |
25 | | - |
26 | | - if (!addParamLinks.length) return; |
27 | | - |
28 | | - addParamLinks.forEach(link => { |
29 | | - link.addEventListener("click", function (event) { |
30 | | - event.preventDefault(); |
31 | | - |
32 | | - const nameField = document.querySelector("#item_name"); |
33 | | - const descriptionField = document.querySelector("#item_description"); |
34 | | - const categoryField = document.querySelector("#item_category_id"); |
35 | | - |
36 | | - const data = { |
37 | | - name: nameField?.value || "", |
38 | | - description: descriptionField?.value || "", |
39 | | - category_id: categoryField?.value || "" |
40 | | - }; |
41 | | - |
42 | | - const itemId = link.dataset.itemId || "new"; |
43 | | - |
44 | | - fetch(`/admin/items/${itemId}/save_meta_to_session`, { |
45 | | - method: "POST", |
46 | | - headers: { |
47 | | - "Content-Type": "application/json", |
48 | | - "X-CSRF-Token": document.querySelector('meta[name="csrf-token"]').content |
49 | | - }, |
50 | | - body: JSON.stringify(data) |
51 | | - }).then(response => { |
52 | | - if (response.ok) { |
53 | | - window.location.href = link.dataset.redirect; |
54 | | - } else { |
55 | | - alert("⚠️ Failed to save temporary data to session"); |
56 | | - } |
57 | | - }); |
58 | | - }); |
59 | | - }); |
60 | | -}); |
61 | 5 |
|
62 | 6 |
|
63 | 7 | // clear new item session |
@@ -108,53 +52,6 @@ document.addEventListener("DOMContentLoaded", function () { |
108 | 52 | }); |
109 | 53 |
|
110 | 54 |
|
111 | | -document.addEventListener("DOMContentLoaded", () => { |
112 | | - const wrapper = document.getElementById("select-options-wrapper"); |
113 | | - const addBtn = document.getElementById("add-option-button"); |
114 | | - |
115 | | - const createOptionRow = () => { |
116 | | - const row = document.createElement("div"); |
117 | | - row.className = "select-option-row"; |
118 | 55 |
|
119 | | - row.innerHTML = ` |
120 | | - <div class="select-field"> |
121 | | - <label>Description</label> |
122 | | - <input type="text" name="select_options[][description]" /> |
123 | | - </div> |
124 | | - <div class="select-field"> |
125 | | - <label>Value</label> |
126 | | - <input type="text" name="select_options[][value]" /> |
127 | | - </div> |
128 | | - <button type="button" class="delete-option-button button light">Delete</button> |
129 | | - `; |
130 | | - |
131 | | - row.querySelector(".delete-option-button").addEventListener("click", () => { |
132 | | - if (wrapper.querySelectorAll(".select-option-row").length > 2) { |
133 | | - row.remove(); |
134 | | - } else { |
135 | | - alert("At least 2 options are required."); |
136 | | - } |
137 | | - }); |
138 | | - |
139 | | - return row; |
140 | | - }; |
141 | | - |
142 | | - addBtn.addEventListener("click", () => { |
143 | | - const newRow = createOptionRow(); |
144 | | - wrapper.appendChild(newRow); |
145 | | - }); |
146 | | - |
147 | | - |
148 | | - wrapper.querySelectorAll(".select-option-row").forEach((row) => { |
149 | | - const delBtn = row.querySelector(".delete-option-button"); |
150 | | - delBtn.addEventListener("click", () => { |
151 | | - if (wrapper.querySelectorAll(".select-option-row").length > 2) { |
152 | | - row.remove(); |
153 | | - } else { |
154 | | - alert("At least 2 options are required."); |
155 | | - } |
156 | | - }); |
157 | | - }); |
158 | | -}); |
159 | 56 |
|
160 | 57 |
|
0 commit comments