|
55 | 55 | <div class="mb-3 row"> |
56 | 56 | <div class="col-3 col-form-label required">Product Image</div> |
57 | 57 | <div class="col"> |
58 | | - <input type="file" class="form-control" name="image"/> |
| 58 | + <button type="button" class="btn btn-primary" id="product-btn" |
| 59 | + data-bs-toggle="offcanvas" data-bs-target="#product" |
| 60 | + aria-controls="product" aria-expanded="false"> |
| 61 | + Upload File |
| 62 | + </button> |
| 63 | + |
| 64 | + <div id="product-wrapper"> |
| 65 | + </div> |
59 | 66 | <small class="form-hint"> |
60 | 67 | @error('image') |
61 | 68 | <div class="text-danger mt-2">{{ $message }}</div> |
|
196 | 203 | </form> |
197 | 204 | </div> |
198 | 205 |
|
| 206 | + @include('admin.components.media.popup', [ |
| 207 | + 'modalId' => 'product', |
| 208 | + 'inputType' => 'single', |
| 209 | + 'imageInputName' => 'image', |
| 210 | + ]) |
| 211 | + <template id="media-template"> |
| 212 | + @include('admin.components.media.popup', [ |
| 213 | + 'modalId' => 'product-variant-__INDEX__', |
| 214 | + 'inputType' => 'single', |
| 215 | + 'imageInputName' => 'combinations[__INDEX__][image]', |
| 216 | + ]) |
| 217 | + </template> |
| 218 | + <div id="product-media-container"></div> |
199 | 219 | @endsection |
200 | 220 |
|
201 | 221 |
|
@@ -325,10 +345,40 @@ function generateVariantCombinations() { |
325 | 345 | <input type="text" name="combinations[${index}][sku]" class="form-control" required> |
326 | 346 | </td> |
327 | 347 | <td> |
328 | | - <input type="file" name="combinations[${index}][image]" class="form-control"> |
| 348 | + <button type="button" class="btn btn-primary" id="product-variant-${index}-btn" |
| 349 | + data-bs-toggle="offcanvas" data-bs-target="#product-variant-${index}" |
| 350 | + aria-controls="product-variant-${index}" aria-expanded="false"> |
| 351 | + Upload File |
| 352 | + </button> |
| 353 | +
|
| 354 | + <div id="product-variant-${index}-wrapper"> |
| 355 | + </div> |
329 | 356 | </td> |
330 | 357 | `; |
331 | 358 |
|
| 359 | + const mediaContainer = document.getElementById('product-media-container'); |
| 360 | + const existingMedia = mediaContainer.querySelector(`#product-variant-${index}`); |
| 361 | + if (!existingMedia) { |
| 362 | + const template = document.getElementById('media-template').innerHTML; |
| 363 | + const rendered = template.replace(/__INDEX__/g, index); |
| 364 | + mediaContainer.insertAdjacentHTML('beforeend', rendered); |
| 365 | +
|
| 366 | + const newModal = document.getElementById(`product-variant-${index}`); |
| 367 | + if(newModal){ |
| 368 | + const offcanvas = new tabler.Offcanvas(newModal); |
| 369 | + newModal.addEventListener('shown.bs.offcanvas', function() { |
| 370 | + const container = newModal.querySelector(`#ajax-container-${newModal.id}`); |
| 371 | + const route = newModal.getAttribute('data-route'); |
| 372 | + if (container && route) { |
| 373 | + loadData(`${route}`, container); |
| 374 | + } else { |
| 375 | + console.error('Missing required elements or data for modal:', newModal.id, { container, route, folderId }); |
| 376 | + } |
| 377 | + }); |
| 378 | + } |
| 379 | + } |
| 380 | +
|
| 381 | +
|
332 | 382 | wrapper.appendChild(row) |
333 | 383 | }); |
334 | 384 | } |
|
0 commit comments