diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index f440da289..1695a3b93 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -12,7 +12,7 @@ const TAINACAN_BLOCKS = [ 'carousel-items-list' => [ 'has_theme_script' => true ], 'carousel-terms-list' => [ 'has_theme_script' => true ], 'carousel-collections-list' => [ 'has_theme_script' => true ], - 'carousel-related-items' => [ 'has_theme_script' => true ], + 'carousel-related-items' => [], 'terms-list' => [ 'extra_editor_script_deps' => array('undescore') ], ]; diff --git a/src/views/gutenberg-blocks/tainacan-items/carousel-related-items/carousel-related-items-modal.js b/src/views/gutenberg-blocks/tainacan-items/carousel-related-items/carousel-related-items-modal.js index b2f8737db..3de390d86 100644 --- a/src/views/gutenberg-blocks/tainacan-items/carousel-related-items/carousel-related-items-modal.js +++ b/src/views/gutenberg-blocks/tainacan-items/carousel-related-items/carousel-related-items-modal.js @@ -12,20 +12,21 @@ export default class CarouselRelatedItemsModal extends React.Component { // Initialize state this.state = { collectionsPerPage: 24, - collectionId: undefined, - collectionName: '', + collectionId: undefined, + itemId: undefined, + collectionName: '', isLoadingCollections: false, modalCollections: [], totalModalCollections: 0, collectionOrderBy: 'date-desc', collectionPage: 1, temporaryCollectionId: '', + temporaryItemId: '', searchCollectionName: '', collections: [], collectionsRequestSource: undefined, searchURL: '', - itemsPerPage: 12, - loadStrategy: 'search' + itemsPerPage: 12 }; // Bind events @@ -34,20 +35,21 @@ export default class CarouselRelatedItemsModal extends React.Component { this.fetchCollections = this.fetchCollections.bind(this); this.fetchModalCollections = this.fetchModalCollections.bind(this); this.fetchCollection = this.fetchCollection.bind(this); - this.applySelectedSearchURL = this.applySelectedSearchURL.bind(this); - this.applySelectedItems = this.applySelectedItems.bind(this); + this.applyRelatedItem = this.applyRelatedItem.bind(this); } componentWillMount() { this.setState({ - collectionId: this.props.existingCollectionId + collectionId: this.props.existingCollectionId, + itemId: this.props.existingItemId }); if (this.props.existingCollectionId != null && this.props.existingCollectionId != undefined) { this.fetchCollection(this.props.existingCollectionId); this.setState({ - searchURL: this.props.existingSearchURL ? this.props.existingSearchURL : tainacan_blocks.admin_url + 'admin.php?page=tainacan_admin#/collections/'+ this.props.existingCollectionId + (this.props.loadStrategy == 'search' ? '/items/?iframemode=true&readmode=true&status=publish' : '/items/?iframemode=true&status=publish') }); + searchURL: tainacan_blocks.admin_url + 'admin.php?page=tainacan_admin#/collections/'+ this.props.existingCollectionId + '/items/?singleselectionmode=true&iframemode=true&status=publish' + }); } else { this.setState({ collectionPage: 1 }); this.fetchModalCollections(); @@ -114,7 +116,7 @@ export default class CarouselRelatedItemsModal extends React.Component { selectCollection(selectedCollectionId) { this.setState({ collectionId: selectedCollectionId, - searchURL: tainacan_blocks.admin_url + 'admin.php?page=tainacan_admin#/collections/' + selectedCollectionId + (this.props.loadStrategy == 'search' ? '/items/?iframemode=true&readmode=true&status=publish' : '/items/?iframemode=true&status=publish') + searchURL: tainacan_blocks.admin_url + 'admin.php?page=tainacan_admin#/collections/' + selectedCollectionId + '/items/?singleselectionmode=true&iframemode=true&status=publish' }); this.props.onSelectCollection(selectedCollectionId); @@ -164,20 +166,13 @@ export default class CarouselRelatedItemsModal extends React.Component { }); } - applySelectedSearchURL() { - let iframe = document.getElementById("itemsFrame"); - if (iframe) { - this.props.onApplySearchURL(iframe.contentWindow.location.href); - } - } - - applySelectedItems() { + applyRelatedItem() { let iframe = document.getElementById("itemsFrame"); if (iframe) { let params = new URLSearchParams(iframe.contentWindow.location.search); let selectedItems = params.getAll('selecteditems'); params.delete('selecteditems') - this.props.onApplySelectedItems(selectedItems); + this.props.onApplyRelatedItem(selectedItems[0]); } } @@ -205,10 +200,10 @@ export default class CarouselRelatedItemsModal extends React.Component { // Items modal this.cancelSelection() } shouldCloseOnClickOutside={ false } - contentLabel={ this.props.loadStrategy == 'selection' ? __('Select items that will be added on block', 'tainacan') : __('Configure your items search that will load items on block', 'tainacan')}> + contentLabel={ __('Select the item that has relations', 'tainacan') }>