|
1 |
| -import $ from 'jquery'; |
2 |
| -import './sylius/sylius-check-all'; |
| 1 | +import $ from 'jquery' |
| 2 | +import './sylius/sylius-check-all' |
3 | 3 | import 'fomantic-ui/dist/components/transition'
|
4 |
| -import loadSteps from './load-steps'; |
5 |
| -import selectResources from './select-resources'; |
| 4 | +import infiniteScrollTable from './infinite-scroll-table' |
| 5 | +import loadSteps from './load-steps' |
| 6 | +import selectResources from './select-resources' |
6 | 7 | import axios from 'axios'
|
7 | 8 |
|
| 9 | + |
8 | 10 | document.addEventListener('DOMContentLoaded', async () => {
|
9 |
| - $('[data-js-bulk-checkboxes]').checkAll(); |
| 11 | + $('[data-js-bulk-checkboxes]').checkAll() |
10 | 12 | $('.ui.dropdown.search:not(.sylius-autocomplete)').dropdown({
|
11 | 13 | action: 'hide',
|
12 | 14 | onChange: function (value, text, $selectedItem) {
|
13 | 15 | changeInputValue()
|
14 |
| - selectedInputValue().value = ''; |
| 16 | + selectedInputValue().value = '' |
15 | 17 | }
|
16 | 18 | })
|
17 | 19 |
|
| 20 | + infiniteScrollTable() |
18 | 21 | loadSteps()
|
19 | 22 | selectResources()
|
20 | 23 | changeInputValue(true)
|
21 |
| -}); |
| 24 | +}) |
22 | 25 |
|
23 |
| -const PREFIX_INPUT = 'criteria_asdoria_bulk_edit_search_attribute_value' |
24 |
| -const selectedInputValue = () => document.querySelector(`#${PREFIX_INPUT}_value`) |
25 |
| -const selectedInputLocale = () => document.querySelector(`#${PREFIX_INPUT}_localeCode`) |
26 |
| -const selectedInputAttribute = () => document.querySelector(`#${PREFIX_INPUT}_attribute`) |
27 |
| -const selectedInputContainer = () => selectedInputValue().closest("div.field") |
28 |
| -const initInputValue = (name, el) => { |
29 |
| - const queryString = window.location.search; |
30 |
| - const urlParams = new URLSearchParams(queryString); |
| 26 | +const PREFIX_INPUT = 'criteria_asdoria_bulk_edit_search_attribute_value' |
| 27 | +const selectedInputValue = () => document.querySelector(`#${ PREFIX_INPUT }_value`) |
| 28 | +const selectedInputLocale = () => document.querySelector(`#${ PREFIX_INPUT }_localeCode`) |
| 29 | +const selectedInputAttribute = () => document.querySelector(`#${ PREFIX_INPUT }_attribute`) |
| 30 | +const selectedInputContainer = () => selectedInputValue().closest('div.field') |
| 31 | +const initInputValue = (name, el) => { |
| 32 | + const queryString = window.location.search |
| 33 | + const urlParams = new URLSearchParams(queryString) |
31 | 34 | const initialValue = urlParams.get(name)
|
32 | 35 | if (el.type === 'checkbox') {
|
33 |
| - el.checked = true |
34 |
| - return; |
| 36 | + el.checked = true |
| 37 | + return |
35 | 38 | }
|
36 | 39 | el.value = urlParams.get(name)
|
37 | 40 | }
|
38 |
| -const changeInputValue = (init = false) => { |
| 41 | +const changeInputValue = (init = false) => { |
39 | 42 | const inputLocale = selectedInputLocale()
|
40 |
| - const inputAttr = selectedInputAttribute() |
| 43 | + const inputAttr = selectedInputAttribute() |
41 | 44 |
|
42 |
| - if (!inputLocale || !inputAttr) return; |
| 45 | + if (!inputLocale || !inputAttr) return |
43 | 46 |
|
44 |
| - const localeCode = inputLocale.value |
45 |
| - const {renderUrl} = inputAttr.dataset |
46 |
| - const attrValue = inputAttr.value |
47 |
| - if (!localeCode || !attrValue) return; |
| 47 | + const localeCode = inputLocale.value |
| 48 | + const { renderUrl } = inputAttr.dataset |
| 49 | + const attrValue = inputAttr.value |
| 50 | + if (!localeCode || !attrValue) return |
48 | 51 |
|
49 |
| - const url = `${renderUrl}?sylius_product_attribute_choice[]=${attrValue}&locale_code=${localeCode}`; |
| 52 | + const url = `${ renderUrl }?sylius_product_attribute_choice[]=${ attrValue }&locale_code=${ localeCode }` |
50 | 53 |
|
51 | 54 | axios
|
52 | 55 | .get(url)
|
53 |
| - .then(({data}) => { |
| 56 | + .then(({ data }) => { |
54 | 57 | const container = selectedInputContainer()
|
55 | 58 | container.classList.remove('error')
|
56 |
| - container.innerHTML = data; |
57 |
| - const input = selectedInputValue() |
| 59 | + container.innerHTML = data |
| 60 | + const input = selectedInputValue() |
58 | 61 | if (input) {
|
59 |
| - const {name} = input.dataset |
60 |
| - input.name = name |
| 62 | + const { name } = input.dataset |
| 63 | + input.name = name |
61 | 64 | if (init) initInputValue(name, input)
|
62 | 65 | }
|
63 |
| - }); |
| 66 | + }) |
64 | 67 | }
|
0 commit comments