Skip to content

Commit

Permalink
Merge pull request #125 from ezsystems/ezee-2660-fix-cotf-with-form-b…
Browse files Browse the repository at this point in the history
…uilder

EZEE-2660: 500 error occurs when publishing form in form on the fly
  • Loading branch information
Łukasz Serwatka authored Jan 21, 2019
2 parents b951284 + 4dd7f64 commit 7848245
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tabWidth": 4,
"semi": true,
"bracketSpacing": true,
"jsxBracketsSameLine": true,
"jsxBracketSameLine": true,
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "es5"
Expand Down
2 changes: 1 addition & 1 deletion Resources/public/js/MultiFileUpload.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/MultiFileUpload.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/SubItems.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/SubItems.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/UniversalDiscovery.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/public/js/UniversalDiscovery.module.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "webpack --config webpack.prod.js",
"builddev": "webpack --config webpack.dev.js",
"watch": "webpack --watch --config webpack.dev.js",
"watchprod": "webpack --watch --config webpack.prod.js"
"watchprod": "webpack --watch --config webpack.prod.js",
"fix-cs": "eslint --fix src/ && prettier --write src/**/*.js"
},
"devDependencies": {
"babel-core": "^6.26.3",
Expand Down
3 changes: 1 addition & 2 deletions src/modules/common/popup/popup.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class Popup extends Component {
className="close c-popup__btn--close"
data-dismiss="modal"
aria-label={closeBtnLabel}
onClick={this.props.onClose}
>
onClick={this.props.onClose}>
<Icon name="discard" extraClasses="ez-icon--medium" />
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ UploadListComponent.propTypes = {
language: PropTypes.string.isRequired,
}).isRequired,
uploadedItemsListTitle: PropTypes.string.isRequired,
contentCreatePermissionsConfig: PropTypes.object.isRequired,
};

