From 19a9d55298db3522c2ef1fe7e43fe05cf44b9c0a Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 11 Jan 2018 15:46:44 +1300 Subject: [PATCH] FIX Remove unused variables import and fix the close modal button after submitting Also update to use the FormBuilderModal component, matching AddToCampaignForm in core. --- client/dist/js/contentreview.js | 2 +- client/dist/js/contentreview.js.map | 1 - client/src/bundles/ContentReviewForm.js | 43 ++++++++++++------------- client/src/styles/bundle.scss | 3 -- 4 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 client/dist/js/contentreview.js.map diff --git a/client/dist/js/contentreview.js b/client/dist/js/contentreview.js index 6f24145..de17c30 100644 --- a/client/dist/js/contentreview.js +++ b/client/dist/js/contentreview.js @@ -1 +1 @@ -!function(e){function n(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}var t={};n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=4)}([function(e,n){e.exports=jQuery},function(e,n,t){"use strict";var o=t(10),i=t.n(o),r=t(0),s=t.n(r),c=t(7),a=t.n(c),u=t(8),d=t.n(u),l=t(9),f=(t.n(l),t(6)),_=(t.n(f),t(5)),p=t.n(_),h=t.i(f.provideInjector)(p.a);s.a.entwine("ss",function(e){e(".cms-content-actions .content-review__button").entwine({onclick:function(n){n.preventDefault();var t=e("#content-review__dialog-wrapper");return t.length||(t=e('
'),e("body").append(t)),t.open(),!1}}),e(".content-review-modal .content-review-modal__nav-link").entwine({onclick:function(n){n.preventDefault();var t=e(n.target);window.location=t.attr("href")}}),e("#content-review__dialog-wrapper").entwine({onunmatch:function(){this._clearModal()},open:function(){this._renderModal(!0)},close:function(){this._renderModal(!1)},_renderModal:function(n){var t=this,o=function(){return t.close()},r=function(){return t._handleSubmitModal.apply(t,arguments)},s=e("form.cms-edit-form :input[name=ID]").val(),c=window.ss.store,u=c.getState().config.sections.find(function(e){return"SilverStripe\\CMS\\Controllers\\CMSPageEditController"===e.name}),f=u.form.ReviewContentForm.schemaUrl+"/"+s,_=i.a._t("ContentReview.CONTENT_DUE_FOR_REVIEW","Content due for review");d.a.render(a.a.createElement(l.Provider,{store:c},a.a.createElement(h,{title:_,show:n,handleSubmit:r,handleHide:o,schemaUrl:f,bodyClassName:"modal__dialog",className:"content-review-modal",responseClassBad:"modal__response modal__response--error",responseClassGood:"modal__response modal__response--good",identifier:"ContentReview.CONTENT_DUE_FOR_REVIEW"})),this[0])},_clearModal:function(){d.a.unmountComponentAtNode(this[0])},_handleSubmitModal:function(e,n,t){return t()}})})},function(e,n,t){"use strict";var o=t(0);t.n(o).a.entwine("ss",function(e){e(".cms-edit-form #Form_EditForm_ContentReviewType_Holder").entwine({onmatch:function(){var e=this;this.find(".optionset :input").bind("change",function(n){e.show_option(n.target.value)});var n=this.find("input[name=ContentReviewType]:checked").val();this.show_option(n),this._super()},onunmatch:function(){return this._super()},show_option:function(e){"Custom"===e?this._custom():"Inherit"===e?this._inherited():this._disabled()},_custom:function(){e(".review-settings").show(),e(".field.custom-setting").show()},_inherited:function(){e(".review-settings").show(),e(".field.custom-setting").hide()},_disabled:function(){e(".review-settings").hide()}})})},function(e,n,t){"use strict";var o=t(0);t.n(o).a.entwine("ss",function(e){function n(n){var t="ContentReviewOwnerID"+n,o=e("div.subsiteSpecificOwnerID"),i=0;for(i=0;i'),n("body").append(e)),e.open(),!1}}),n(".content-review-modal .content-review-modal__nav-link").entwine({onclick:function(e){e.preventDefault();var t=n(e.target);window.location=t.attr("href")}}),n("#content-review__dialog-wrapper").entwine({onunmatch:function(){this._clearModal()},open:function(){this._renderModal(!0)},close:function(){this._renderModal(!1)},_renderModal:function(e){var t=this,o=function(){return t.close()},r=function(){return t._handleSubmitModal.apply(t,arguments)},s=n("form.cms-edit-form :input[name=ID]").val(),c=window.ss.store,u=c.getState().config.sections.find(function(n){return"SilverStripe\\CMS\\Controllers\\CMSPageEditController"===n.name}),l=u.form.ReviewContentForm.schemaUrl+"/"+s,_=i.a._t("ContentReview.CONTENT_DUE_FOR_REVIEW","Content due for review");d.a.render(a.a.createElement(f,{title:_,show:e,onSubmit:r,onHide:o,schemaUrl:l,bodyClassName:"modal__dialog",className:"content-review-modal",responseClassBad:"modal__response modal__response--error",responseClassGood:"modal__response modal__response--good",identifier:"ContentReview.CONTENT_DUE_FOR_REVIEW"}),this[0])},_clearModal:function(){d.a.unmountComponentAtNode(this[0])},_handleSubmitModal:function(e,t,o){return n(".content-review__button-holder").remove(),o()}})})},function(n,e,t){"use strict";var o=t(0);t.n(o).a.entwine("ss",function(n){n(".cms-edit-form #Form_EditForm_ContentReviewType_Holder").entwine({onmatch:function(){var n=this;this.find(".optionset :input").bind("change",function(e){n.show_option(e.target.value)});var e=this.find("input[name=ContentReviewType]:checked").val();this.show_option(e),this._super()},onunmatch:function(){return this._super()},show_option:function(n){"Custom"===n?this._custom():"Inherit"===n?this._inherited():this._disabled()},_custom:function(){n(".review-settings").show(),n(".field.custom-setting").show()},_inherited:function(){n(".review-settings").show(),n(".field.custom-setting").hide()},_disabled:function(){n(".review-settings").hide()}})})},function(n,e,t){"use strict";var o=t(0);t.n(o).a.entwine("ss",function(n){function e(e){var t="ContentReviewOwnerID"+e,o=n("div.subsiteSpecificOwnerID"),i=0;for(i=0;i {\n\t/**\n * Kick off a \"content due for review\" dialog from the CMS actions.\n */\n $('.cms-content-actions .content-review__button').entwine({\n onclick(e) {\n e.preventDefault();\n\n let dialog = $('#content-review__dialog-wrapper');\n\n if (!dialog.length) {\n dialog = $('
');\n $('body').append(dialog);\n }\n\n dialog.open();\n\n return false;\n },\n });\n\n // This is required because the React version of e.preventDefault() doesn't work\n // this is to prevent PJAX request to occur when clicking a link the modal\n $('.content-review-modal .content-review-modal__nav-link').entwine({\n onclick: (e) => {\n e.preventDefault();\n const $link = $(e.target);\n window.location = $link.attr('href');\n },\n });\n\n\t/**\n * Uses React-Bootstrap in order to replicate the bootstrap styling and JavaScript behaviour.\n */\n $('#content-review__dialog-wrapper').entwine({\n onunmatch() {\n // solves errors given by ReactDOM \"no matched root found\" error.\n this._clearModal();\n },\n\n open() {\n this._renderModal(true);\n },\n\n close() {\n this._renderModal(false);\n },\n\n _renderModal(show) {\n const handleHide = () => this.close();\n const handleSubmit = (...args) => this._handleSubmitModal(...args);\n const id = $('form.cms-edit-form :input[name=ID]').val();\n const store = window.ss.store;\n const sectionConfigKey = 'SilverStripe\\\\CMS\\\\Controllers\\\\CMSPageEditController';\n const sectionConfig = store.getState().config.sections\n .find((section) => section.name === sectionConfigKey);\n const modalSchemaUrl = `${sectionConfig.form.ReviewContentForm.schemaUrl}/${id}`;\n const title = i18n._t(\n 'SilverStripe\\\\ContentReview\\\\Models\\\\ContentReviewLog.CONTENT_DUE_FOR_REVIEW',\n 'Content due for review'\n );\n\n ReactDOM.render(\n \n \n ,\n this[0]\n );\n },\n\n _clearModal() {\n ReactDOM.unmountComponentAtNode(this[0]);\n // this.empty();\n },\n\n _handleSubmitModal(data, action, submitFn) {\n return submitFn();\n },\n });\n});\n\n\n\n// WEBPACK FOOTER //\n// ./client/src/bundles/ContentReviewForm.js","import jQuery from 'jquery';\n\njQuery.entwine('ss', ($) => {\n /**\n * Class: .cms-edit-form #Form_EditForm_ContentReviewType_Holder\n *\n * Toggle display of group dropdown in \"access\" tab,\n * based on selection of radiobuttons.\n */\n $('.cms-edit-form #Form_EditForm_ContentReviewType_Holder').entwine({\n // Constructor: onmatch\n onmatch() {\n const self = this;\n this.find('.optionset :input').bind('change', (e) => {\n self.show_option(e.target.value);\n });\n\n // initial state\n const currentVal = this.find('input[name=ContentReviewType]:checked').val();\n this.show_option(currentVal);\n this._super();\n },\n\n onunmatch() {\n return this._super();\n },\n\n show_option(value) {\n if (value === 'Custom') {\n this._custom();\n } else if (value === 'Inherit') {\n this._inherited();\n } else {\n this._disabled();\n }\n },\n\n _custom() {\n $('.review-settings').show();\n $('.field.custom-setting').show();\n },\n\n _inherited() {\n $('.review-settings').show();\n $('.field.custom-setting').hide();\n },\n\n _disabled() {\n $('.review-settings').hide();\n },\n });\n});\n\n\n\n// WEBPACK FOOTER //\n// ./client/src/bundles/ContentReviewSettings.js","import jQuery from 'jquery';\n\n/**\n * @todo Re-validate this with Subsites\n */\njQuery.entwine('ss', ($) => {\n // Hide all owner dropdowns except the one for the current subsite\n function showCorrectSubsiteIDDropdown(value) {\n const domid = `ContentReviewOwnerID${value}`;\n\n const ownerIDDropdowns = $('div.subsiteSpecificOwnerID');\n let i = 0;\n for (i = 0; i < ownerIDDropdowns.length; i++) {\n if (ownerIDDropdowns[i].id === domid) {\n $(ownerIDDropdowns[i]).show();\n } else {\n $(ownerIDDropdowns[i]).hide();\n }\n }\n }\n\n $('#Form_EditForm_SubsiteIDWithOwner').entwine({\n // Call method to show on report load\n onmatch() {\n showCorrectSubsiteIDDropdown(this.value);\n },\n\n // Call method to show on dropdown change\n change() {\n showCorrectSubsiteIDDropdown(this.value);\n },\n });\n});\n\n\n\n// WEBPACK FOOTER //\n// ./client/src/bundles/PagesDueForReview.js","import 'bundles/ContentReviewForm.js';\nimport 'bundles/ContentReviewSettings.js';\nimport 'bundles/PagesDueForReview.js';\n\n\n\n// WEBPACK FOOTER //\n// ./client/src/bundles/bundle.js","module.exports = FormBuilderModal;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"FormBuilderModal\"\n// module id = 5\n// module chunks = 0","module.exports = Injector;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"Injector\"\n// module id = 6\n// module chunks = 0","module.exports = React;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"React\"\n// module id = 7\n// module chunks = 0","module.exports = ReactDom;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"ReactDom\"\n// module id = 8\n// module chunks = 0","module.exports = ReactRedux;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"ReactRedux\"\n// module id = 9\n// module chunks = 0","module.exports = i18n;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"i18n\"\n// module id = 10\n// module chunks = 0"],"sourceRoot":""} \ No newline at end of file diff --git a/client/src/bundles/ContentReviewForm.js b/client/src/bundles/ContentReviewForm.js index 9ad4895..0edd662 100644 --- a/client/src/bundles/ContentReviewForm.js +++ b/client/src/bundles/ContentReviewForm.js @@ -1,12 +1,11 @@ +/* global window */ import i18n from 'i18n'; import jQuery from 'jquery'; import React from 'react'; import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux'; -import { provideInjector } from 'lib/Injector'; -import FormBuilderModal from 'components/FormBuilderModal/FormBuilderModal'; +import { loadComponent } from 'lib/Injector'; -const InjectableFormBuilderModal = provideInjector(FormBuilderModal); +const FormBuilderModal = loadComponent('FormBuilderModal'); /** * "Content due for review" modal popup. See AddToCampaignForm.js in @@ -17,9 +16,7 @@ jQuery.entwine('ss', ($) => { * Kick off a "content due for review" dialog from the CMS actions. */ $('.cms-content-actions .content-review__button').entwine({ - onclick(e) { - e.preventDefault(); - + onclick() { let dialog = $('#content-review__dialog-wrapper'); if (!dialog.length) { @@ -64,28 +61,26 @@ jQuery.entwine('ss', ($) => { const handleHide = () => this.close(); const handleSubmit = (...args) => this._handleSubmitModal(...args); const id = $('form.cms-edit-form :input[name=ID]').val(); - const store = window.ss.store; const sectionConfigKey = 'SilverStripe\\CMS\\Controllers\\CMSPageEditController'; + const store = window.ss.store; const sectionConfig = store.getState().config.sections .find((section) => section.name === sectionConfigKey); const modalSchemaUrl = `${sectionConfig.form.ReviewContentForm.schemaUrl}/${id}`; const title = i18n._t('ContentReview.CONTENT_DUE_FOR_REVIEW', 'Content due for review'); ReactDOM.render( - - - , + , this[0] ); }, @@ -95,6 +90,10 @@ jQuery.entwine('ss', ($) => { }, _handleSubmitModal(data, action, submitFn) { + // Remove the "review content" bell button so users won't do it again + $('.content-review__button-holder').remove(); + + // Handle the review submission return submitFn(); }, }); diff --git a/client/src/styles/bundle.scss b/client/src/styles/bundle.scss index ae52d95..cd41e1f 100644 --- a/client/src/styles/bundle.scss +++ b/client/src/styles/bundle.scss @@ -1,4 +1 @@ -// See includePaths in webpack.config.js -@import "variables"; - @import "ContentReviewForm";