From bb9b8b83633aaa79837847ffa2580d9a9fc64917 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 2 Jan 2024 12:08:35 +1300 Subject: [PATCH] . --- client/dist/js/bundle.js | 270 ++++++++++++------ client/src/boot/registerTransforms.js | 28 +- .../ElementActions/ArchiveAction.js | 37 ++- .../ElementActions/DuplicateAction.js | 31 +- .../ElementActions/PublishAction.js | 25 +- .../ElementActions/UnpublishAction.js | 82 +++--- .../components/ElementEditor/ElementEditor.js | 11 +- src/Controllers/ElementalAreaController.php | 11 +- 8 files changed, 311 insertions(+), 184 deletions(-) diff --git a/client/dist/js/bundle.js b/client/dist/js/bundle.js index 2fe8f5c9..cf97af66 100644 --- a/client/dist/js/bundle.js +++ b/client/dist/js/bundle.js @@ -241,6 +241,9 @@ var _UnpublishAction2 = _interopRequireDefault(_UnpublishAction); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = function () { + + var globalUseGraphqQL = false; + _Injector2.default.transform('elemental-fieldgroup', function (updater) { updater.component('FieldGroup.HistoryViewer.VersionDetail', _HistoricElementView2.default, 'HistoricElement'); }, { @@ -255,16 +258,17 @@ exports.default = function () { updater.component('HistoryViewerToolbar.VersionedAdmin.HistoryViewer.Element.HistoryViewerVersionDetail', _revertToBlockVersionMutation2.default, 'BlockRevertMutation'); }); - var globalUseGraphqQL = false; if (globalUseGraphqQL) { _Injector2.default.transform('cms-element-editor', function (updater) { updater.component('ElementList', _readBlocksForAreaQuery2.default, 'PageElements'); }); } - _Injector2.default.transform('cms-element-adder', function (updater) { - updater.component('AddElementPopover', _addElementMutation2.default, 'ElementAddButton'); - }); + if (globalUseGraphqQL) { + _Injector2.default.transform('cms-element-adder', function (updater) { + updater.component('AddElementPopover', _addElementMutation2.default, 'ElementAddButton'); + }); + } _Injector2.default.transform('element-actions', function (updater) { updater.component('ElementActions', _SaveAction2.default, 'ElementActionsWithSave'); @@ -312,7 +316,7 @@ var _classnames = __webpack_require__(7); var _classnames2 = _interopRequireDefault(_classnames); -var _reactstrap = __webpack_require__(10); +var _reactstrap = __webpack_require__(11); var _elementTypeType = __webpack_require__("./client/src/types/elementTypeType.js"); @@ -383,28 +387,46 @@ var _i18n = __webpack_require__(2); var _i18n2 = _interopRequireDefault(_i18n); +var _ElementEditor = __webpack_require__("./client/src/components/ElementEditor/ElementEditor.js"); + +var _Backend = __webpack_require__(8); + +var _Backend2 = _interopRequireDefault(_Backend); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var ArchiveAction = function ArchiveAction(MenuComponent) { return function (props) { + var _useContext = (0, _react.useContext)(_ElementEditor.ElementEditorContext), + fetchBlocks = _useContext.fetchBlocks; + var handleClick = function handleClick(event) { event.stopPropagation(); - - var id = props.element.id, - isPublished = props.isPublished, - handleArchiveBlock = props.actions.handleArchiveBlock; - - + var isPublished = props.element.isPublished; var archiveMessage = _i18n2.default._t('ElementArchiveAction.CONFIRM_DELETE', 'Are you sure you want to send this block to the archive?'); - if (isPublished) { archiveMessage = _i18n2.default._t('ElementArchiveAction.CONFIRM_DELETE_AND_UNPUBLISH', 'Warning: This block will be unpublished before being sent to the archive. Are you sure you want to proceed?'); } - - if (handleArchiveBlock && window.confirm(archiveMessage)) { - handleArchiveBlock(id).then(function () { - var preview = window.jQuery('.cms-preview'); - preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); + if (!window.confirm(archiveMessage)) { + return; + } + var globalUseGraphqQL = false; + if (globalUseGraphqQL) { + var id = props.element.id, + handleArchiveBlock = props.actions.handleArchiveBlock; + + if (handleArchiveBlock) { + handleArchiveBlock(id).then(function () { + var preview = window.jQuery('.cms-preview'); + preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); + }); + } + } else { + var _id = props.element.id; + _Backend2.default.post('/admin/elemental-area/archive', { + ID: _id + }).then(function () { + return fetchBlocks(); }); } }; @@ -464,25 +486,42 @@ var _i18n = __webpack_require__(2); var _i18n2 = _interopRequireDefault(_i18n); +var _ElementEditor = __webpack_require__("./client/src/components/ElementEditor/ElementEditor.js"); + +var _Backend = __webpack_require__(8); + +var _Backend2 = _interopRequireDefault(_Backend); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var DuplicateAction = function DuplicateAction(MenuComponent) { return function (props) { + var _useContext = (0, _react.useContext)(_ElementEditor.ElementEditorContext), + fetchBlocks = _useContext.fetchBlocks; + if (props.type.broken) { return _react2.default.createElement(MenuComponent, props); } var handleClick = function handleClick(event) { event.stopPropagation(); - - var id = props.element.id, - handleDuplicateBlock = props.actions.handleDuplicateBlock; - - - if (handleDuplicateBlock) { - handleDuplicateBlock(id).then(function () { - var preview = window.jQuery('.cms-preview'); - preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); + var globalUseGraphqQL = false; + if (globalUseGraphqQL) { + var id = props.element.id, + handleDuplicateBlock = props.actions.handleDuplicateBlock; + + if (handleDuplicateBlock) { + handleDuplicateBlock(id).then(function () { + var preview = window.jQuery('.cms-preview'); + preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); + }); + } + } else { + var _id = props.element.id; + _Backend2.default.post('/admin/elemental-area/duplicate', { + ID: _id + }).then(function () { + return fetchBlocks(); }); } }; @@ -542,17 +581,19 @@ var _i18n = __webpack_require__(2); var _i18n2 = _interopRequireDefault(_i18n); -var _Backend = __webpack_require__(12); +var _Backend = __webpack_require__(8); var _Backend2 = _interopRequireDefault(_Backend); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); var _loadElementSchemaValue = __webpack_require__("./client/src/state/editor/loadElementSchemaValue.js"); var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); -var _reduxForm = __webpack_require__(11); +var _reduxForm = __webpack_require__(12); + +var _ElementEditor = __webpack_require__("./client/src/components/ElementEditor/ElementEditor.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -593,6 +634,9 @@ var performSaveForElementWithFormData = function performSaveForElementWithFormDa var PublishAction = function PublishAction(MenuComponent) { return function (props) { + var _useContext = (0, _react.useContext)(_ElementEditor.ElementEditorContext), + fetchBlocks = _useContext.fetchBlocks; + if (props.type.broken) { return _react2.default.createElement(MenuComponent, props); } @@ -601,6 +645,23 @@ var PublishAction = function PublishAction(MenuComponent) { formDirty = props.formDirty; + var publishElement = function publishElement() { + var globalUseGraphqQL = false; + if (globalUseGraphqQL) { + var id = props.element.id, + handleArchiveBlock = props.actions.handleArchiveBlock; + + return handleArchiveBlock(id); + } else { + var _id = props.element.id; + return _Backend2.default.post('/admin/elemental-area/publish', { + ID: _id + }).then(function () { + return fetchBlocks(); + }); + } + }; + var handleClick = function handleClick(event) { event.stopPropagation(); @@ -610,7 +671,6 @@ var PublishAction = function PublishAction(MenuComponent) { type = props.type, securityId = props.securityId, formData = props.formData, - handlePublishBlock = props.actions.handlePublishBlock, reinitialiseForm = props.reinitialiseForm; @@ -626,7 +686,7 @@ var PublishAction = function PublishAction(MenuComponent) { } actionFlow.then(function () { - return handlePublishBlock(id); + return publishElement(); }).then(function () { return reportPublicationStatus(type.title, title, true); }).catch(function () { @@ -705,13 +765,13 @@ var _react2 = _interopRequireDefault(_react); var _redux = __webpack_require__(4); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); var _AbstractAction = __webpack_require__("./client/src/components/ElementActions/AbstractAction.js"); var _AbstractAction2 = _interopRequireDefault(_AbstractAction); -var _Backend = __webpack_require__(12); +var _Backend = __webpack_require__(8); var _Backend2 = _interopRequireDefault(_Backend); @@ -723,7 +783,7 @@ var _loadElementSchemaValue = __webpack_require__("./client/src/state/editor/loa var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); -var _reduxForm = __webpack_require__(11); +var _reduxForm = __webpack_require__(12); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -829,7 +889,7 @@ exports.default = (0, _redux.compose)((0, _reactRedux.connect)(mapStateToProps, /***/ (function(module, exports, __webpack_require__) { "use strict"; - +/* WEBPACK VAR INJECTION */(function($) { Object.defineProperty(exports, "__esModule", { value: true @@ -854,46 +914,68 @@ var _i18n = __webpack_require__(2); var _i18n2 = _interopRequireDefault(_i18n); +var _Backend = __webpack_require__(8); + +var _Backend2 = _interopRequireDefault(_Backend); + +var _ElementEditor = __webpack_require__("./client/src/components/ElementEditor/ElementEditor.js"); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var UnpublishAction = function UnpublishAction(MenuComponent) { return function (props) { + var _useContext = (0, _react.useContext)(_ElementEditor.ElementEditorContext), + fetchBlocks = _useContext.fetchBlocks; + + var globalUseGraphqQL = false; + if (props.type.broken) { return _react2.default.createElement(MenuComponent, props); } - var element = props.element, - type = props.type, - handleUnpublishBlock = props.actions.handleUnpublishBlock; - - - var handleClick = function handleClick(event) { - event.stopPropagation(); - var _window = window, - $ = _window.jQuery; + var reportUnpublicationStatus = function reportUnpublicationStatus(type, title, success) { + var noTitle = _i18n2.default.inject(_i18n2.default._t('ElementHeader.NOTITLE', 'Untitled {type} block'), { type: type }); + var successMessage = _i18n2.default.inject(_i18n2.default._t('ElementUnpublishAction.SUCCESS_NOTIFICATION', 'Removed \'{title}\' from the published page'), { title: title || noTitle }); + var errorMessage = _i18n2.default.inject(_i18n2.default._t('ElementUnpublishAction.ERROR_NOTIFICATION', 'Error unpublishing \'{title}\''), { title: title || noTitle }); + window.jQuery.noticeAdd({ + text: success ? successMessage : errorMessage, + stay: false, + type: success ? 'success' : 'error' + }); + }; - var noTitle = _i18n2.default.inject(_i18n2.default._t('ElementHeader.NOTITLE', 'Untitled {type} block'), { type: type.title }); + var unpublishElement = function unpublishElement() { + if (globalUseGraphqQL) { + var id = props.element.id, + handleUnpublishBlock = props.actions.handleUnpublishBlock; - if (handleUnpublishBlock) { - handleUnpublishBlock(element.id).then(function () { + return handleUnpublishBlock(id).then(function () { var preview = $('.cms-preview'); preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); - - $.noticeAdd({ - text: _i18n2.default.inject(_i18n2.default._t('ElementUnpublishAction.SUCCESS_NOTIFICATION', 'Removed \'{title}\' from the published page'), { title: element.title || noTitle }), - stay: false, - type: 'success' - }); - }).catch(function () { - $.noticeAdd({ - text: _i18n2.default.inject(_i18n2.default._t('ElementUnpublishAction.ERROR_NOTIFICATION', 'Error unpublishing \'{title}\''), { title: element.title || noTitle }), - stay: false, - type: 'error' - }); + }); + } else { + var _id = props.element.id; + return _Backend2.default.post('/admin/elemental-area/unpublish', { + ID: _id + }).then(function () { + return fetchBlocks(); }); } }; + var element = props.element, + type = props.type; + + + var handleClick = function handleClick(event) { + event.stopPropagation(); + unpublishElement().then(function () { + return reportUnpublicationStatus(type.title, element.title, true); + }).catch(function () { + return reportUnpublicationStatus(type.title, element.title, false); + }); + }; + var disabled = props.element.canUnpublish !== undefined && !props.element.canUnpublish; var label = _i18n2.default._t('ElementArchiveAction.UNPUBLISH', 'Unpublish'); var title = disabled ? _i18n2.default._t('ElementArchiveAction.UNPUBLISH_PERMISSION_DENY', 'Unpublish, insufficient permissions') : label; @@ -917,6 +999,7 @@ var UnpublishAction = function UnpublishAction(MenuComponent) { exports.Component = UnpublishAction; exports.default = (0, _redux.compose)(_unpublishBlockMutation2.default, UnpublishAction); +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(17))) /***/ }), @@ -952,7 +1035,7 @@ var _i18n = __webpack_require__(2); var _i18n2 = _interopRequireDefault(_i18n); -var _Backend = __webpack_require__(12); +var _Backend = __webpack_require__(8); var _Backend2 = _interopRequireDefault(_Backend); @@ -1116,7 +1199,7 @@ var _propTypes = __webpack_require__(1); var _propTypes2 = _interopRequireDefault(_propTypes); -var _reactstrap = __webpack_require__(10); +var _reactstrap = __webpack_require__(11); var _i18n = __webpack_require__(2); @@ -1238,11 +1321,11 @@ var _Injector = __webpack_require__(3); var _redux = __webpack_require__(4); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); -var _reduxForm = __webpack_require__(11); +var _reduxForm = __webpack_require__(12); var _getFormState = __webpack_require__(16); @@ -1436,17 +1519,17 @@ var _classnames = __webpack_require__(7); var _classnames2 = _interopRequireDefault(_classnames); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); var _loadElementSchemaValue = __webpack_require__("./client/src/state/editor/loadElementSchemaValue.js"); -var _TabsActions = __webpack_require__(19); +var _TabsActions = __webpack_require__(20); var TabsActions = _interopRequireWildcard(_TabsActions); -var _reactDnd = __webpack_require__(9); +var _reactDnd = __webpack_require__(10); var _reactDndHtml5Backend = __webpack_require__(14); @@ -1829,7 +1912,7 @@ var _propTypes2 = _interopRequireDefault(_propTypes); var _redux = __webpack_require__(4); -var _reactstrap = __webpack_require__(10); +var _reactstrap = __webpack_require__(11); var _Injector = __webpack_require__(3); @@ -1993,7 +2076,7 @@ var _Header = __webpack_require__("./client/src/components/ElementEditor/Header. var _Header2 = _interopRequireDefault(_Header); -var _reactDnd = __webpack_require__(9); +var _reactDnd = __webpack_require__(10); var _elementType = __webpack_require__("./client/src/types/elementType.js"); @@ -2106,11 +2189,11 @@ var _redux = __webpack_require__(4); var _elementTypeType = __webpack_require__("./client/src/types/elementTypeType.js"); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); -var _reactDnd = __webpack_require__(9); +var _reactDnd = __webpack_require__(10); var _sortBlockMutation = __webpack_require__("./client/src/state/editor/sortBlockMutation.js"); @@ -2124,7 +2207,7 @@ var _withDragDropContext = __webpack_require__(21); var _withDragDropContext2 = _interopRequireDefault(_withDragDropContext); -var _Backend = __webpack_require__(12); +var _Backend = __webpack_require__(8); var _Backend2 = _interopRequireDefault(_Backend); @@ -2222,6 +2305,9 @@ var ElementEditor = function (_PureComponent) { contentBlocks: responseJson, isLoading: false })); + + var preview = window.jQuery('.cms-preview'); + preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); }); } }, { @@ -2384,7 +2470,7 @@ var _i18n = __webpack_require__(2); var _i18n2 = _interopRequireDefault(_i18n); -var _reactDnd = __webpack_require__(9); +var _reactDnd = __webpack_require__(10); var _dragHelpers = __webpack_require__("./client/src/lib/dragHelpers.js"); @@ -2621,7 +2707,7 @@ var _propTypes = __webpack_require__(1); var _propTypes2 = _interopRequireDefault(_propTypes); -var _reactstrap = __webpack_require__(10); +var _reactstrap = __webpack_require__(11); var _elementType = __webpack_require__("./client/src/types/elementType.js"); @@ -2629,7 +2715,7 @@ var _elementTypeType = __webpack_require__("./client/src/types/elementTypeType.j var _redux = __webpack_require__(4); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); var _Injector = __webpack_require__(3); @@ -2643,9 +2729,9 @@ var _classnames2 = _interopRequireDefault(_classnames); var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); -var _reduxForm = __webpack_require__(11); +var _reduxForm = __webpack_require__(12); -var _reactDnd = __webpack_require__(9); +var _reactDnd = __webpack_require__(10); var _getFormState = __webpack_require__(16); @@ -3060,7 +3146,7 @@ var _classnames = __webpack_require__(7); var _classnames2 = _interopRequireDefault(_classnames); -var _FormBuilderLoader = __webpack_require__(18); +var _FormBuilderLoader = __webpack_require__(19); var _FormBuilderLoader2 = _interopRequireDefault(_FormBuilderLoader); @@ -3072,7 +3158,7 @@ var _i18n2 = _interopRequireDefault(_i18n); var _loadElementFormStateName = __webpack_require__("./client/src/state/editor/loadElementFormStateName.js"); -var _reactRedux = __webpack_require__(8); +var _reactRedux = __webpack_require__(9); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -3296,7 +3382,7 @@ var _Injector = __webpack_require__(3); var _elementTypeType = __webpack_require__("./client/src/types/elementTypeType.js"); -var _reactDnd = __webpack_require__(9); +var _reactDnd = __webpack_require__(10); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -3502,9 +3588,9 @@ var _react = __webpack_require__(0); var _react2 = _interopRequireDefault(_react); -var _reactstrap = __webpack_require__(10); +var _reactstrap = __webpack_require__(11); -var _FieldHolder = __webpack_require__(17); +var _FieldHolder = __webpack_require__(18); var _FieldHolder2 = _interopRequireDefault(_FieldHolder); @@ -3561,7 +3647,7 @@ exports.default = (0, _FieldHolder2.default)(TextCheckboxGroupField); "use strict"; -var _jquery = __webpack_require__(20); +var _jquery = __webpack_require__(17); var _jquery2 = _interopRequireDefault(_jquery); @@ -3577,7 +3663,7 @@ var _Injector = __webpack_require__(3); var _elementConfig = __webpack_require__("./client/src/state/editor/elementConfig.js"); -var _reduxForm = __webpack_require__(11); +var _reduxForm = __webpack_require__(12); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -4634,21 +4720,21 @@ module.exports = PropTypes; /***/ 10: /***/ (function(module, exports) { -module.exports = Reactstrap; +module.exports = ReactDND; /***/ }), /***/ 11: /***/ (function(module, exports) { -module.exports = ReduxForm; +module.exports = Reactstrap; /***/ }), /***/ 12: /***/ (function(module, exports) { -module.exports = Backend; +module.exports = ReduxForm; /***/ }), @@ -4683,21 +4769,21 @@ module.exports = getFormState; /***/ 17: /***/ (function(module, exports) { -module.exports = FieldHolder; +module.exports = jQuery; /***/ }), /***/ 18: /***/ (function(module, exports) { -module.exports = FormBuilderLoader; +module.exports = FieldHolder; /***/ }), /***/ 19: /***/ (function(module, exports) { -module.exports = TabsActions; +module.exports = FormBuilderLoader; /***/ }), @@ -4711,7 +4797,7 @@ module.exports = i18n; /***/ 20: /***/ (function(module, exports) { -module.exports = jQuery; +module.exports = TabsActions; /***/ }), @@ -4760,14 +4846,14 @@ module.exports = classnames; /***/ 8: /***/ (function(module, exports) { -module.exports = ReactRedux; +module.exports = Backend; /***/ }), /***/ 9: /***/ (function(module, exports) { -module.exports = ReactDND; +module.exports = ReactRedux; /***/ }) diff --git a/client/src/boot/registerTransforms.js b/client/src/boot/registerTransforms.js index 78972976..0a8724d4 100644 --- a/client/src/boot/registerTransforms.js +++ b/client/src/boot/registerTransforms.js @@ -11,6 +11,9 @@ import SaveAction from 'components/ElementActions/SaveAction'; import UnpublishAction from 'components/ElementActions/UnpublishAction'; export default () => { + + const globalUseGraphqQL = false; + Injector.transform( 'elemental-fieldgroup', (updater) => { @@ -49,7 +52,6 @@ export default () => { } ); - const globalUseGraphqQL = false; if (globalUseGraphqQL) { Injector.transform( 'cms-element-editor', @@ -64,17 +66,19 @@ export default () => { ); } - Injector.transform( - 'cms-element-adder', - (updater) => { - // Add GraphQL query for adding elements to an ElementEditor (ElementalArea) - updater.component( - 'AddElementPopover', - addElementToArea, - 'ElementAddButton' - ); - } - ); + if (globalUseGraphqQL) { + Injector.transform( + 'cms-element-adder', + (updater) => { + // Add GraphQL query for adding elements to an ElementEditor (ElementalArea) + updater.component( + 'AddElementPopover', + addElementToArea, + 'ElementAddButton' + ); + } + ); + } // Add elemental editor actions Injector.transform('element-actions', (updater) => { diff --git a/client/src/components/ElementActions/ArchiveAction.js b/client/src/components/ElementActions/ArchiveAction.js index 339ab796..2b4b3185 100644 --- a/client/src/components/ElementActions/ArchiveAction.js +++ b/client/src/components/ElementActions/ArchiveAction.js @@ -1,37 +1,50 @@ /* global window */ -import React from 'react'; +import React, { useContext } from 'react'; import { compose } from 'redux'; import AbstractAction from 'components/ElementActions/AbstractAction'; import archiveBlockMutation from 'state/editor/archiveBlockMutation'; import i18n from 'i18n'; +import { ElementEditorContext } from 'components/ElementEditor/ElementEditor'; +import backend from 'lib/Backend'; /** * Adds the elemental menu action to archive a block of any state */ const ArchiveAction = (MenuComponent) => (props) => { + const { fetchBlocks } = useContext(ElementEditorContext); + const handleClick = (event) => { event.stopPropagation(); - - const { element: { id }, isPublished, actions: { handleArchiveBlock } } = props; - + const isPublished = props.element.isPublished; let archiveMessage = i18n._t( 'ElementArchiveAction.CONFIRM_DELETE', 'Are you sure you want to send this block to the archive?' ); - if (isPublished) { archiveMessage = i18n._t( 'ElementArchiveAction.CONFIRM_DELETE_AND_UNPUBLISH', 'Warning: This block will be unpublished before being sent to the archive. Are you sure you want to proceed?' ); } - - // eslint-disable-next-line no-alert - if (handleArchiveBlock && window.confirm(archiveMessage)) { - handleArchiveBlock(id).then(() => { - const preview = window.jQuery('.cms-preview'); - preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); - }); + if (!window.confirm(archiveMessage)) { + return; + } + const globalUseGraphqQL = false; + if (globalUseGraphqQL) { + const { element: { id }, actions: { handleArchiveBlock } } = props; + // eslint-disable-next-line no-alert + if (handleArchiveBlock) { + handleArchiveBlock(id).then(() => { + const preview = window.jQuery('.cms-preview'); + preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); + }); + } + } else { + const id = props.element.id; + backend.post(`/admin/elemental-area/archive`, { + ID: id, + }) + .then(() => fetchBlocks()); } }; diff --git a/client/src/components/ElementActions/DuplicateAction.js b/client/src/components/ElementActions/DuplicateAction.js index f1996aab..91a9bfa8 100644 --- a/client/src/components/ElementActions/DuplicateAction.js +++ b/client/src/components/ElementActions/DuplicateAction.js @@ -1,14 +1,18 @@ /* global window */ -import React from 'react'; +import React, { useContext } from 'react'; import { compose } from 'redux'; import AbstractAction from 'components/ElementActions/AbstractAction'; import duplicateBlockMutation from 'state/editor/duplicateBlockMutation'; import i18n from 'i18n'; +import { ElementEditorContext } from 'components/ElementEditor/ElementEditor'; +import backend from 'lib/Backend'; /** * Adds the elemental menu action to duplicate a block */ const DuplicateAction = (MenuComponent) => (props) => { + const { fetchBlocks } = useContext(ElementEditorContext); + if (props.type.broken) { // Don't allow this action for a broken element. return ( @@ -18,16 +22,23 @@ const DuplicateAction = (MenuComponent) => (props) => { const handleClick = (event) => { event.stopPropagation(); - - const { element: { id }, actions: { handleDuplicateBlock } } = props; - - if (handleDuplicateBlock) { - handleDuplicateBlock(id).then(() => { - const preview = window.jQuery('.cms-preview'); - preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); - }); + const globalUseGraphqQL = false; + if (globalUseGraphqQL) { + const { element: { id }, actions: { handleDuplicateBlock } } = props; + if (handleDuplicateBlock) { + handleDuplicateBlock(id).then(() => { + const preview = window.jQuery('.cms-preview'); + preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); + }); + } + } else { + const id = props.element.id; + backend.post('/admin/elemental-area/duplicate', { + ID: id, + }) + .then(() => fetchBlocks()); } - }; + } const disabled = props.element.canCreate !== undefined && !props.element.canCreate; const label = i18n._t('ElementArchiveAction.DUPLICATE', 'Duplicate'); diff --git a/client/src/components/ElementActions/PublishAction.js b/client/src/components/ElementActions/PublishAction.js index 60cdf4d7..4ea2c152 100644 --- a/client/src/components/ElementActions/PublishAction.js +++ b/client/src/components/ElementActions/PublishAction.js @@ -1,5 +1,5 @@ /* global window */ -import React from 'react'; +import React, { useContext } from 'react'; import { compose } from 'redux'; import AbstractAction from 'components/ElementActions/AbstractAction'; import publishBlockMutation from 'state/editor/publishBlockMutation'; @@ -9,6 +9,7 @@ import { connect } from 'react-redux'; import { loadElementSchemaValue } from 'state/editor/loadElementSchemaValue'; import { loadElementFormStateName } from 'state/editor/loadElementFormStateName'; import { initialize } from 'redux-form'; +import { ElementEditorContext } from 'components/ElementEditor/ElementEditor'; /** * Show a toast message reporting whether publication of Element was successful @@ -76,6 +77,8 @@ const performSaveForElementWithFormData = (id, formData, securityId) => { * Adds the elemental menu action to publish a draft/modified block */ const PublishAction = (MenuComponent) => (props) => { + const { fetchBlocks } = useContext(ElementEditorContext); + if (props.type.broken) { // Don't allow this action for a broken element. return ( @@ -85,6 +88,20 @@ const PublishAction = (MenuComponent) => (props) => { const { element, formDirty } = props; + const publishElement = () => { + const globalUseGraphqQL = false; + if (globalUseGraphqQL) { + const { element: { id }, actions: { handleArchiveBlock } } = props; + return handleArchiveBlock(id); + } else { + const id = props.element.id; + return backend.post('/admin/elemental-area/publish', { + ID: id, + }) + .then(() => fetchBlocks()); + } + } + const handleClick = (event) => { event.stopPropagation(); @@ -96,7 +113,6 @@ const PublishAction = (MenuComponent) => (props) => { type, securityId, formData, - actions: { handlePublishBlock }, reinitialiseForm, } = props; @@ -113,7 +129,8 @@ const PublishAction = (MenuComponent) => (props) => { // Perform publish. Data is assumed to be up to date actionFlow - .then(() => handlePublishBlock(id)) + // .then(() => handlePublishBlock(id)) + .then(() => publishElement()) .then(() => reportPublicationStatus(type.title, title, true)) .catch(() => reportPublicationStatus(type.title, title, false)); }; @@ -169,7 +186,7 @@ function mapDispatchToProps(dispatch, ownProps) { export { PublishAction as Component }; export default compose( - publishBlockMutation, + publishBlockMutation, // todo connect(mapStateToProps, mapDispatchToProps), PublishAction ); diff --git a/client/src/components/ElementActions/UnpublishAction.js b/client/src/components/ElementActions/UnpublishAction.js index a8bc506d..1a060045 100644 --- a/client/src/components/ElementActions/UnpublishAction.js +++ b/client/src/components/ElementActions/UnpublishAction.js @@ -1,14 +1,19 @@ /* global window */ -import React from 'react'; +import React, { useContext } from 'react'; import { compose } from 'redux'; import AbstractAction from 'components/ElementActions/AbstractAction'; import unpublishBlockMutation from 'state/editor/unpublishBlockMutation'; import i18n from 'i18n'; +import backend from 'lib/Backend'; +import { ElementEditorContext } from 'components/ElementEditor/ElementEditor'; /** * Adds the elemental menu action to unpublish a published block */ const UnpublishAction = (MenuComponent) => (props) => { + const { fetchBlocks } = useContext(ElementEditorContext); + const globalUseGraphqQL = false; + if (props.type.broken) { // Don't allow this action for a broken element. return ( @@ -16,52 +21,51 @@ const UnpublishAction = (MenuComponent) => (props) => { ); } - const { element, type, actions: { handleUnpublishBlock } } = props; - - const handleClick = (event) => { - event.stopPropagation(); - const { jQuery: $ } = window; + const reportUnpublicationStatus = (type, title, success) => { const noTitle = i18n.inject( - i18n._t( - 'ElementHeader.NOTITLE', - 'Untitled {type} block' - ), - { type: type.title } + i18n._t('ElementHeader.NOTITLE', 'Untitled {type} block'), + { type } ); + const successMessage = i18n.inject( + i18n._t('ElementUnpublishAction.SUCCESS_NOTIFICATION', 'Removed \'{title}\' from the published page'), + { title: title || noTitle } + ); + const errorMessage = i18n.inject( + i18n._t('ElementUnpublishAction.ERROR_NOTIFICATION', 'Error unpublishing \'{title}\''), + { title: title || noTitle } + ); + window.jQuery.noticeAdd({ + text: success ? successMessage : errorMessage, + stay: false, + type: success ? 'success' : 'error', + }); + } - if (handleUnpublishBlock) { - handleUnpublishBlock(element.id) + const unpublishElement = () => { + if (globalUseGraphqQL) { + const { element: { id }, actions: { handleUnpublishBlock } } = props; + return handleUnpublishBlock(id) .then(() => { const preview = $('.cms-preview'); preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); - - $.noticeAdd({ - text: i18n.inject( - i18n._t( - 'ElementUnpublishAction.SUCCESS_NOTIFICATION', - 'Removed \'{title}\' from the published page' - ), - { title: element.title || noTitle } - ), - stay: false, - type: 'success' - }); - }) - .catch(() => { - $.noticeAdd({ - text: i18n.inject( - i18n._t( - 'ElementUnpublishAction.ERROR_NOTIFICATION', - 'Error unpublishing \'{title}\'' - ), - { title: element.title || noTitle } - ), - stay: false, - type: 'error' - }); }); + } else { + const id = props.element.id; + return backend.post('/admin/elemental-area/unpublish', { + ID: id, + }) + .then(() => fetchBlocks()); } - }; + } + + const { element, type } = props; + + const handleClick = (event) => { + event.stopPropagation(); + unpublishElement() + .then(() => reportUnpublicationStatus(type.title, element.title, true)) + .catch(() => reportUnpublicationStatus(type.title, element.title, false)); + } const disabled = props.element.canUnpublish !== undefined && !props.element.canUnpublish; const label = i18n._t('ElementArchiveAction.UNPUBLISH', 'Unpublish'); diff --git a/client/src/components/ElementEditor/ElementEditor.js b/client/src/components/ElementEditor/ElementEditor.js index 7eabe07b..4372e799 100644 --- a/client/src/components/ElementEditor/ElementEditor.js +++ b/client/src/components/ElementEditor/ElementEditor.js @@ -70,17 +70,11 @@ class ElementEditor extends PureComponent { preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); }); } else { - // # rpc - // make a call to a sort endpoint with (ID, afterBlocKID) - // after sort there is NOT a call to readAll elements, GraphQL will only do a fairly pointless - // call to read the element that was moved - // (strange code for sorting is in this component and not ElementList, however do not refator it) - // update the preview via jquery/entwine (see graphql code above) backend.post(`/admin/elemental-area/sort`, { ID: sourceId, afterBlockID: afterId, }) - .then(() => this.fetchBlocks()) + .then(() => this.fetchBlocks()); } this.setState({ @@ -108,6 +102,9 @@ class ElementEditor extends PureComponent { contentBlocks: responseJson, isLoading: false, }) + // refresh preview + const preview = window.jQuery('.cms-preview'); + preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src')); }); } diff --git a/src/Controllers/ElementalAreaController.php b/src/Controllers/ElementalAreaController.php index 41b1eee6..0a851cb8 100644 --- a/src/Controllers/ElementalAreaController.php +++ b/src/Controllers/ElementalAreaController.php @@ -59,7 +59,7 @@ class ElementalAreaController extends CMSMain 'apiArchive', 'apiPublish', 'apiUnpublish', - 'revert', // ???? todo there is a revert mutation, though not sure it's actually used? + 'revert', // todo - revert mutation is used in history viewer (versioned-admin) ]; private function jsonResponse(int $statusCode = 200, ?array $data = null, string $message = ''): HTTPResponse @@ -132,7 +132,7 @@ public function apiUnpublish(): HTTPResponse public function apiDuplicate(): HTTPResponse { $id = $this->getPostData()['ID'] ?? ''; - $element = BaseElement::get()->byID($id); + $element = BaseElement::get()->byID($id); if (!$element) { return $this->jsonResponse(400, null, "Element with ID $id does not exist"); } @@ -257,8 +257,7 @@ public function apiAdd(): HTTPResponse $postData = json_decode($request->getBody(), true); $elementClass = $postData['elementClass']; $elementalAreaID = $postData['elementalAreaID']; - $afterElementID = $postData['afterElementID'] ?? null; - + $afterElementID = $postData['insertAfterElementID'] ?? null; // validate post vars if (!is_subclass_of($elementClass, BaseElement::class)) { throw new InvalidArgumentException("$elementClass is not a subclass of " . BaseElement::class); @@ -267,7 +266,6 @@ public function apiAdd(): HTTPResponse if (!$elementalArea) { throw new InvalidArgumentException("Invalid ElementalAreaID: $elementalAreaID"); } - // permission checks if (!$elementalArea->canEdit()) { throw new InvalidArgumentException("The current user has insufficient permission to edit ElementalAreas"); @@ -279,13 +277,11 @@ public function apiAdd(): HTTPResponse 'The current user has insufficient permission to edit Elements' ); } - // Assign the parent ID directly rather than via HasManyList to prevent multiple writes. // See BaseElement::$has_one for the "Parent" naming. $newElement->ParentID = $elementalArea->ID; // Ensure that a sort order is assigned - see BaseElement::onBeforeWrite() $newElement->onBeforeWrite(); - if ($afterElementID !== null) { /** @var ReorderElements $reorderer */ $reorderer = Injector::inst()->create(ReorderElements::class, $newElement); @@ -293,7 +289,6 @@ public function apiAdd(): HTTPResponse } else { $newElement->write(); } - $response = $this->getResponse(); $response->setStatusCode(201); return $response;