From 1c20dbfa9db78df6ea1f23b1c65c005d56c2dec9 Mon Sep 17 00:00:00 2001 From: Sabina Talipova <87288324+sabina-talipova@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:00:47 +1300 Subject: [PATCH] ENH More Actions button is hidden if Campaign is published (#288) --- client/dist/js/bundle.js | 2 +- .../CampaignAdmin/CampaignAdminList.js | 22 ++++++------ .../tests/CampaignAdminList-test.js | 1 + src/CampaignAdmin.php | 3 ++ tests/behat/features/manage-campaigns.feature | 2 ++ tests/php/CampaignAdminTest.php | 36 +++++++++++++++++++ 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/client/dist/js/bundle.js b/client/dist/js/bundle.js index cb39e9c0..e4ec648c 100644 --- a/client/dist/js/bundle.js +++ b/client/dist/js/bundle.js @@ -1 +1 @@ -!function(){"use strict";var e={558:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a,i=(a=n(648))&&a.__esModule?a:{default:a};t.default=()=>{i.default.transform("add-to-campaign",(e=>{e.form.alterSchema("*.AddToCampaign",(e=>{if(!e.getFieldByName("AddNewSelect"))return e.getState();const t=e.getValue("AddNewSelect");return e.setFieldClass("NewTitle","show",t).setFieldClass("NewTitle","hide",!t).getState()}))}))}},274:function(e,t,n){var a=c(n(510)),i=c(n(648)),r=c(n(873)),o=c(n(646)),s=c(n(277)),l=c(n(558)),d=n(845);function c(e){return e&&e.__esModule?e:{default:e}}document.addEventListener("DOMContentLoaded",(()=>{const e=a.default.getSection("SilverStripe\\CampaignAdmin\\CampaignAdmin").reactRoutePath;r.default.add({path:"/",routes:[{path:(0,d.joinUrlPaths)(e,"set/:id/:view"),component:o.default},{path:(0,d.joinUrlPaths)(e,":type/:id/:view"),component:o.default},{path:e,component:o.default}]}),i.default.reducer.register("campaign",s.default),(0,l.default)()}))},235:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=l(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,n&&n.set(e,a);return a}(n(363)),i=s(n(86)),r=s(n(754)),o=s(n(264));function s(e){return e&&e.__esModule?e:{default:e}}function l(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(l=function(e){return e?n:t})(e)}class d extends a.Component{constructor(e){super(e),this.handleClose=this.handleClose.bind(this)}handleClose(e){this.props.onClose(e)}renderContent(){const e=o.default.infoScreen.callToAction,t=o.default.infoScreen.links;return a.default.createElement("div",{className:"flexbox-area-grow campaign-info__content"},a.default.createElement("h3",null,r.default._t("CampaignAdmin.InfoScreenHeader","How do campaigns work?")),a.default.createElement("p",null,r.default._t("CampaignAdmin.InfoScreenContent","Campaigns allow multiple users to publish large amounts of content (pages, files, etc.) all at once from one place.")),a.default.createElement("div",{className:"campaign-info__links"},t.map((e=>a.default.createElement("a",{key:e.text,href:e.link,target:"_blank",rel:"noopener noreferrer"},e.text)))),a.default.createElement("div",{className:"campaign-info__content-buttons"},e&&a.default.createElement("a",{className:"btn btn-outline-secondary",href:e.link,target:"_blank",rel:"noopener noreferrer"},e.text)))}render(){return this.props.show?a.default.createElement("div",{className:"fill-width campaign-info"},a.default.createElement("div",{className:"campaign-info__icon"},a.default.createElement("span",{className:"font-icon-white-question icon btn--icon-xl btn--no-text"})),this.renderContent(),a.default.createElement("div",{className:"campaign-info__banner-image"}),a.default.createElement("div",{className:"campaign-info__buttons"},a.default.createElement("a",{className:"btn campaign-info__close btn--no-text font-icon-cancel btn--icon-xl",onClick:this.handleClose,role:"button","aria-label":r.default._t("CampaignAdmin.HELP_HIDE","Hide help"),tabIndex:0}))):null}}d.propTypes={show:i.default.bool,onClose:i.default.func},d.defaultProps={show:!1,onClose:()=>null};t.default=d},264:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;const n="https://userhelp.silverstripe.org/en/4/creating_pages_and_content/campaigns/";t.default={infoScreen:{links:[{text:"Creating a new campaign",link:`${n}#creating-a-new-campaign`},{text:"Editing details/settings",link:`${n}#editing-details-settings`},{text:"Adding items to a campaign",link:`${n}#adding-items-to-a-campaign`},{text:"Managing items in a campaign",link:`${n}#managing-items-in-a-campaign`},{text:"Publishing a campaign",link:`${n}#publishing-a-campaign`}],callToAction:null}}},646:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.Component=void 0;var a=y(n(363)),i=v(n(86)),r=n(624),o=n(762),s=n(827),l=v(n(720)),d=v(n(159)),c=y(n(466)),u=y(n(674)),m=y(n(826)),p=v(n(803)),f=v(n(13)),h=v(n(754)),g=v(n(71)),C=v(n(238)),_=v(n(235)),b=v(n(104)),E=y(n(432)),A=y(n(108)),I=n(845),w=v(n(379));function v(e){return e&&e.__esModule?e:{default:e}}function S(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(S=function(e){return e?n:t})(e)}function y(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=S(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}return a.default=e,n&&n.set(e,a),a}function M(){return M=Object.assign?Object.assign.bind():function(e){for(var t=1;t1){const a=t[t.length-2];a&&a.href&&(e.preventDefault(),n(a.href))}}handleCreateCampaignSubmit(e,t,n){const a=n();if(!a)throw new Error("Promise was not returned for submitting");return a.then((e=>{const n=this.hasErrors(e);if("action_save"===t&&!n){const t=e.record.id;this.props.campaignActions.setNewItem(t),this.props.router.navigate(this.getActionRoute(t,"show"))}return e}))}handleFormAction(e){const{router:{navigate:t},sectionConfig:{reactRoutePath:n}}=this.props;"action_cancel"===e.currentTarget.name&&(t((0,I.joinUrlPaths)("/",n)),e.preventDefault())}handleRemoveCampaignItem(e,t){const n=h.default._t("CampaignAdmin.REMOVE_ITEM_MESSAGE","Are you sure you want to remove this item?\n\nBy removing this item all linked items will be removed unless used elsewhere.");return window.confirm(n)?(this.setState({loading:!0}),this.removeCampaignItem(e,t).then(this.fetchCampaignsList.bind(this)).then((()=>this.setState({loading:!1}))).then((()=>{this.props.campaignActions.selectChangeSetItem(null),window.document.body.click()}))):null}handleToggleMessage(){this.props.campaignActions.setShowMessage(!this.props.showMessage)}handleHideMessage(){this.props.campaignActions.setShowMessage(!1)}removeCampaignItem(e,t){return this.props.campaignActions.removeCampaignItem(this.removeCampaignItemApi,e,t)}fetchCampaignsList(){const e=this.props.sectionConfig.readCampaignsEndpoint,t=e.url;return this.props.recordActions.fetchRecords(this.props.sectionConfig.treeClass,e.method,t)}hasErrors(e){if(e.errors&&e.errors.length)return!0;const t=e.state;if(!t)return!1;if(t.messages&&t.messages.find((e=>"good"!==e.type)))return!0;const n=t.fields&&t.fields.find((e=>e.message&&"good"!==e.message.type));return Boolean(n)}campaignEditCreateFn(e,t){const{sectionConfig:{reactRoutePath:n},router:{navigate:i}}=this.props;if("action_cancel"===t.name){const r={...t,onClick:e=>{e.preventDefault(),i((0,I.joinUrlPaths)("/",n))}};return a.default.createElement(e,M({key:t.id},r))}return a.default.createElement(e,M({key:t.id},t))}campaignAddCreateFn(e,t){const{router:{navigate:n},sectionConfig:{reactRoutePath:i}}=this.props;if("action_cancel"===t.name){const r={...t,onClick:e=>{e.preventDefault(),n((0,I.joinUrlPaths)("/",i))}};return a.default.createElement(e,M({key:t.name},r))}return a.default.createElement(e,M({key:t.name},t))}campaignListCreateFn(e,t){const{router:{navigate:n},sectionConfig:{reactRoutePath:i}}=this.props;if("GridField"===t.schemaComponent){const r={...t,data:{...t.data,onDrillDown:(e,t)=>{n((0,I.joinUrlPaths)("/",i,`set/${t.ID}/show`))},onEditRecord:(e,t)=>{n((0,I.joinUrlPaths)("/",i,`set/${t}/edit`))}}};return a.default.createElement(e,M({key:r.name},r))}return a.default.createElement(e,M({key:t.name},t))}addCampaign(){const e=this.getActionRoute(0,"create");this.props.router.navigate(e)}renderDetailEditView(){const{FormBuilderLoaderComponent:e,BreadcrumbComponent:t}=this.props;if(this.props.router.params.id<=0)return this.renderCreateView();const n=this.props.sectionConfig.form.campaignEditForm.schemaUrl,i=(0,I.joinUrlPaths)(n,"/",this.props.router.params.id);return a.default.createElement("div",{className:"fill-height"},a.default.createElement(g.default,{showBackButton:!0,onBackButtonClick:this.handleBackButtonClick},a.default.createElement(t,{multiline:!0})),a.default.createElement(e,{fieldHolder:{className:"panel panel--padded panel--scrollable flexbox-area-grow form--inline"},actionHolder:{className:"toolbar--south"},onAction:this.handleFormAction,schemaUrl:i,identifier:"Campaign.EditView"}))}renderCreateView(){const{FormBuilderLoaderComponent:e,BreadcrumbComponent:t}=this.props,{schemaUrl:n}=this.props.sectionConfig.form.campaignCreateForm;return a.default.createElement("div",{className:"fill-height"},a.default.createElement(g.default,{showBackButton:!0,onBackButtonClick:this.handleBackButtonClick},a.default.createElement(t,{multiline:!0})),a.default.createElement(e,{fieldHolder:{className:"panel panel--padded panel--scrollable flexbox-area-grow form--inline"},actionHolder:{className:"toolbar--south"},onSubmit:this.handleCreateCampaignSubmit,onAction:this.handleFormAction,schemaUrl:n,identifier:"Campaign.CreateView"}))}renderIndexView(){const{showMessage:e,BreadcrumbComponent:t,FormBuilderLoaderComponent:n}=this.props,{schemaUrl:i}=this.props.sectionConfig.form.EditForm,r={title:h.default._t("CampaignAdmin.ADDCAMPAIGN","Add campaign"),icon:"plus",extraClass:"btn-primary",onClick:this.addCampaign},o={createFn:this.campaignListCreateFn.bind(this),schemaUrl:i,identifier:"Campaign.IndexView"};return a.default.createElement("div",{className:"fill-height","aria-expanded":"true"},a.default.createElement(g.default,null,a.default.createElement(t,{multiline:!0})),a.default.createElement("div",{className:"panel panel--scrollable flexbox-area-grow"},a.default.createElement(_.default,{show:e,onClose:this.handleHideMessage}),a.default.createElement("div",{className:"panel panel--padded flexbox-area-grow"},a.default.createElement("div",{className:"toolbar toolbar--content"},a.default.createElement("div",{className:"btn-toolbar fill-width"},a.default.createElement("div",{className:"btn-toolbar__left-panel flexbox-area-grow"},a.default.createElement(f.default,r)),a.default.createElement("div",{className:"btn-toolbar__left-panel"},a.default.createElement("a",{role:"button","aria-label":h.default._t("CampaignAdmin.HELP_SHOW","Show help"),tabIndex:0,onClick:this.handleToggleMessage,className:"btn btn-secondary font-icon-white-question btn--icon-xl btn--no-text"})))),a.default.createElement(n,o))))}renderItemListView(){const{sectionConfig:e,previewState:t,router:{params:{id:n}}}=this.props,{loading:i}=this.state,r={sectionConfig:e,campaignId:n,itemListViewEndpoint:e.itemListViewEndpoint,publishApi:this.publishApi,onBackButtonClick:this.handleBackButtonClick,onRemoveCampaignItem:this.handleRemoveCampaignItem,loading:i,previewState:t};return a.default.createElement(b.default,{style:{position:"relative"},className:"flexbox-area-grow fill-height",onResize:e=>{let{width:t}=e;return this.props.onResize(t)}},a.default.createElement(w.default,r))}render(){let e=null;switch(this.props.router.params.view){case"show":e=this.renderItemListView();break;case"edit":e=this.renderDetailEditView();break;case"create":e=this.renderCreateView();break;default:e=this.renderIndexView()}return e}}t.Component=N,N.propTypes={breadcrumbsActions:i.default.object.isRequired,campaignId:i.default.string,sectionConfig:i.default.shape({publishEndpoint:i.default.shape({url:i.default.string,method:i.default.string}),form:i.default.shape({EditForm:i.default.shape({schemaUrl:i.default.string}),campaignEditForm:i.default.shape({schemaUrl:i.default.string}),campaignCreateForm:i.default.shape({schemaUrl:i.default.string})})}),securityId:i.default.string.isRequired,view:i.default.string,router:E.routerPropTypes,showMessage:i.default.bool,previewState:i.default.oneOf(["edit","preview","split"]),onResize:i.default.func.isRequired,FormBuilderLoaderComponent:i.default.oneOfType([i.default.object,i.default.func]),BreadcrumbComponent:i.default.oneOfType([i.default.object,i.default.func])},N.defaultProps={sectionConfig:{},router:{params:{}},view:"show",breadcrumbs:[],FormBuilderLoaderComponent:C.default,BreadcrumbComponent:p.default};t.default=(0,E.default)((0,r.connect)((function(e,t){let n=null;const a=e.config.sections.find((e=>"SilverStripe\\CampaignAdmin\\CampaignAdmin"===e.name)),i=e.viewMode;if(t.router.params.id>0){const i=`${a.form.campaignEditForm.schemaUrl}/${t.router.params.id}`,r=e.form.formSchemas[i],s=r&&r.name&&(0,o.formValueSelector)(r.name,l.default);n=s&&s(e,"Name")}return{previewState:i.activeState,config:e.config,campaignId:e.campaign.campaignId,view:e.campaign.view,breadcrumbs:e.breadcrumbs,sectionConfig:a,securityId:e.config.SecurityID,title:n,showMessage:e.campaign.showMessage}}),(function(e){return{breadcrumbsActions:(0,s.bindActionCreators)(u,e),campaignActions:(0,s.bindActionCreators)(c,e),recordActions:(0,s.bindActionCreators)(m,e),onResize(t){e(A.enableOrDisableSplitMode(t))}}}))(N))},326:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=d(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,n&&n.set(e,a);return a}(n(363)),i=l(n(754)),r=n(127),o=l(n(742)),s=l(n(86));function l(e){return e&&e.__esModule?e:{default:e}}function d(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(d=function(e){return e?n:t})(e)}class c extends a.Component{getNumReferTo(){const{item:e}=this.props;return e._links&&e._links.references&&e._links.references.length||0}getNumReferredBy(){const{item:e}=this.props;return e._links&&e._links.referenced_by&&e._links.referenced_by.length||0}getReferToTooltipText(){const e=this.getNumReferTo();return i.default.inject(i.default._t("CampaignAdmin.LINKED_TO","Requires {number} item(s)"),{number:(0,o.default)(e)})}getReferredByTooltipText(){const e=this.getNumReferredBy();return i.default.inject(i.default._t("CampaignAdmin.LINKED_FROM","Required by {number} item(s)"),{number:(0,o.default)(e)})}renderLinks(){const{isLinked:e,selected:t,item:{ID:n}}=this.props,s=this.getNumReferTo(),l=this.getNumReferredBy(),d=[];s>0&&d.push(this.getReferToTooltipText()),l>0&&d.push(i.default.sprintf(0===d.length?this.getReferredByTooltipText():this.getReferredByTooltipText().toLocaleLowerCase(),(0,o.default)(l)));let c=null;if(t&&s+l>0||e){const t=["list-group-item__info","campaign-admin__item-links",e?"campaign-admin__item-links--is-linked":"campaign-admin__item-links--has-links"];c=a.default.createElement("div",{className:t.join(" ")},a.default.createElement("span",{id:`campaign-tooltip-${n}`},a.default.createElement("span",{className:"campaign-admin__item-links__number"},s+l),a.default.createElement("span",{className:"font-icon-link"})),a.default.createElement(r.UncontrolledTooltip,{placement:"left",target:`campaign-tooltip-${n}`},d.join(", ")))}return c}render(){let e=null;const t={},{campaign:n,item:r}=this.props;if("open"===n.State)switch(r.ChangeType){case"created":t.className="badge badge-warning list-group-item__status",t.Title=i.default._t("CampaignAdmin.DRAFT","Draft");break;case"modified":t.className="badge badge-warning list-group-item__status",t.Title=i.default._t("CampaignAdmin.MODIFIED","Modified");break;case"deleted":t.className="badge badge-error list-group-item__status",t.Title=i.default._t("CampaignAdmin.REMOVED","Removed");break;default:t.className="badge badge-success list-group-item__status",t.Title=i.default._t("CampaignAdmin.NO_CHANGES","No changes")}const o=this.renderLinks();r.Thumbnail&&(e=a.default.createElement("span",{className:"list-group-item__thumbnail"},a.default.createElement("img",{alt:r.Title,src:r.Thumbnail})));const s=r.Title?r.Title:i.default._t("CampaignAdmin.UNTITLED","Untitled");return a.default.createElement("div",{className:"fill-width"},e,a.default.createElement("div",{className:"list-group-item__details"},a.default.createElement("h4",{className:"list-group-item__heading",title:s},s),o,t.className&&t.Title&&a.default.createElement("span",{className:t.className},t.Title)))}}c.propTypes={campaign:s.default.object.isRequired,item:s.default.object.isRequired,isLinked:s.default.bool,selected:s.default.bool};t.default=c},379:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.Component=void 0;var a=w(n(363)),i=A(n(86)),r=n(827),o=n(624),s=w(n(674)),l=w(n(826)),d=w(n(466)),c=A(n(430)),u=A(n(942)),m=A(n(962)),p=A(n(71)),f=A(n(803)),h=n(127),g=A(n(754)),C=n(648),_=A(n(820)),b=n(845),E=A(n(326));function A(e){return e&&e.__esModule?e:{default:e}}function I(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(I=function(e){return e?n:t})(e)}function w(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=I(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}return a.default=e,n&&n.set(e,a),a}class v extends a.Component{constructor(e){super(e),this.handlePublish=this.handlePublish.bind(this),this.handleItemSelected=this.handleItemSelected.bind(this),this.setBreadcrumbs=this.setBreadcrumbs.bind(this),this.handleCloseItem=this.handleCloseItem.bind(this),this.handleRemoveItem=this.handleRemoveItem.bind(this),this.renderCampaignAdminListDetail=this.renderCampaignAdminListDetail.bind(this),this.isRecordLoaded(e)?this.state={loading:!1,error:!1,errorCode:0}:this.state={loading:!0,error:!1,errorCode:0}}componentDidMount(){const{campaignId:e,itemListViewEndpoint:t,recordActions:n,treeClass:a}=this.props,i=t.url.replace(/:id/,e);this.setBreadcrumbs(),this.isRecordLoaded()||n.fetchRecord(a,"get",i).then((()=>{this.setBreadcrumbs(),this.setState({loading:!1})})).catch((e=>{this.setState({loading:!1,error:!0,errorCode:e.response.status})}))}componentWillUnmount(){this.props.campaignActions.setNewItem(null)}setBreadcrumbs(){const{breadcrumbsActions:e,campaignId:t,record:n,sectionConfig:{reactRoutePath:a}}=this.props;if(!n)return;const i=[{text:g.default._t("CampaignAdmin.CAMPAIGN","Campaigns"),href:(0,b.joinUrlPaths)("/",a)}];i.push({text:n.Name,href:(0,b.joinUrlPaths)("/",a,`set/${t}/show`)}),e.setBreadcrumbs(i)}getSelectedItem(){const{campaign:{changeSetItemId:e}}=this.props,t=this.getItems()||[];let n=null;if(e&&(n=t.find((t=>e===t.ID))),!n){const e=this.groupItemsForSet(),t=Object.keys(e).find((t=>e[t]&&e[t].items.length>0));n=t?e[t].items[0]:null}return n}getMoreActions(){const{DropdownItemComponent:e}=this.props,t=this.getSelectedItem();if(!t)return null;const n=t._links&&t._links.referenced_by,i=n&&n.length||0,r=g.default._t("CampaignAdmin.UNREMOVEABLE_INFO","Required by {number} item(s), and cannot be removed directly.");return["explicitly"===t.Added?a.default.createElement(e,{key:"remove_action",className:"btn btn-secondary action",onClick:this.handleRemoveItem},g.default._t("CampaignAdmin.REMOVE","Remove")):a.default.createElement(e,{tag:"p",key:"unremoveable_info",className:"alert alert-info campaign-admin__unremoveable-item"},a.default.createElement("span",{className:"font-icon-link"}),g.default.inject(r,{number:i}))]}getItems(){const{record:e}=this.props;return e&&e._embedded?e._embedded.items:null}getPlaceholderGroups(){const e={},{record:t}=this.props;return t&&t.placeholderGroups&&t.placeholderGroups.forEach((t=>{e[t.baseClass]={...t},e[t.baseClass].items=[...t.items]})),e}groupItemsForSet(){const e=this.getPlaceholderGroups(),t=this.getItems();return t?(t.forEach((t=>{const n=t.BaseClass;e[n]||(e[n]={singular:t.Singular,plural:t.Plural,items:[]}),e[n].items.push(t)})),e):e}isRecordLoaded(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props;return 0!==Object.keys(e.record).length}handleRemoveItem(){const{campaignId:e,onRemoveCampaignItem:t}=this.props;"function"==typeof t&&t(e,this.getSelectedItem().ID)}handleItemSelected(e,t){this.props.campaignActions.selectChangeSetItem(t)}handleCloseItem(){this.props.campaignActions.selectChangeSetItem(null)}handlePublish(e){const{campaignId:t,campaignActions:{publishCampaign:n},publishApi:a,treeClass:i}=this.props;e.preventDefault();const r=g.default._t("CampaignAdmin.PUBLISH_CAMPAIGN_CONFIRM","Are you sure you want to publish this campaign?");window.confirm(r)&&n(a,i,t)}renderButtonToolbar(){const{ViewModeComponent:e,FormActionComponent:t,record:n,campaign:{isPublishing:i}}=this.props,r=this.getItems(),o=!r||0===r.length;let s=null;return o?s={title:g.default._t("CampaignAdmin.PUBLISHCAMPAIGN","Publish campaign"),buttonStyle:"outline-secondary",icon:"rocket",disabled:!0}:"open"===n.State&&(s={title:g.default._t("CampaignAdmin.PUBLISHCAMPAIGN","Publish campaign"),buttonStyle:"primary",loading:i,onClick:this.handlePublish,icon:"rocket"}),s?a.default.createElement("div",{className:"btn-toolbar"},a.default.createElement(t,s),!o&&a.default.createElement(e,{id:"view-mode-toggle-in-edit-nb",area:"edit"})):null}renderErrorMessage(e){switch(e){case 403:return a.default.createElement("p",null,g.default._t("CampaignAdmin.FORBIDDEN","You do not have access to view this campaign."));case 404:return a.default.createElement("p",null,g.default._t("CampaignAdmin.PAGE_NOT_FOUND","The campaign you are looking for can not be found."));default:return a.default.createElement("p",null,g.default._t("CampaignAdmin.SOMETHING_WENT_WRONG","Something went wrong."))}}renderPreview(e,t){const{PreviewComponent:n,previewState:i}=this.props,{loading:r,error:o,errorCode:s}=this.state;let l=["flexbox-area-grow","fill-height","preview","campaign-admin__campaign-preview","campaign-admin__campaign-preview--empty"];switch(i){case"preview":l.push("preview-only");break;case"edit":return null}if(l=(0,_.default)(l),r)return a.default.createElement("div",{className:l},a.default.createElement("p",null,g.default._t("CampaignAdmin.LOADING","Loading...")));if(o)return a.default.createElement("div",{className:l},this.renderErrorMessage(s));if(!this.getItems()||0===this.getItems().length){const e=g.default._t("CampaignAdmin.SELECTFROMSECTIONS",'Select "Add to Campaign" from pages, files, and other admin sections with content types');return a.default.createElement("div",{className:l},a.default.createElement("h2",{className:"campaign-admin__empty-heading"},g.default._t("CampaignAdmin.GETTINGSTARTED","Getting started")),a.default.createElement("p",{className:"campaign-admin__empty-info"},e))}return a.default.createElement(n,{itemLinks:e,itemId:t,onBack:this.handleCloseItem,moreActions:this.getMoreActions(),className:l})}renderCampaignAdminListDetail(e){const{previewState:t,onBackButtonClick:n,newItem:i,BreadcrumbComponent:r}=this.props,o=(0,_.default)("panel","panel--padded","panel--scrollable","flexbox-area-grow"),s=i?a.default.createElement("p",{className:"alert alert-success alert--no-border",role:"alert"},g.default._t("CampaignAdmin.NEWCAMPAIGNSUCCESS","Nice one! You have successfully created a campaign.")):null;if("preview"===t)return null;const l=(0,_.default)("fill-height","campaign-admin__campaign-items",{"fill-height":"edit"===t,"campaign-admin__campaign-items-edit":"edit"===t});return a.default.createElement("div",{className:l,"aria-expanded":"true"},a.default.createElement(p.default,{showBackButton:!0,onBackButtonClick:n},a.default.createElement(r,{multiline:!0})),s,a.default.createElement("div",{className:o},e),a.default.createElement("div",{className:"toolbar toolbar--south"},this.renderButtonToolbar()))}render(){const{campaign:{changeSetItemId:e},campaignId:t,record:n}=this.props;let i=e,r=null;const o=i?"":"campaign-admin__campaign--hide-preview",s=this.groupItemsForSet(),l=[],d=this.getSelectedItem(),p=d&&d._links&&d._links.references||[],f=d&&d._links&&d._links.referenced_by||[];Object.keys(s).forEach((e=>{const o=s[e],d=o.items.length,c=[],h=`\n ${0===d?"":d}\n ${1===d?o.singular:o.plural}\n `,g=`Set_${t}_Group_${e}`;o.items.forEach(((e,t)=>{i||(i=e.ID);const o=i===e.ID;o&&e._links&&(r=e._links);const s=(0,_.default)({"list-group-item--inactive":"none"===e.ChangeType||"published"===n.State,active:o});let l=!!p.find((t=>t.ChangeSetItemID===parseInt(e.ID,10)));l=l||f.find((t=>t.ChangeSetItemID===e.ID)),c.push(a.default.createElement(m.default,{key:e.ID||t,className:s,onClick:this.handleItemSelected,onClickArg:e.ID},a.default.createElement(E.default,{item:e,campaign:this.props.record,selected:o,isLinked:l})))}));const C=(0,_.default)("list-group-wrapper",{"list-group-wrapper--empty":0===c.length});l.push(a.default.createElement("div",{className:C,key:g},a.default.createElement(u.default,{groupid:g,title:h},c.length>0?c:a.default.createElement("p",{className:"list-group-item"},o.noItemsText))))}));const h=a.default.createElement(c.default,null,l),g=this.props.loading&&[a.default.createElement("div",{key:"overlay",className:"cms-content-loading-overlay ui-widget-overlay-light"}),a.default.createElement("div",{key:"spinner",className:"cms-content-loading-spinner"})];return a.default.createElement("div",{className:`fill-width campaign-admin__campaign ${o}`},g,this.renderCampaignAdminListDetail(h,r),this.renderPreview(r,i))}}t.Component=v,v.propTypes={campaign:i.default.shape({isPublishing:i.default.bool,changeSetItemId:i.default.number}),publishApi:i.default.func.isRequired,record:i.default.object.isRequired,sectionConfig:i.default.object.isRequired,onBackButtonClick:i.default.func,onRemoveCampaignItem:i.default.func,breadcrumbsActions:i.default.object.isRequired,campaignActions:i.default.object.isRequired,recordActions:i.default.object.isRequired,PreviewComponent:i.default.elementType,ViewModeComponent:i.default.elementType,FormActionComponent:i.default.elementType,previewState:i.default.oneOf(["edit","preview","split"]),BreadcrumbComponent:i.default.oneOfType([i.default.object,i.default.func]),DropdownItemComponent:i.default.oneOfType([i.default.object,i.default.func])},v.defaultProps={BreadcrumbComponent:f.default,DropdownItemComponent:h.DropdownItem};t.default=(0,r.compose)((0,o.connect)((function(e,t){const n=t.sectionConfig.treeClass,a=parseInt(t.campaignId,10),i=(e.records[n]||[]).find((e=>e.ID===a))||{};return{config:e.config,record:i,campaign:e.campaign,treeClass:n,newItem:e.campaign.newItem}}),(function(e){return{breadcrumbsActions:(0,r.bindActionCreators)(s,e),recordActions:(0,r.bindActionCreators)(l,e),campaignActions:(0,r.bindActionCreators)(d,e)}})),(0,C.inject)(["FormAction","ViewModeToggle","Preview"],((e,t,n)=>({FormActionComponent:e,ViewModeComponent:t,PreviewComponent:n})),(()=>"CampaignAdmin.CampaignAdmin.List")))(v)},675:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default={SET_CAMPAIGN_ACTIVE_CHANGESET:"SET_CAMPAIGN_ACTIVE_CHANGESET",SET_CAMPAIGN_SELECTED_CHANGESETITEM:"SET_CAMPAIGN_SELECTED_CHANGESETITEM",PUBLISH_CAMPAIGN_REQUEST:"PUBLISH_CAMPAIGN_REQUEST",PUBLISH_CAMPAIGN_SUCCESS:"PUBLISH_CAMPAIGN_SUCCESS",PUBLISH_CAMPAIGN_FAILURE:"PUBLISH_CAMPAIGN_FAILURE",SET_NEW_CAMPAIGN:"SET_NEW_CAMPAIGN",REMOVE_CAMPAIGN_ITEM_REQUEST:"REMOVE_CAMPAIGN_ITEM_REQUEST",REMOVE_CAMPAIGN_ITEM_SUCCESS:"REMOVE_CAMPAIGN_ITEM_SUCCESS",REMOVE_CAMPAIGN_ITEM_FAILURE:"REMOVE_CAMPAIGN_ITEM_FAILURE",SET_SHOW_MESSAGE:"SET_SHOW_MESSAGE"}},466:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.publishCampaign=function(e,t,n){return s=>{s({type:o.default.PUBLISH_CAMPAIGN_REQUEST,payload:{campaignId:n}}),e({id:n}).then((e=>{s({type:o.default.PUBLISH_CAMPAIGN_SUCCESS,payload:{campaignId:n}}),s({type:a.default.FETCH_RECORD_SUCCESS,payload:{recordType:t,data:e}});const l=r.default._t("CampaignAdmin.PUBLISH_SUCCESS",'Published "%s" successfully.');s(i.success(r.default.sprintf(l,e.Name)))})).catch((e=>{s({type:o.default.PUBLISH_CAMPAIGN_FAILURE,payload:{error:e}});const t="string"==typeof e?e:r.default._t("CampaignAdmin.PUBLISH_FAIL","Campaign could not be published.");s(i.error(t))}))}},t.removeCampaignItem=function(e,t,n){return a=>(a({type:o.default.REMOVE_CAMPAIGN_ITEM_REQUEST,payload:{campaignId:t,itemId:n}}),e({id:t,itemId:n}).then((()=>{a({type:o.default.REMOVE_CAMPAIGN_ITEM_SUCCESS,payload:{campaignId:t,itemId:n}})})).catch((e=>{a({type:o.default.REMOVE_CAMPAIGN_ITEM_FAILURE,payload:{error:e}})})))},t.selectChangeSetItem=function(e){return{type:o.default.SET_CAMPAIGN_SELECTED_CHANGESETITEM,payload:{changeSetItemId:e}}},t.setNewItem=function(e){return{type:o.default.SET_NEW_CAMPAIGN,payload:{newItem:e}}},t.setShowMessage=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.localStorage;return t.setItem("campaign.showMessage",e),{type:o.default.SET_SHOW_MESSAGE,payload:{show:e}}},t.showCampaignView=function(e,t){return n=>{n({type:o.default.SET_CAMPAIGN_ACTIVE_CHANGESET,payload:{campaignId:e,view:t}})}};var a=l(n(852)),i=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=s(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,n&&n.set(e,a);return a}(n(123)),r=l(n(754)),o=l(n(675));function s(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(s=function(e){return e?n:t})(e)}function l(e){return e&&e.__esModule?e:{default:e}}},277:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=r(n(752)),i=r(n(675));function r(e){return e&&e.__esModule?e:{default:e}}const o=window.localStorage.getItem("campaign.showMessage"),s=(0,a.default)({campaignId:null,changeSetItemId:null,isPublishing:!1,view:null,newItem:null,showMessage:null===o});t.default=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case i.default.SET_CAMPAIGN_SELECTED_CHANGESETITEM:return(0,a.default)(Object.assign({},e,{changeSetItemId:t.payload.changeSetItemId}));case i.default.SET_CAMPAIGN_ACTIVE_CHANGESET:return(0,a.default)(Object.assign({},e,{campaignId:t.payload.campaignId,view:t.payload.view,changeSetItemId:null}));case i.default.PUBLISH_CAMPAIGN_REQUEST:return(0,a.default)(Object.assign({},e,{isPublishing:!0}));case i.default.PUBLISH_CAMPAIGN_SUCCESS:case i.default.PUBLISH_CAMPAIGN_FAILURE:return(0,a.default)(Object.assign({},e,{isPublishing:!1}));case i.default.SET_NEW_CAMPAIGN:return(0,a.default)({...e,newItem:t.payload.newItem});case i.default.SET_SHOW_MESSAGE:return(0,a.default)({...e,showMessage:t.payload.show});default:return e}}},430:function(e){e.exports=Accordion},942:function(e){e.exports=AccordionBlock},159:function(e){e.exports=Backend},803:function(e){e.exports=Breadcrumb},674:function(e){e.exports=BreadcrumbsActions},510:function(e){e.exports=Config},752:function(e){e.exports=DeepFreezeStrict},13:function(e){e.exports=FormAction},238:function(e){e.exports=FormBuilderLoader},648:function(e){e.exports=Injector},962:function(e){e.exports=ListGroupItem},86:function(e){e.exports=PropTypes},363:function(e){e.exports=React},624:function(e){e.exports=ReactRedux},873:function(e){e.exports=ReactRouteRegister},127:function(e){e.exports=Reactstrap},852:function(e){e.exports=RecordsActionTypes},826:function(e){e.exports=RecordsActions},827:function(e){e.exports=Redux},762:function(e){e.exports=ReduxForm},104:function(e){e.exports=ResizeAware},123:function(e){e.exports=ToastsActions},71:function(e){e.exports=Toolbar},108:function(e){e.exports=ViewModeActions},820:function(e){e.exports=classnames},742:function(e){e.exports=formatWrittenNumber},720:function(e){e.exports=getFormState},754:function(e){e.exports=i18n},845:function(e){e.exports=ssUrlLib},432:function(e){e.exports=withRouter}},t={};function n(a){var i=t[a];if(void 0!==i)return i.exports;var r=t[a]={exports:{}};return e[a](r,r.exports,n),r.exports}n(274)}(); \ No newline at end of file +!function(){"use strict";var e={558:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a,i=(a=n(648))&&a.__esModule?a:{default:a};t.default=()=>{i.default.transform("add-to-campaign",(e=>{e.form.alterSchema("*.AddToCampaign",(e=>{if(!e.getFieldByName("AddNewSelect"))return e.getState();const t=e.getValue("AddNewSelect");return e.setFieldClass("NewTitle","show",t).setFieldClass("NewTitle","hide",!t).getState()}))}))}},274:function(e,t,n){var a=c(n(510)),i=c(n(648)),r=c(n(873)),o=c(n(646)),s=c(n(277)),l=c(n(558)),d=n(845);function c(e){return e&&e.__esModule?e:{default:e}}document.addEventListener("DOMContentLoaded",(()=>{const e=a.default.getSection("SilverStripe\\CampaignAdmin\\CampaignAdmin").reactRoutePath;r.default.add({path:"/",routes:[{path:(0,d.joinUrlPaths)(e,"set/:id/:view"),component:o.default},{path:(0,d.joinUrlPaths)(e,":type/:id/:view"),component:o.default},{path:e,component:o.default}]}),i.default.reducer.register("campaign",s.default),(0,l.default)()}))},235:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=l(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,n&&n.set(e,a);return a}(n(363)),i=s(n(86)),r=s(n(754)),o=s(n(264));function s(e){return e&&e.__esModule?e:{default:e}}function l(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(l=function(e){return e?n:t})(e)}class d extends a.Component{constructor(e){super(e),this.handleClose=this.handleClose.bind(this)}handleClose(e){this.props.onClose(e)}renderContent(){const e=o.default.infoScreen.callToAction,t=o.default.infoScreen.links;return a.default.createElement("div",{className:"flexbox-area-grow campaign-info__content"},a.default.createElement("h3",null,r.default._t("CampaignAdmin.InfoScreenHeader","How do campaigns work?")),a.default.createElement("p",null,r.default._t("CampaignAdmin.InfoScreenContent","Campaigns allow multiple users to publish large amounts of content (pages, files, etc.) all at once from one place.")),a.default.createElement("div",{className:"campaign-info__links"},t.map((e=>a.default.createElement("a",{key:e.text,href:e.link,target:"_blank",rel:"noopener noreferrer"},e.text)))),a.default.createElement("div",{className:"campaign-info__content-buttons"},e&&a.default.createElement("a",{className:"btn btn-outline-secondary",href:e.link,target:"_blank",rel:"noopener noreferrer"},e.text)))}render(){return this.props.show?a.default.createElement("div",{className:"fill-width campaign-info"},a.default.createElement("div",{className:"campaign-info__icon"},a.default.createElement("span",{className:"font-icon-white-question icon btn--icon-xl btn--no-text"})),this.renderContent(),a.default.createElement("div",{className:"campaign-info__banner-image"}),a.default.createElement("div",{className:"campaign-info__buttons"},a.default.createElement("a",{className:"btn campaign-info__close btn--no-text font-icon-cancel btn--icon-xl",onClick:this.handleClose,role:"button","aria-label":r.default._t("CampaignAdmin.HELP_HIDE","Hide help"),tabIndex:0}))):null}}d.propTypes={show:i.default.bool,onClose:i.default.func},d.defaultProps={show:!1,onClose:()=>null};t.default=d},264:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;const n="https://userhelp.silverstripe.org/en/4/creating_pages_and_content/campaigns/";t.default={infoScreen:{links:[{text:"Creating a new campaign",link:`${n}#creating-a-new-campaign`},{text:"Editing details/settings",link:`${n}#editing-details-settings`},{text:"Adding items to a campaign",link:`${n}#adding-items-to-a-campaign`},{text:"Managing items in a campaign",link:`${n}#managing-items-in-a-campaign`},{text:"Publishing a campaign",link:`${n}#publishing-a-campaign`}],callToAction:null}}},646:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.Component=void 0;var a=y(n(363)),i=v(n(86)),r=n(624),o=n(762),s=n(827),l=v(n(720)),d=v(n(159)),c=y(n(466)),u=y(n(674)),m=y(n(826)),p=v(n(803)),f=v(n(13)),h=v(n(754)),g=v(n(71)),C=v(n(238)),_=v(n(235)),b=v(n(104)),E=y(n(432)),A=y(n(108)),I=n(845),w=v(n(379));function v(e){return e&&e.__esModule?e:{default:e}}function S(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(S=function(e){return e?n:t})(e)}function y(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=S(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}return a.default=e,n&&n.set(e,a),a}function M(){return M=Object.assign?Object.assign.bind():function(e){for(var t=1;t1){const a=t[t.length-2];a&&a.href&&(e.preventDefault(),n(a.href))}}handleCreateCampaignSubmit(e,t,n){const a=n();if(!a)throw new Error("Promise was not returned for submitting");return a.then((e=>{const n=this.hasErrors(e);if("action_save"===t&&!n){const t=e.record.id;this.props.campaignActions.setNewItem(t),this.props.router.navigate(this.getActionRoute(t,"show"))}return e}))}handleFormAction(e){const{router:{navigate:t},sectionConfig:{reactRoutePath:n}}=this.props;"action_cancel"===e.currentTarget.name&&(t((0,I.joinUrlPaths)("/",n)),e.preventDefault())}handleRemoveCampaignItem(e,t){const n=h.default._t("CampaignAdmin.REMOVE_ITEM_MESSAGE","Are you sure you want to remove this item?\n\nBy removing this item all linked items will be removed unless used elsewhere.");return window.confirm(n)?(this.setState({loading:!0}),this.removeCampaignItem(e,t).then(this.fetchCampaignsList.bind(this)).then((()=>this.setState({loading:!1}))).then((()=>{this.props.campaignActions.selectChangeSetItem(null),window.document.body.click()}))):null}handleToggleMessage(){this.props.campaignActions.setShowMessage(!this.props.showMessage)}handleHideMessage(){this.props.campaignActions.setShowMessage(!1)}removeCampaignItem(e,t){return this.props.campaignActions.removeCampaignItem(this.removeCampaignItemApi,e,t)}fetchCampaignsList(){const e=this.props.sectionConfig.readCampaignsEndpoint,t=e.url;return this.props.recordActions.fetchRecords(this.props.sectionConfig.treeClass,e.method,t)}hasErrors(e){if(e.errors&&e.errors.length)return!0;const t=e.state;if(!t)return!1;if(t.messages&&t.messages.find((e=>"good"!==e.type)))return!0;const n=t.fields&&t.fields.find((e=>e.message&&"good"!==e.message.type));return Boolean(n)}campaignEditCreateFn(e,t){const{sectionConfig:{reactRoutePath:n},router:{navigate:i}}=this.props;if("action_cancel"===t.name){const r={...t,onClick:e=>{e.preventDefault(),i((0,I.joinUrlPaths)("/",n))}};return a.default.createElement(e,M({key:t.id},r))}return a.default.createElement(e,M({key:t.id},t))}campaignAddCreateFn(e,t){const{router:{navigate:n},sectionConfig:{reactRoutePath:i}}=this.props;if("action_cancel"===t.name){const r={...t,onClick:e=>{e.preventDefault(),n((0,I.joinUrlPaths)("/",i))}};return a.default.createElement(e,M({key:t.name},r))}return a.default.createElement(e,M({key:t.name},t))}campaignListCreateFn(e,t){const{router:{navigate:n},sectionConfig:{reactRoutePath:i}}=this.props;if("GridField"===t.schemaComponent){const r={...t,data:{...t.data,onDrillDown:(e,t)=>{n((0,I.joinUrlPaths)("/",i,`set/${t.ID}/show`))},onEditRecord:(e,t)=>{n((0,I.joinUrlPaths)("/",i,`set/${t}/edit`))}}};return a.default.createElement(e,M({key:r.name},r))}return a.default.createElement(e,M({key:t.name},t))}addCampaign(){const e=this.getActionRoute(0,"create");this.props.router.navigate(e)}renderDetailEditView(){const{FormBuilderLoaderComponent:e,BreadcrumbComponent:t}=this.props;if(this.props.router.params.id<=0)return this.renderCreateView();const n=this.props.sectionConfig.form.campaignEditForm.schemaUrl,i=(0,I.joinUrlPaths)(n,"/",this.props.router.params.id);return a.default.createElement("div",{className:"fill-height"},a.default.createElement(g.default,{showBackButton:!0,onBackButtonClick:this.handleBackButtonClick},a.default.createElement(t,{multiline:!0})),a.default.createElement(e,{fieldHolder:{className:"panel panel--padded panel--scrollable flexbox-area-grow form--inline"},actionHolder:{className:"toolbar--south"},onAction:this.handleFormAction,schemaUrl:i,identifier:"Campaign.EditView"}))}renderCreateView(){const{FormBuilderLoaderComponent:e,BreadcrumbComponent:t}=this.props,{schemaUrl:n}=this.props.sectionConfig.form.campaignCreateForm;return a.default.createElement("div",{className:"fill-height"},a.default.createElement(g.default,{showBackButton:!0,onBackButtonClick:this.handleBackButtonClick},a.default.createElement(t,{multiline:!0})),a.default.createElement(e,{fieldHolder:{className:"panel panel--padded panel--scrollable flexbox-area-grow form--inline"},actionHolder:{className:"toolbar--south"},onSubmit:this.handleCreateCampaignSubmit,onAction:this.handleFormAction,schemaUrl:n,identifier:"Campaign.CreateView"}))}renderIndexView(){const{showMessage:e,BreadcrumbComponent:t,FormBuilderLoaderComponent:n}=this.props,{schemaUrl:i}=this.props.sectionConfig.form.EditForm,r={title:h.default._t("CampaignAdmin.ADDCAMPAIGN","Add campaign"),icon:"plus",extraClass:"btn-primary",onClick:this.addCampaign},o={createFn:this.campaignListCreateFn.bind(this),schemaUrl:i,identifier:"Campaign.IndexView"};return a.default.createElement("div",{className:"fill-height","aria-expanded":"true"},a.default.createElement(g.default,null,a.default.createElement(t,{multiline:!0})),a.default.createElement("div",{className:"panel panel--scrollable flexbox-area-grow"},a.default.createElement(_.default,{show:e,onClose:this.handleHideMessage}),a.default.createElement("div",{className:"panel panel--padded flexbox-area-grow"},a.default.createElement("div",{className:"toolbar toolbar--content"},a.default.createElement("div",{className:"btn-toolbar fill-width"},a.default.createElement("div",{className:"btn-toolbar__left-panel flexbox-area-grow"},a.default.createElement(f.default,r)),a.default.createElement("div",{className:"btn-toolbar__left-panel"},a.default.createElement("a",{role:"button","aria-label":h.default._t("CampaignAdmin.HELP_SHOW","Show help"),tabIndex:0,onClick:this.handleToggleMessage,className:"btn btn-secondary font-icon-white-question btn--icon-xl btn--no-text"})))),a.default.createElement(n,o))))}renderItemListView(){const{sectionConfig:e,previewState:t,router:{params:{id:n}}}=this.props,{loading:i}=this.state,r={sectionConfig:e,campaignId:n,itemListViewEndpoint:e.itemListViewEndpoint,publishApi:this.publishApi,onBackButtonClick:this.handleBackButtonClick,onRemoveCampaignItem:this.handleRemoveCampaignItem,loading:i,previewState:t};return a.default.createElement(b.default,{style:{position:"relative"},className:"flexbox-area-grow fill-height",onResize:e=>{let{width:t}=e;return this.props.onResize(t)}},a.default.createElement(w.default,r))}render(){let e=null;switch(this.props.router.params.view){case"show":e=this.renderItemListView();break;case"edit":e=this.renderDetailEditView();break;case"create":e=this.renderCreateView();break;default:e=this.renderIndexView()}return e}}t.Component=N,N.propTypes={breadcrumbsActions:i.default.object.isRequired,campaignId:i.default.string,sectionConfig:i.default.shape({publishEndpoint:i.default.shape({url:i.default.string,method:i.default.string}),form:i.default.shape({EditForm:i.default.shape({schemaUrl:i.default.string}),campaignEditForm:i.default.shape({schemaUrl:i.default.string}),campaignCreateForm:i.default.shape({schemaUrl:i.default.string})})}),securityId:i.default.string.isRequired,view:i.default.string,router:E.routerPropTypes,showMessage:i.default.bool,previewState:i.default.oneOf(["edit","preview","split"]),onResize:i.default.func.isRequired,FormBuilderLoaderComponent:i.default.oneOfType([i.default.object,i.default.func]),BreadcrumbComponent:i.default.oneOfType([i.default.object,i.default.func])},N.defaultProps={sectionConfig:{},router:{params:{}},view:"show",breadcrumbs:[],FormBuilderLoaderComponent:C.default,BreadcrumbComponent:p.default};t.default=(0,E.default)((0,r.connect)((function(e,t){let n=null;const a=e.config.sections.find((e=>"SilverStripe\\CampaignAdmin\\CampaignAdmin"===e.name)),i=e.viewMode;if(t.router.params.id>0){const i=`${a.form.campaignEditForm.schemaUrl}/${t.router.params.id}`,r=e.form.formSchemas[i],s=r&&r.name&&(0,o.formValueSelector)(r.name,l.default);n=s&&s(e,"Name")}return{previewState:i.activeState,config:e.config,campaignId:e.campaign.campaignId,view:e.campaign.view,breadcrumbs:e.breadcrumbs,sectionConfig:a,securityId:e.config.SecurityID,title:n,showMessage:e.campaign.showMessage}}),(function(e){return{breadcrumbsActions:(0,s.bindActionCreators)(u,e),campaignActions:(0,s.bindActionCreators)(c,e),recordActions:(0,s.bindActionCreators)(m,e),onResize(t){e(A.enableOrDisableSplitMode(t))}}}))(N))},326:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=d(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,n&&n.set(e,a);return a}(n(363)),i=l(n(754)),r=n(127),o=l(n(742)),s=l(n(86));function l(e){return e&&e.__esModule?e:{default:e}}function d(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(d=function(e){return e?n:t})(e)}class c extends a.Component{getNumReferTo(){const{item:e}=this.props;return e._links&&e._links.references&&e._links.references.length||0}getNumReferredBy(){const{item:e}=this.props;return e._links&&e._links.referenced_by&&e._links.referenced_by.length||0}getReferToTooltipText(){const e=this.getNumReferTo();return i.default.inject(i.default._t("CampaignAdmin.LINKED_TO","Requires {number} item(s)"),{number:(0,o.default)(e)})}getReferredByTooltipText(){const e=this.getNumReferredBy();return i.default.inject(i.default._t("CampaignAdmin.LINKED_FROM","Required by {number} item(s)"),{number:(0,o.default)(e)})}renderLinks(){const{isLinked:e,selected:t,item:{ID:n}}=this.props,s=this.getNumReferTo(),l=this.getNumReferredBy(),d=[];s>0&&d.push(this.getReferToTooltipText()),l>0&&d.push(i.default.sprintf(0===d.length?this.getReferredByTooltipText():this.getReferredByTooltipText().toLocaleLowerCase(),(0,o.default)(l)));let c=null;if(t&&s+l>0||e){const t=["list-group-item__info","campaign-admin__item-links",e?"campaign-admin__item-links--is-linked":"campaign-admin__item-links--has-links"];c=a.default.createElement("div",{className:t.join(" ")},a.default.createElement("span",{id:`campaign-tooltip-${n}`},a.default.createElement("span",{className:"campaign-admin__item-links__number"},s+l),a.default.createElement("span",{className:"font-icon-link"})),a.default.createElement(r.UncontrolledTooltip,{placement:"left",target:`campaign-tooltip-${n}`},d.join(", ")))}return c}render(){let e=null;const t={},{campaign:n,item:r}=this.props;if("open"===n.State)switch(r.ChangeType){case"created":t.className="badge badge-warning list-group-item__status",t.Title=i.default._t("CampaignAdmin.DRAFT","Draft");break;case"modified":t.className="badge badge-warning list-group-item__status",t.Title=i.default._t("CampaignAdmin.MODIFIED","Modified");break;case"deleted":t.className="badge badge-error list-group-item__status",t.Title=i.default._t("CampaignAdmin.REMOVED","Removed");break;default:t.className="badge badge-success list-group-item__status",t.Title=i.default._t("CampaignAdmin.NO_CHANGES","No changes")}const o=this.renderLinks();r.Thumbnail&&(e=a.default.createElement("span",{className:"list-group-item__thumbnail"},a.default.createElement("img",{alt:r.Title,src:r.Thumbnail})));const s=r.Title?r.Title:i.default._t("CampaignAdmin.UNTITLED","Untitled");return a.default.createElement("div",{className:"fill-width"},e,a.default.createElement("div",{className:"list-group-item__details"},a.default.createElement("h4",{className:"list-group-item__heading",title:s},s),o,t.className&&t.Title&&a.default.createElement("span",{className:t.className},t.Title)))}}c.propTypes={campaign:s.default.object.isRequired,item:s.default.object.isRequired,isLinked:s.default.bool,selected:s.default.bool};t.default=c},379:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.Component=void 0;var a=w(n(363)),i=A(n(86)),r=n(827),o=n(624),s=w(n(674)),l=w(n(826)),d=w(n(466)),c=A(n(430)),u=A(n(942)),m=A(n(962)),p=A(n(71)),f=A(n(803)),h=n(127),g=A(n(754)),C=n(648),_=A(n(820)),b=n(845),E=A(n(326));function A(e){return e&&e.__esModule?e:{default:e}}function I(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(I=function(e){return e?n:t})(e)}function w(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=I(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}return a.default=e,n&&n.set(e,a),a}class v extends a.Component{constructor(e){super(e),this.handlePublish=this.handlePublish.bind(this),this.handleItemSelected=this.handleItemSelected.bind(this),this.setBreadcrumbs=this.setBreadcrumbs.bind(this),this.handleCloseItem=this.handleCloseItem.bind(this),this.handleRemoveItem=this.handleRemoveItem.bind(this),this.renderCampaignAdminListDetail=this.renderCampaignAdminListDetail.bind(this),this.isRecordLoaded(e)?this.state={loading:!1,error:!1,errorCode:0}:this.state={loading:!0,error:!1,errorCode:0}}componentDidMount(){const{campaignId:e,itemListViewEndpoint:t,recordActions:n,treeClass:a}=this.props,i=t.url.replace(/:id/,e);this.setBreadcrumbs(),this.isRecordLoaded()||n.fetchRecord(a,"get",i).then((()=>{this.setBreadcrumbs(),this.setState({loading:!1})})).catch((e=>{this.setState({loading:!1,error:!0,errorCode:e.response.status})}))}componentWillUnmount(){this.props.campaignActions.setNewItem(null)}setBreadcrumbs(){const{breadcrumbsActions:e,campaignId:t,record:n,sectionConfig:{reactRoutePath:a}}=this.props;if(!n)return;const i=[{text:g.default._t("CampaignAdmin.CAMPAIGN","Campaigns"),href:(0,b.joinUrlPaths)("/",a)}];i.push({text:n.Name,href:(0,b.joinUrlPaths)("/",a,`set/${t}/show`)}),e.setBreadcrumbs(i)}getSelectedItem(){const{campaign:{changeSetItemId:e}}=this.props,t=this.getItems()||[];let n=null;if(e&&(n=t.find((t=>e===t.ID))),!n){const e=this.groupItemsForSet(),t=Object.keys(e).find((t=>e[t]&&e[t].items.length>0));n=t?e[t].items[0]:null}return n}getMoreActions(){const{DropdownItemComponent:e}=this.props,t=this.getSelectedItem();if(!t)return null;const n=t._links&&t._links.referenced_by,i=n&&n.length||0,r=g.default._t("CampaignAdmin.UNREMOVEABLE_INFO","Required by {number} item(s), and cannot be removed directly.");return["explicitly"===t.Added?a.default.createElement(e,{key:"remove_action",className:"btn btn-secondary action",onClick:this.handleRemoveItem},g.default._t("CampaignAdmin.REMOVE","Remove")):a.default.createElement(e,{tag:"p",key:"unremoveable_info",className:"alert alert-info campaign-admin__unremoveable-item"},a.default.createElement("span",{className:"font-icon-link"}),g.default.inject(r,{number:i}))]}getItems(){const{record:e}=this.props;return e&&e._embedded?e._embedded.items:null}getPlaceholderGroups(){const e={},{record:t}=this.props;return t&&t.placeholderGroups&&t.placeholderGroups.forEach((t=>{e[t.baseClass]={...t},e[t.baseClass].items=[...t.items]})),e}groupItemsForSet(){const e=this.getPlaceholderGroups(),t=this.getItems();return t?(t.forEach((t=>{const n=t.BaseClass;e[n]||(e[n]={singular:t.Singular,plural:t.Plural,items:[]}),e[n].items.push(t)})),e):e}isRecordLoaded(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props;return 0!==Object.keys(e.record).length}handleRemoveItem(){const{campaignId:e,onRemoveCampaignItem:t}=this.props;"function"==typeof t&&t(e,this.getSelectedItem().ID)}handleItemSelected(e,t){this.props.campaignActions.selectChangeSetItem(t)}handleCloseItem(){this.props.campaignActions.selectChangeSetItem(null)}handlePublish(e){const{campaignId:t,campaignActions:{publishCampaign:n},publishApi:a,treeClass:i}=this.props;e.preventDefault();const r=g.default._t("CampaignAdmin.PUBLISH_CAMPAIGN_CONFIRM","Are you sure you want to publish this campaign?");window.confirm(r)&&n(a,i,t)}renderButtonToolbar(){const{ViewModeComponent:e,FormActionComponent:t,record:n,campaign:{isPublishing:i}}=this.props,r=this.getItems(),o=!r||0===r.length;let s=null;return o?s={title:g.default._t("CampaignAdmin.PUBLISHCAMPAIGN","Publish campaign"),buttonStyle:"outline-secondary",icon:"rocket",disabled:!0}:"open"===n.State&&(s={title:g.default._t("CampaignAdmin.PUBLISHCAMPAIGN","Publish campaign"),buttonStyle:"primary",loading:i,onClick:this.handlePublish,icon:"rocket"}),s?a.default.createElement("div",{className:"btn-toolbar"},a.default.createElement(t,s),!o&&a.default.createElement(e,{id:"view-mode-toggle-in-edit-nb",area:"edit"})):null}renderErrorMessage(e){switch(e){case 403:return a.default.createElement("p",null,g.default._t("CampaignAdmin.FORBIDDEN","You do not have access to view this campaign."));case 404:return a.default.createElement("p",null,g.default._t("CampaignAdmin.PAGE_NOT_FOUND","The campaign you are looking for can not be found."));default:return a.default.createElement("p",null,g.default._t("CampaignAdmin.SOMETHING_WENT_WRONG","Something went wrong."))}}renderPreview(e,t){const{PreviewComponent:n,previewState:i,record:{State:r}}=this.props,{loading:o,error:s,errorCode:l}=this.state;let d=["flexbox-area-grow","fill-height","preview","campaign-admin__campaign-preview","campaign-admin__campaign-preview--empty"];switch(i){case"preview":d.push("preview-only");break;case"edit":return null}if(d=(0,_.default)(d),o)return a.default.createElement("div",{className:d},a.default.createElement("p",null,g.default._t("CampaignAdmin.LOADING","Loading...")));if(s)return a.default.createElement("div",{className:d},this.renderErrorMessage(l));if(!this.getItems()||0===this.getItems().length){const e=g.default._t("CampaignAdmin.SELECTFROMSECTIONS",'Select "Add to Campaign" from pages, files, and other admin sections with content types');return a.default.createElement("div",{className:d},a.default.createElement("h2",{className:"campaign-admin__empty-heading"},g.default._t("CampaignAdmin.GETTINGSTARTED","Getting started")),a.default.createElement("p",{className:"campaign-admin__empty-info"},e))}const c={itemLinks:e,itemId:t,onBack:this.handleCloseItem,className:d};return"open"===r&&(c.moreActions=this.getMoreActions()),a.default.createElement(n,c)}renderCampaignAdminListDetail(e){const{previewState:t,onBackButtonClick:n,newItem:i,BreadcrumbComponent:r}=this.props,o=(0,_.default)("panel","panel--padded","panel--scrollable","flexbox-area-grow"),s=i?a.default.createElement("p",{className:"alert alert-success alert--no-border",role:"alert"},g.default._t("CampaignAdmin.NEWCAMPAIGNSUCCESS","Nice one! You have successfully created a campaign.")):null;if("preview"===t)return null;const l=(0,_.default)("fill-height","campaign-admin__campaign-items",{"fill-height":"edit"===t,"campaign-admin__campaign-items-edit":"edit"===t});return a.default.createElement("div",{className:l,"aria-expanded":"true"},a.default.createElement(p.default,{showBackButton:!0,onBackButtonClick:n},a.default.createElement(r,{multiline:!0})),s,a.default.createElement("div",{className:o},e),a.default.createElement("div",{className:"toolbar toolbar--south"},this.renderButtonToolbar()))}render(){const{campaign:{changeSetItemId:e},campaignId:t,record:n}=this.props;let i=e,r=null;const o=i?"":"campaign-admin__campaign--hide-preview",s=this.groupItemsForSet(),l=[],d=this.getSelectedItem(),p=d&&d._links&&d._links.references||[],f=d&&d._links&&d._links.referenced_by||[];Object.keys(s).forEach((e=>{const o=s[e],d=o.items.length,c=[],h=`\n ${0===d?"":d}\n ${1===d?o.singular:o.plural}\n `,g=`Set_${t}_Group_${e}`;o.items.forEach(((e,t)=>{i||(i=e.ID);const o=i===e.ID;o&&e._links&&(r=e._links);const s=(0,_.default)({"list-group-item--inactive":"none"===e.ChangeType||"published"===n.State,active:o});let l=!!p.find((t=>t.ChangeSetItemID===parseInt(e.ID,10)));l=l||f.find((t=>t.ChangeSetItemID===e.ID)),c.push(a.default.createElement(m.default,{key:e.ID||t,className:s,onClick:this.handleItemSelected,onClickArg:e.ID},a.default.createElement(E.default,{item:e,campaign:this.props.record,selected:o,isLinked:l})))}));const C=(0,_.default)("list-group-wrapper",{"list-group-wrapper--empty":0===c.length});l.push(a.default.createElement("div",{className:C,key:g},a.default.createElement(u.default,{groupid:g,title:h},c.length>0?c:a.default.createElement("p",{className:"list-group-item"},o.noItemsText))))}));const h=a.default.createElement(c.default,null,l),g=this.props.loading&&[a.default.createElement("div",{key:"overlay",className:"cms-content-loading-overlay ui-widget-overlay-light"}),a.default.createElement("div",{key:"spinner",className:"cms-content-loading-spinner"})];return a.default.createElement("div",{className:`fill-width campaign-admin__campaign ${o}`},g,this.renderCampaignAdminListDetail(h,r),this.renderPreview(r,i))}}t.Component=v,v.propTypes={campaign:i.default.shape({isPublishing:i.default.bool,changeSetItemId:i.default.number}),publishApi:i.default.func.isRequired,record:i.default.object.isRequired,sectionConfig:i.default.object.isRequired,onBackButtonClick:i.default.func,onRemoveCampaignItem:i.default.func,breadcrumbsActions:i.default.object.isRequired,campaignActions:i.default.object.isRequired,recordActions:i.default.object.isRequired,PreviewComponent:i.default.elementType,ViewModeComponent:i.default.elementType,FormActionComponent:i.default.elementType,previewState:i.default.oneOf(["edit","preview","split"]),BreadcrumbComponent:i.default.oneOfType([i.default.object,i.default.func]),DropdownItemComponent:i.default.oneOfType([i.default.object,i.default.func])},v.defaultProps={BreadcrumbComponent:f.default,DropdownItemComponent:h.DropdownItem};t.default=(0,r.compose)((0,o.connect)((function(e,t){const n=t.sectionConfig.treeClass,a=parseInt(t.campaignId,10),i=(e.records[n]||[]).find((e=>e.ID===a))||{};return{config:e.config,record:i,campaign:e.campaign,treeClass:n,newItem:e.campaign.newItem}}),(function(e){return{breadcrumbsActions:(0,r.bindActionCreators)(s,e),recordActions:(0,r.bindActionCreators)(l,e),campaignActions:(0,r.bindActionCreators)(d,e)}})),(0,C.inject)(["FormAction","ViewModeToggle","Preview"],((e,t,n)=>({FormActionComponent:e,ViewModeComponent:t,PreviewComponent:n})),(()=>"CampaignAdmin.CampaignAdmin.List")))(v)},675:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default={SET_CAMPAIGN_ACTIVE_CHANGESET:"SET_CAMPAIGN_ACTIVE_CHANGESET",SET_CAMPAIGN_SELECTED_CHANGESETITEM:"SET_CAMPAIGN_SELECTED_CHANGESETITEM",PUBLISH_CAMPAIGN_REQUEST:"PUBLISH_CAMPAIGN_REQUEST",PUBLISH_CAMPAIGN_SUCCESS:"PUBLISH_CAMPAIGN_SUCCESS",PUBLISH_CAMPAIGN_FAILURE:"PUBLISH_CAMPAIGN_FAILURE",SET_NEW_CAMPAIGN:"SET_NEW_CAMPAIGN",REMOVE_CAMPAIGN_ITEM_REQUEST:"REMOVE_CAMPAIGN_ITEM_REQUEST",REMOVE_CAMPAIGN_ITEM_SUCCESS:"REMOVE_CAMPAIGN_ITEM_SUCCESS",REMOVE_CAMPAIGN_ITEM_FAILURE:"REMOVE_CAMPAIGN_ITEM_FAILURE",SET_SHOW_MESSAGE:"SET_SHOW_MESSAGE"}},466:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.publishCampaign=function(e,t,n){return s=>{s({type:o.default.PUBLISH_CAMPAIGN_REQUEST,payload:{campaignId:n}}),e({id:n}).then((e=>{s({type:o.default.PUBLISH_CAMPAIGN_SUCCESS,payload:{campaignId:n}}),s({type:a.default.FETCH_RECORD_SUCCESS,payload:{recordType:t,data:e}});const l=r.default._t("CampaignAdmin.PUBLISH_SUCCESS",'Published "%s" successfully.');s(i.success(r.default.sprintf(l,e.Name)))})).catch((e=>{s({type:o.default.PUBLISH_CAMPAIGN_FAILURE,payload:{error:e}});const t="string"==typeof e?e:r.default._t("CampaignAdmin.PUBLISH_FAIL","Campaign could not be published.");s(i.error(t))}))}},t.removeCampaignItem=function(e,t,n){return a=>(a({type:o.default.REMOVE_CAMPAIGN_ITEM_REQUEST,payload:{campaignId:t,itemId:n}}),e({id:t,itemId:n}).then((()=>{a({type:o.default.REMOVE_CAMPAIGN_ITEM_SUCCESS,payload:{campaignId:t,itemId:n}})})).catch((e=>{a({type:o.default.REMOVE_CAMPAIGN_ITEM_FAILURE,payload:{error:e}})})))},t.selectChangeSetItem=function(e){return{type:o.default.SET_CAMPAIGN_SELECTED_CHANGESETITEM,payload:{changeSetItemId:e}}},t.setNewItem=function(e){return{type:o.default.SET_NEW_CAMPAIGN,payload:{newItem:e}}},t.setShowMessage=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.localStorage;return t.setItem("campaign.showMessage",e),{type:o.default.SET_SHOW_MESSAGE,payload:{show:e}}},t.showCampaignView=function(e,t){return n=>{n({type:o.default.SET_CAMPAIGN_ACTIVE_CHANGESET,payload:{campaignId:e,view:t}})}};var a=l(n(852)),i=function(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var n=s(t);if(n&&n.has(e))return n.get(e);var a={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var o=i?Object.getOwnPropertyDescriptor(e,r):null;o&&(o.get||o.set)?Object.defineProperty(a,r,o):a[r]=e[r]}a.default=e,n&&n.set(e,a);return a}(n(123)),r=l(n(754)),o=l(n(675));function s(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,n=new WeakMap;return(s=function(e){return e?n:t})(e)}function l(e){return e&&e.__esModule?e:{default:e}}},277:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=r(n(752)),i=r(n(675));function r(e){return e&&e.__esModule?e:{default:e}}const o=window.localStorage.getItem("campaign.showMessage"),s=(0,a.default)({campaignId:null,changeSetItemId:null,isPublishing:!1,view:null,newItem:null,showMessage:null===o});t.default=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s,t=arguments.length>1?arguments[1]:void 0;switch(t.type){case i.default.SET_CAMPAIGN_SELECTED_CHANGESETITEM:return(0,a.default)(Object.assign({},e,{changeSetItemId:t.payload.changeSetItemId}));case i.default.SET_CAMPAIGN_ACTIVE_CHANGESET:return(0,a.default)(Object.assign({},e,{campaignId:t.payload.campaignId,view:t.payload.view,changeSetItemId:null}));case i.default.PUBLISH_CAMPAIGN_REQUEST:return(0,a.default)(Object.assign({},e,{isPublishing:!0}));case i.default.PUBLISH_CAMPAIGN_SUCCESS:case i.default.PUBLISH_CAMPAIGN_FAILURE:return(0,a.default)(Object.assign({},e,{isPublishing:!1}));case i.default.SET_NEW_CAMPAIGN:return(0,a.default)({...e,newItem:t.payload.newItem});case i.default.SET_SHOW_MESSAGE:return(0,a.default)({...e,showMessage:t.payload.show});default:return e}}},430:function(e){e.exports=Accordion},942:function(e){e.exports=AccordionBlock},159:function(e){e.exports=Backend},803:function(e){e.exports=Breadcrumb},674:function(e){e.exports=BreadcrumbsActions},510:function(e){e.exports=Config},752:function(e){e.exports=DeepFreezeStrict},13:function(e){e.exports=FormAction},238:function(e){e.exports=FormBuilderLoader},648:function(e){e.exports=Injector},962:function(e){e.exports=ListGroupItem},86:function(e){e.exports=PropTypes},363:function(e){e.exports=React},624:function(e){e.exports=ReactRedux},873:function(e){e.exports=ReactRouteRegister},127:function(e){e.exports=Reactstrap},852:function(e){e.exports=RecordsActionTypes},826:function(e){e.exports=RecordsActions},827:function(e){e.exports=Redux},762:function(e){e.exports=ReduxForm},104:function(e){e.exports=ResizeAware},123:function(e){e.exports=ToastsActions},71:function(e){e.exports=Toolbar},108:function(e){e.exports=ViewModeActions},820:function(e){e.exports=classnames},742:function(e){e.exports=formatWrittenNumber},720:function(e){e.exports=getFormState},754:function(e){e.exports=i18n},845:function(e){e.exports=ssUrlLib},432:function(e){e.exports=withRouter}},t={};function n(a){var i=t[a];if(void 0!==i)return i.exports;var r=t[a]={exports:{}};return e[a](r,r.exports,n),r.exports}n(274)}(); \ No newline at end of file diff --git a/client/src/containers/CampaignAdmin/CampaignAdminList.js b/client/src/containers/CampaignAdmin/CampaignAdminList.js index 261b8313..7af6619a 100644 --- a/client/src/containers/CampaignAdmin/CampaignAdminList.js +++ b/client/src/containers/CampaignAdmin/CampaignAdminList.js @@ -327,7 +327,7 @@ class CampaignAdminList extends Component { } renderPreview(itemLinks, itemId) { - const { PreviewComponent, previewState } = this.props; + const { PreviewComponent, previewState, record: { State } } = this.props; const { loading, error, errorCode } = this.state; let previewClasses = [ @@ -384,16 +384,16 @@ class CampaignAdminList extends Component { ); } - - return ( - - ); + const props = { + itemLinks, + itemId, + onBack: this.handleCloseItem, + className: previewClasses, + }; + if (State === 'open') { + props.moreActions = this.getMoreActions(); + } + return ; } /** diff --git a/client/src/containers/CampaignAdmin/tests/CampaignAdminList-test.js b/client/src/containers/CampaignAdmin/tests/CampaignAdminList-test.js index a11f356b..be55eb40 100644 --- a/client/src/containers/CampaignAdmin/tests/CampaignAdminList-test.js +++ b/client/src/containers/CampaignAdmin/tests/CampaignAdminList-test.js @@ -12,6 +12,7 @@ function makeProps(obj = {}) { itemListViewEndpoint: { url: '', method: 'POST' }, record: { ID: 3, + State: 'open', placeholderGroups: [ { baseClass: 'SilverStripe\\CMS\\Model\\SiteTree', diff --git a/src/CampaignAdmin.php b/src/CampaignAdmin.php index 49cd63ce..51f693a5 100644 --- a/src/CampaignAdmin.php +++ b/src/CampaignAdmin.php @@ -497,6 +497,9 @@ public function removeCampaignItem(HTTPRequest $request) return (new HTTPResponse(null, 404)); } + if ($campaign->State !== ChangeSet::STATE_OPEN) { + return (new HTTPResponse(null, 400)); + } $campaign->removeObject($item->Object()); diff --git a/tests/behat/features/manage-campaigns.feature b/tests/behat/features/manage-campaigns.feature index a8a9ee96..c3a31156 100644 --- a/tests/behat/features/manage-campaigns.feature +++ b/tests/behat/features/manage-campaigns.feature @@ -76,6 +76,8 @@ Feature: Manage campaigns And I click on the ".grid-field__cell--drillable" element And I press the "Publish campaign" button And I confirm the dialog + And I should not see the "Publish campaign" button + And I should not see an "#tab-ActionMenus_MoreOptions" element When I go to "/admin/pages" Then the rendered HTML should not contain "badge status-addedtodraft" diff --git a/tests/php/CampaignAdminTest.php b/tests/php/CampaignAdminTest.php index 11145ee5..e092c8e5 100644 --- a/tests/php/CampaignAdminTest.php +++ b/tests/php/CampaignAdminTest.php @@ -4,6 +4,7 @@ use ReflectionClass; use SilverStripe\CampaignAdmin\CampaignAdmin; +use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; use SilverStripe\Dev\FunctionalTest; @@ -13,6 +14,7 @@ use SilverStripe\Security\Member; use SilverStripe\Security\Permission; use SilverStripe\Versioned\ChangeSet; +use SilverStripe\Versioned\ChangeSetItem; class CampaignAdminTest extends FunctionalTest { @@ -159,4 +161,38 @@ public function testReadCampaign( $response = $this->get("/admin/campaigns/set/$changeSetID/show", null, ['Accept' => 'application/json']); $this->assertEquals($expectedResponseCode, $response->getStatusCode()); } + + public function provideRemoveCampaignItem(): array + { + return [ + 'open campaign' => [false, false, 204], + 'published campaign' => [true, false, 400], + 'incorrect campaign ID' => [true, true, 404], + ]; + } + + /** + * @dataProvider provideRemoveCampaignItem + */ + public function testRemoveCampaignItem( + bool $isPublished, + bool $isWrongID, + int $expectedResponseCode, + ): void { + $item = new SiteTree(); + $item->write(); + $changeset = new ChangeSet(); + $changeset->write(); + $changeset->addObject($item); + + if ($isPublished) { + $changeset->publish(); + } + + $changesetitemID = ChangeSetItem::get()->where(['"ChangeSetID" = ?' => $changeset->ID])->first()->ID; + $changesetID = $isWrongID ? 12345 : $changeset->ID; + + $response = $this->post("/admin/campaigns/removeCampaignItem/$changesetID/$changesetitemID", null); + $this->assertEquals($expectedResponseCode, $response->getStatusCode()); + } }