@@ -13,6 +13,8 @@ import { createLabeledInputNumber } from '../../common/input-number/utils';
1313import { addMultivalueSupport } from '../../common/multivalue-dropdown/utils' ;
1414import { getCustomAttributesConfig , getCustomClassesConfig } from '../../custom-attributes/helpers/config-helper' ;
1515
16+ const { ibexa } = window ;
17+
1618class 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
478516export default IbexaLinkFormView ;
0 commit comments