Skip to content

Commit 0efec63

Browse files
committed
IBX-9266: Added fetching siteaccess list
1 parent 15e67ba commit 0efec63

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

src/bundle/Resources/public/js/CKEditor/embed/image/embed-image-editing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class IbexaEmbedImageEditing extends Plugin {
7676
defineSchema() {
7777
const { schema } = this.editor.model;
7878
const customClassesConfig = getCustomClassesConfig();
79-
const allowedAttributes = ['contentId', 'size', 'ibexaLinkHref', 'ibexaLinkTitle', 'ibexaLinkTarget'];
79+
const allowedAttributes = ['contentId', 'size', 'ibexaLinkHref', 'ibexaLinkTitle', 'ibexaLinkTarget', 'siteaccess'];
8080

8181
if (customClassesConfig.link) {
8282
allowedAttributes.push('ibexaLinkClasses');

src/bundle/Resources/public/js/CKEditor/link/ui/link-form-view.js

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { createLabeledInputNumber } from '../../common/input-number/utils';
1313
import { addMultivalueSupport } from '../../common/multivalue-dropdown/utils';
1414
import { getCustomAttributesConfig, getCustomClassesConfig } from '../../custom-attributes/helpers/config-helper';
1515

16+
const { ibexa } = window;
17+
1618
class IbexaLinkFormView extends View {
1719
constructor(props) {
1820
super(props);
@@ -27,7 +29,7 @@ class IbexaLinkFormView extends View {
2729
this.urlInputView = this.createTextInput({ label: 'Link to' });
2830
this.titleView = this.createTextInput({ label: 'Title' });
2931
this.targetSwitcherView = this.createBoolean({ label: 'Open in tab' });
30-
this.siteAccessView = this.createDropdown({ label: 'Site access', choices: ['site', 'test'] }); //TODO
32+
this.siteAccessView = this.createDropdown({ label: 'Site access', choices: [] });
3133
this.attributeRenderMethods = {
3234
string: this.createTextInput,
3335
number: this.createNumberInput,
@@ -267,20 +269,17 @@ class IbexaLinkFormView extends View {
267269

268270
children.add(this.selectContentButtonView);
269271
children.add(this.urlInputView);
272+
children.add(this.siteAccessView);
270273
children.add(this.titleView);
271274
children.add(this.targetSwitcherView);
272-
children.add(this.siteAccessView);
273275

274276
return children;
275277
}
276278

277-
createDropdown(config, isCustomAttribute = false) {
279+
createDropdownItemsList(config) {
278280
const Translator = getTranslator();
279-
const labeledDropdown = new LabeledFieldView(this.locale, createLabeledDropdown);
280281
const itemsList = new Collection();
281282

282-
labeledDropdown.label = config.label;
283-
284283
if (!config.multiple && !config.required) {
285284
itemsList.add({
286285
type: 'button',
@@ -303,6 +302,15 @@ class IbexaLinkFormView extends View {
303302
});
304303
});
305304

305+
return itemsList;
306+
}
307+
308+
createDropdown(config, isCustomAttribute = false) {
309+
const labeledDropdown = new LabeledFieldView(this.locale, createLabeledDropdown);
310+
const itemsList = this.createDropdownItemsList(config);
311+
312+
labeledDropdown.label = config.label;
313+
306314
addListToDropdown(labeledDropdown.fieldView, itemsList);
307315

308316
if (config.multiple) {
@@ -467,12 +475,42 @@ class IbexaLinkFormView extends View {
467475
this.urlInputView.fieldView.set('value', url);
468476
this.urlInputView.fieldView.set('isEmpty', !url);
469477

478+
this.fetchSiteaccesses(items[0].id);
479+
470480
this.editor.focus();
471481
}
472482

473483
cancelHandler() {
474484
this.editor.focus();
475485
}
486+
487+
fetchSiteaccesses(locationId) {
488+
const request = new Request(`/api/ibexa/v2/site-access/load-non-admin-for-location/${locationId}`, {
489+
method: 'GET',
490+
headers: {
491+
Accept: 'application/json',
492+
},
493+
mode: 'same-origin',
494+
credentials: 'same-origin',
495+
});
496+
497+
fetch(request)
498+
.then(ibexa.helpers.request.getJsonFromResponse)
499+
.then((response) => {
500+
const itemsList = this.createDropdownItemsList({
501+
choices: response.SiteAccessesList.values.map((siteaccess) => siteaccess.name),
502+
});
503+
504+
this.siteAccessView.fieldView.once(
505+
'change:isOpen',
506+
() => {
507+
this.siteAccessView.fieldView.panelView.children.clear();
508+
addListToDropdown(this.siteAccessView.fieldView, itemsList);
509+
},
510+
{ priority: 'highest' },
511+
);
512+
});
513+
}
476514
}
477515

478516
export default IbexaLinkFormView;

src/bundle/Resources/public/scss/_balloon-form.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
border: calculateRem(1px) solid $ibexa-color-dark-200;
2929
border-radius: calculateRem(5px);
3030
width: 100%;
31-
max-width: calculateRem(288px);
3231

3332
.ibexa-ckeditor-dropdown-selected-items {
3433
display: flex;

0 commit comments

Comments
 (0)