Skip to content

Commit 23eff43

Browse files
GrabowskiMtomaszszopinski
authored andcommitted
fixed initial state
1 parent 90ae9e6 commit 23eff43

File tree

2 files changed

+37
-62
lines changed

2 files changed

+37
-62
lines changed

src/bundle/Resources/public/js/scripts/admin.fields.selector.js

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
const siteaccess = doc.querySelector('meta[name="SiteAccess"]').content;
44
const currentLanguageCode = ibexa.adminUiConfig.languages.priority[0];
55
const fieldsSelectorNodes = doc.querySelectorAll('.ibexa-fields-selector');
6-
const DROPDOWN_ROUTINE = {
7-
CHANGE_ANY_ITEM: 'changeAnyItem',
8-
CHANGE_ITEM: 'changeItem',
9-
};
106
const ANY_ITEM = {
117
id: '*',
128
name: Translator.trans(/*@Desc("Any")*/ 'ibexa.fields_selector.any_item', {}, 'forms'),
139
};
14-
let contentTypeGroups = [];
1510
const getNameForContentType = (names) => {
1611
const currentLanguageNames = names.value.find(({ _languageCode }) => _languageCode === currentLanguageCode);
1712

@@ -58,8 +53,8 @@
5853
return fetch(request)
5954
.then(ibexa.helpers.request.getJsonFromResponse)
6055
.then((response) => {
61-
contentTypeGroups = response.ContentTypeGroupList.ContentTypeGroup.map(({ id, identifier }) => ({
62-
id,
56+
const contentTypeGroups = response.ContentTypeGroupList.ContentTypeGroup.map(({ identifier }) => ({
57+
id: identifier,
6358
name: identifier,
6459
}));
6560

@@ -83,7 +78,7 @@
8378
}
8479

8580
if (params.selectedValues[0] !== '*') {
86-
bodyRequest.ViewInput.ContentTypeQuery.Query.ContentTypeGroupIdCriterion = params.selectedValues;
81+
bodyRequest.ViewInput.ContentTypeQuery.Query.ContentTypeGroupNameCriterion = params.selectedValues;
8782
}
8883

8984
const request = new Request('/api/ibexa/v2/content/types/view', {
@@ -136,29 +131,7 @@
136131
return value === ANY_ITEM.id;
137132
}
138133

139-
fitItems() {
140-
if (this.dropdownRoutine === DROPDOWN_ROUTINE.CHANGE_ITEM) {
141-
return;
142-
}
143-
144-
super.fitItems();
145-
}
146-
147-
onSelectSetSelectionInfoState(element, ...restArgs) {
148-
if (this.isAnyItem(element)) {
149-
return;
150-
}
151-
152-
super.onSelectSetSelectionInfoState(element, ...restArgs);
153-
}
154-
155-
onSelectSetCurrentSelectedValueState(element, selected, ...restArgs) {
156-
if (this.dropdownRoutine === DROPDOWN_ROUTINE.CHANGE_ITEM) {
157-
return;
158-
}
159-
160-
super.onSelectSetCurrentSelectedValueState(element, selected, ...restArgs);
161-
}
134+
onSelectSetCurrentSelectedValueState() {}
162135

163136
getNumberOfSelectedItems() {
164137
let numberOfSelectedItems = this.getSelectedItems().length;
@@ -176,8 +149,6 @@
176149
const anyItemCheckbox = anyItemElement.querySelector('.ibexa-input--checkbox');
177150
const numberOfSelectedItems = this.getNumberOfSelectedItems();
178151

179-
this.dropdownRoutine = DROPDOWN_ROUTINE.CHANGE_ANY_ITEM;
180-
181152
if (numberOfSelectedItems === 0) {
182153
anyItemLabel.textContent = ANY_ITEM.name;
183154
} else {
@@ -192,15 +163,17 @@
192163

193164
if (numberOfSelectedItems === 0) {
194165
anyItemCheckbox.indeterminate = false;
166+
this.onSelectSetSourceInputState(anyItemElement, false);
167+
this.onSelectSetItemsListState(anyItemElement, false);
195168
} else if (numberOfSelectedItems === this.getAllItems().length) {
196169
anyItemCheckbox.indeterminate = false;
197-
this.onSelect(anyItemElement, true);
170+
this.onSelectSetSourceInputState(anyItemElement, true);
171+
this.onSelectSetItemsListState(anyItemElement, true);
198172
} else {
199-
this.onSelect(anyItemElement, false);
173+
this.onSelectSetSourceInputState(anyItemElement, false);
174+
this.onSelectSetItemsListState(anyItemElement, false);
200175
anyItemCheckbox.indeterminate = true;
201176
}
202-
203-
this.dropdownRoutine = null;
204177
}
205178

206179
deselectOption(...args) {
@@ -209,37 +182,33 @@
209182
this.updateAnyItemState();
210183
}
211184

212-
onSelect(element, selected, ...restArgs) {
213-
super.onSelect(element, selected, ...restArgs);
214-
215-
if (this.isAnyItem(element)) {
216-
if (this.dropdownRoutine === DROPDOWN_ROUTINE.CHANGE_ANY_ITEM) {
217-
return;
218-
}
219-
220-
const allItems = this.getAllItems();
185+
toggleAllItems(selected) {
186+
const allItems = this.getAllItems();
221187

222-
this.dropdownRoutine = DROPDOWN_ROUTINE.CHANGE_ITEM;
188+
allItems.forEach((item) => {
189+
const itemValue = this.getValueFromElement(item);
190+
const sourceOption = this.sourceInput.querySelector(`[value=${itemValue}]`);
223191

224-
allItems.forEach((item) => {
225-
const value = this.getValueFromElement(item);
226-
const { selected: itemSelected } = this.sourceInput.querySelector(`[value=${value}]`);
227-
228-
if (selected && !itemSelected) {
229-
this.onSelect(item, true, ...restArgs);
230-
} else if (!selected && itemSelected) {
231-
this.onSelect(item, false, ...restArgs);
232-
}
233-
});
192+
if (sourceOption.selected !== selected) {
193+
this.onSelectSetSourceInputState(item, selected);
194+
this.onSelectSetItemsListState(item, selected);
195+
this.onSelectSetSelectionInfoState(item, selected);
196+
}
197+
});
198+
}
234199

235-
this.dropdownRoutine = null;
236-
this.fitItems();
237-
this.fireValueChangedEvent();
200+
onSelect(element, selected, ...restArgs) {
201+
if (this.isAnyItem(element)) {
202+
const anyItemCheckbox = element.querySelector('.ibexa-input--checkbox');
203+
const nextSelectState = anyItemCheckbox.indeterminate ? false : selected;
238204

239-
return;
205+
this.toggleAllItems(nextSelectState);
206+
} else {
207+
super.onSelect(element, selected, ...restArgs);
240208
}
241209

242210
this.updateAnyItemState();
211+
this.fireValueChangedEvent();
243212
}
244213
}
245214

src/bundle/Resources/public/js/scripts/core/multistep.selector.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@
6565

6666
this.dropdownInstance.init();
6767

68+
this.value = values;
6869
values.forEach((value) => {
6970
const element = this.dropdownInstance.itemsContainer.querySelector(`.ibexa-dropdown__item[data-value="${value}"]`);
7071

72+
if (!element) {
73+
return;
74+
}
75+
7176
this.dropdownInstance.onSelect(element, true);
7277
});
7378

@@ -106,11 +111,12 @@
106111
this.toggleLoader(true);
107112

108113
requestPromise().then((response) => {
114+
this.toggleLoader(false);
115+
109116
if (response.length === 0) {
110117
return;
111118
}
112119

113-
this.toggleLoader(false);
114120
this.createDropdown(response, values);
115121
});
116122
}

0 commit comments

Comments
 (0)