UploadListComponent.defaultProps = {
Expand Down
8 changes: 3 additions & 5 deletions src/modules/sub-items/sub.items.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export default class SubItemsModule extends Component {
*/
deselectItems(locationsIds) {
const { selectedItems } = this.state;
const newSelection = new Map([...selectedItems].filter(([locationId, item]) => !locationsIds.has(locationId)));
const newSelection = new Map([...selectedItems].filter(([locationId]) => !locationsIds.has(locationId)));

this.setState(() => ({ selectedItems: newSelection }));
}
Expand Down Expand Up @@ -634,8 +634,7 @@ export default class SubItemsModule extends Component {
onClick={this.closeBulkDeletePopup}
type="button"
className="btn btn-secondary btn--no m-sub-items__confirmation-modal-cancel-btn"
data-dismiss="modal"
>
data-dismiss="modal">
{cancelLabel}
</button>
<button onClick={this.onBulkDeletePopupConfirm} type="button" className="btn btn-danger font-weight-bold btn--trigger">
Expand Down Expand Up @@ -665,8 +664,7 @@ export default class SubItemsModule extends Component {
isLoading={false}
size="medium"
footerChildren={this.renderConfirmationPopupFooter()}
noHeader={true}
>
noHeader={true}>
<div className="m-sub-items__confirmation-modal-body">{confirmationMessage}</div>
</Popup>,
this.bulkDeleteModalContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ export default class ContentCreatorComponent extends Component {

this.handleIframeLoad = this.handleIframeLoad.bind(this);
this.handlePublish = this.handlePublish.bind(this);
this.enablePublishBtn = this.enablePublishBtn.bind(this);
this.disablePublishBtn = this.disablePublishBtn.bind(this);
this.renderPublishBtn = this.renderPublishBtn.bind(this);

this._refIframe = null;

this.state = {
iframeLoading: true,
publishBtnDisabled: false,
};
}

handlePublish() {
this.iframe.contentWindow.onbeforeunload = () => {};
this.iframe.contentWindow.document.body.querySelector('#ezrepoforms_content_edit_publish').click();
this._refIframe.contentWindow.onbeforeunload = () => {};
this._refIframe.contentWindow.document.body.querySelector('#ezrepoforms_content_edit_publish').click();
}

handleIframeLoad() {
const locationId = this.iframe.contentWindow.document.querySelector('meta[name="LocationID"]');
const iframeWindow = this._refIframe.contentWindow;
const iframeDoc = iframeWindow.document;
const locationId = iframeDoc.querySelector('meta[name="LocationID"]');
const iframeUrl = this.generateIframeUrl();

if (this.iframe.contentWindow.location.pathname !== iframeUrl && !locationId) {
this.iframe.setAttribute('src', iframeUrl);
if (iframeWindow.location.pathname !== iframeUrl && !locationId) {
this._refIframe.setAttribute('src', iframeUrl);

return;
}
Expand All @@ -37,13 +45,24 @@ export default class ContentCreatorComponent extends Component {
} else {
this.setState((state) => Object.assign({}, state, { iframeLoading: false }));

this.iframe.contentWindow.onbeforeunload = () => {
iframeWindow.onbeforeunload = () => {
return '';
};
this.iframe.contentWindow.onunload = () => {
iframeWindow.onunload = () => {
this.setState((state) => Object.assign({}, state, { iframeLoading: true }));
};
}

iframeDoc.body.addEventListener('fbFormBuilderLoaded', this.disablePublishBtn, false);
iframeDoc.body.addEventListener('fbFormBuilderUnloaded', this.enablePublishBtn, false);
}

enablePublishBtn() {
this.setState(() => ({ publishBtnDisabled: false }));
}

disablePublishBtn() {
this.setState(() => ({ publishBtnDisabled: true }));
}

loadLocationInfo(locationId) {
Expand Down Expand Up @@ -84,6 +103,21 @@ export default class ContentCreatorComponent extends Component {
);
}

renderPublishBtn() {
const publishLabel = Translator.trans(/*@Desc("Publish")*/ 'content_on_the_fly.publish.label', {}, 'universal_discovery_widget');
const attrs = {
className: 'm-ud__action--publish',
onClick: this.handlePublish,
type: 'button',
};

if (this.state.publishBtnDisabled) {
attrs.disabled = true;
}

return <button {...attrs}>{publishLabel}</button>;
}

render() {
const { selectedContentType, selectedLanguage, maxHeight, onCancel } = this.props;
const title = Translator.trans(
Expand All @@ -95,33 +129,30 @@ export default class ContentCreatorComponent extends Component {
'universal_discovery_widget'
);
const cancelLabel = Translator.trans(/*@Desc("Cancel")*/ 'cancel.label', {}, 'universal_discovery_widget');
const publishLabel = Translator.trans(/*@Desc("Publish")*/ 'content_on_the_fly.publish.label', {}, 'universal_discovery_widget');
const iframeUrl = this.generateIframeUrl();
const contentClass = this.state.iframeLoading ? 'm-ud__content is-loading' : 'm-ud__content';

return (
<div className="m-ud__wrapper">
<div className="m-ud c-content-creator">
<div className="m-ud c-content-creator" ref={this.props.setMainContainerRef}>
<h1 className="m-ud__title">{title}</h1>
<div className="m-ud__content-wrapper">
<div className={contentClass} ref={(ref) => (this._refContentContainer = ref)}>
<div className={contentClass}>
{this.renderLoadingSpinner()}
<iframe
src={iframeUrl}
ref={(ref) => (this.iframe = ref)}
ref={(ref) => (this._refIframe = ref)}
className="c-content-creator__iframe"
onLoad={this.handleIframeLoad}
style={{ height: `${maxHeight + 32}px` }}
/>
</div>
<div className="m-ud__actions">
<div className="m-ud__btns">
<button className="m-ud__action--cancel" onClick={onCancel}>
<button className="m-ud__action--cancel" onClick={onCancel} type="button">
{cancelLabel}
</button>
<button className="m-ud__action--publish" onClick={this.handlePublish}>
{publishLabel}
</button>
{this.renderPublishBtn()}
</div>
</div>
</div>
Expand All @@ -140,6 +171,7 @@ ContentCreatorComponent.propTypes = {
handlePublish: PropTypes.func.isRequired,
loadLocation: PropTypes.func,
restInfo: PropTypes.object.isRequired,
setMainContainerRef: PropTypes.func.isRequired,
};

ContentCreatorComponent.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@
background: #cb3400;
}

.m-ud__action--publish[disabled],
.m-ud__action--publish[disabled]:hover,
.m-ud__action--publish[disabled]:focus {
cursor: not-allowed;
background: #f15a10;
opacity: 0.3;
}

.m-ud__content {
position: relative;
}

.is-loading:before {
content: "";
content: '';
position: absolute;
top: 0;
left: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,12 @@ import SelectContentButtonComponent from '../select-content-button/select.conten
import './css/content.table.item.component.css';

const ContentTableItemComponent = (props) => {
const {
onItemClick,
onPreview,
data,
contentTypesMap,
multiple,
selectedContent,
onSelectContent,
onItemRemove,
canSelectContent,
} = props;
const { onPreview, data, contentTypesMap, multiple, selectedContent, onSelectContent, onItemRemove, canSelectContent } = props;
const notAvailableLabel = Translator.trans(/*@Desc("N/A")*/ 'content_table.not_available.label', {}, 'universal_discovery_widget');
const item = data.ContentInfo.Content;
const contentType = contentTypesMap ? contentTypesMap[item.ContentType._href] : null;
const contentTypeIdentifier = contentType ? contentType.identifier : null;
const contentTypeName = contentTypeIdentifier ? window.eZ.adminUiConfig.contentTypeNames[contentTypeIdentifier] : notAvailableLabel;
const onClick = !!onItemClick ? onItemClick.bind(null, data) : null;
const isSelectedContent = selectedContent.find((content) => content.id === data.id);
const iconId = isSelectedContent ? 'checkmark' : 'create';

return (
<div className="c-content-table-item" onClick={() => onPreview(data)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const SearchPaginationComponent = (props) => {
console.warn('[DEPRECATED] it will be removed from ezplatform-admin-ui-modules 2.0');
console.warn('[DEPRECATED] use ContentTablePaginationComponent instead');

const { minIndex, activeIndex, maxIndex, onChange, labels } = props;
const { minIndex, activeIndex, maxIndex, onChange } = props;
const btnFirstLabel = Translator.trans(/*@Desc("First")*/ 'pagination.first', {}, 'universal_discovery_widget');
const btnPrevLabel = Translator.trans(/*@Desc("Previous")*/ 'pagination.prev', {}, 'universal_discovery_widget');
const btnNextLabel = Translator.trans(/*@Desc("Next")*/ 'pagination.next', {}, 'universal_discovery_widget');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export default class SelectedContentComponent extends PureComponent {
let limitLabel = '';

if (this.props.itemsLimit && this.props.multiple) {
const limitLabel = Translator.trans(
const limitLabelText = Translator.trans(
/*@Desc("Limit %items% max")*/ 'select_content.limit.label',
{
items: this.props.itemsLimit,
},
'universal_discovery_widget'
);

limitLabel = <small className="c-selected-content__label--limit">{limitLabel}</small>;
limitLabel = <small className="c-selected-content__label--limit">{limitLabelText}</small>;
}

return limitLabel;
Expand Down
7 changes: 6 additions & 1 deletion src/modules/universal-discovery/services/bookmark.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { showErrorNotification } from '../../common/services/notification.service';
import { getBasicRequestInit, handleRequestResponse, handleRequestError, handleRequestResponseStatus } from '../../common/helpers/request.helper.js';
import {
getBasicRequestInit,
handleRequestResponse,
handleRequestError,
handleRequestResponseStatus,
} from '../../common/helpers/request.helper.js';

const ENDPOINT_BOOKMARK = '/api/ezp/v2/bookmark';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ export default class UniversalDiscoveryModule extends Component {
onCancel={this.props.onCancel}
handlePublish={this.handlePublish}
restInfo={this.props.restInfo}
setMainContainerRef={this.setMainContainerRef}
/>
);
}
Expand Down

0 comments on commit 7848245

Please sign in to comment.