Skip to content

Commit

Permalink
Added new dialog for adding list elements through the ADE menu.
Browse files Browse the repository at this point in the history
This feature is enabled for a container element by using a new tag, <cms:enable-list-add>, in the formatter for the element.
  • Loading branch information
gWestenberger committed Jan 11, 2023
1 parent c6cf9b1 commit b7b381c
Show file tree
Hide file tree
Showing 23 changed files with 1,149 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ GUI_TITLE_MODEL_0=Template
GUI_ADDINFO_SCHEMA_0=Schema
GUI_ADDINFO_FORMATTER_0=Formatter
GUI_ADDINFO_FORMATTER_KEY_0=Schlüssel
GUI_ADDINFO_FORMATTER_LOCATION_0=Konfiguration
GUI_ADDINFO_FORMATTER_LOCATION_0=Konfiguration
GUI_LISTADD_CAPTION_0=Wählen Sie den anzulegenden Inhaltstyp aus
GUI_LISTADD_NO_TYPES_0=Es sind keine Inhaltstypen zum Anlegen verfügbar.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opencms.ade.containerpage.client.ui.CmsToolbarFavLocationButton;
import org.opencms.ade.containerpage.client.ui.CmsToolbarGalleryMenu;
import org.opencms.ade.containerpage.client.ui.CmsToolbarInfoButton;
import org.opencms.ade.containerpage.client.ui.CmsToolbarListAddButton;
import org.opencms.ade.containerpage.client.ui.CmsToolbarListManagerButton;
import org.opencms.ade.containerpage.client.ui.CmsToolbarMoveButton;
import org.opencms.ade.containerpage.client.ui.CmsToolbarPublishButton;
Expand Down Expand Up @@ -301,8 +302,10 @@ public void onModuleLoad() {

I_CmsLayoutBundle.INSTANCE.containerpageCss().ensureInjected();
I_CmsLayoutBundle.INSTANCE.dragdropCss().ensureInjected();

I_CmsLayoutBundle.INSTANCE.groupcontainerCss().ensureInjected();
org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.elementSettingsDialogCss().ensureInjected();
org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.listAddCss().ensureInjected();

final CmsContainerpageController controller = new CmsContainerpageController();
final CmsContainerpageHandler containerpageHandler = new CmsContainerpageHandler(controller, this);
Expand Down Expand Up @@ -400,6 +403,7 @@ public void onClose(CloseEvent<Window> event) {
m_edit,
m_move,
new CmsToolbarListManagerButton(containerpageHandler),
new CmsToolbarListAddButton(containerpageHandler),
m_info,
m_properties,
m_addToFavorites,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.opencms.ade.containerpage.client.ui.CmsElementSettingsDialog;
import org.opencms.ade.containerpage.client.ui.CmsElementSettingsDialog.NoFormatterException;
import org.opencms.ade.containerpage.client.ui.CmsGroupContainerElementPanel;
import org.opencms.ade.containerpage.client.ui.CmsListAddDialog;
import org.opencms.ade.containerpage.client.ui.CmsSmallElementsHandler;
import org.opencms.ade.containerpage.client.ui.I_CmsDropContainer;
import org.opencms.ade.containerpage.shared.CmsContainerElement;
Expand All @@ -43,6 +44,7 @@
import org.opencms.ade.publish.client.CmsPublishDialog;
import org.opencms.ade.publish.shared.CmsPublishOptions;
import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.I_CmsEditableData;
import org.opencms.gwt.client.dnd.I_CmsDNDController;
import org.opencms.gwt.client.rpc.CmsRpcAction;
import org.opencms.gwt.client.ui.A_CmsToolbarHandler;
Expand Down Expand Up @@ -79,9 +81,12 @@
import org.opencms.gwt.shared.CmsCoreData;
import org.opencms.gwt.shared.CmsCoreData.AdeContext;
import org.opencms.gwt.shared.CmsGwtConstants;
import org.opencms.gwt.shared.CmsListElementCreationDialogData;
import org.opencms.gwt.shared.CmsListElementCreationOption;
import org.opencms.gwt.shared.CmsLockInfo;
import org.opencms.gwt.shared.CmsModelResourceInfo;
import org.opencms.gwt.shared.CmsTemplateContextInfo;
import org.opencms.gwt.shared.I_CmsEditableDataExtensions;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;

Expand Down Expand Up @@ -788,6 +793,110 @@ public void openEditorForElement(final CmsContainerPageElementPanel element, boo
}
}

/**
* Triggers creation/editing of a new content after an option has been selected.
*
* @param option the type option selected by the user
* @param reloadId the id of the element to be reloaded after editing
* @param postCreateHandler the post-create handler (for assigning categories or similar)
*/
public void openEditorForNewListContent(
CmsListElementCreationOption option,
String reloadId,
String postCreateHandler) {

I_CmsEditableData editableData = new I_CmsEditableData() {

public String getContextId() {

return null;
}

public String getEditId() {

return null;
}

public String getElementId() {

return null;
}

public String getElementLanguage() {

return null;
}

public String getElementName() {

return null;
}

public I_CmsEditableDataExtensions getExtensions() {

return null;
}

public String getNewLink() {

return option.getNewLink();
}

public String getNewTitle() {

return null;
}

public String getNoEditReason() {

return null;
}

public String getPostCreateHandler() {

return postCreateHandler;
}

public String getSitePath() {

return null;
}

public CmsUUID getStructureId() {

return CmsCoreProvider.get().getStructureId();
}

public boolean hasEditHandler() {

return false;
}

public boolean hasResource() {

return false;
}

public boolean isUnreleasedOrExpired() {

return false;
}

public void setSitePath(String sitePath) {

// no-op

}
};

CmsContainerpageController.get().getContentEditorHandler().openDialog(
editableData,
true/*isNew*/,
reloadId /*dependingElementId*/,
null /*mode*/,
null /*handlerData*/);
}

/**
* Opens the elements info dialog.<p>
*/
Expand All @@ -809,6 +918,51 @@ public void onClose(CloseEvent<PopupPanel> event) {
});
}

/**
* Opens the dialog for adding a new list content.
*
* @param structureId the structure id of the container element
* @param listAddMetadata the list-add metadata read from the container element
*/
public void openListAddDialog(CmsUUID structureId, String listAddMetadata) {

CmsRpcAction<CmsListElementCreationDialogData> action = new CmsRpcAction<CmsListElementCreationDialogData>() {

@Override
public void execute() {

start(0, false);
CmsContainerpageHandler.this.m_controller.getContainerpageService().getListElementCreationOptions(
structureId,
listAddMetadata,
this);

}

@Override
protected void onResponse(CmsListElementCreationDialogData result) {

stop(false);
// "0 options" case is handled by the dialog
if (result.getOptions().size() == 1) {
// skip the selection dialog, immediately create and edit the content
openEditorForNewListContent(
result.getOptions().get(0),
"" + structureId,
result.getPostCreateHandler());
} else {
CmsListAddDialog dialog = new CmsListAddDialog(
structureId,
result,
option -> openEditorForNewListContent(option, "" + structureId, result.getPostCreateHandler()));
dialog.centerHorizontally(100);
}
}
};
action.execute();

}

/**
* Opens the lock report for the given element.<p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ private boolean tryParseSingleClass(String token) {
/** The former copy model property. */
public static final String PROP_WAS_MODEL_GROUP = "was_model_group";

/** Property used to mark an element as belonging to this widget. */
public static final String PROP_ELEMENT_OBJECT_ID = "element_object_id";

/** Highlighting border for this element. */
protected CmsHighlightingBorder m_highlighting;

Expand Down Expand Up @@ -277,6 +280,9 @@ private boolean tryParseSingleClass(String token) {
**/
private boolean m_writePermission;

/** A random id, which is also stored as a property on the HTML element for this widget. */
private String m_objectId;

/** The resource type icon CSS classes. */
private String m_iconClasses;

Expand Down Expand Up @@ -329,6 +335,7 @@ public CmsContainerPageElementPanel(

super(element);
m_clientId = clientId;
m_objectId = "" + Math.random();
m_sitePath = sitePath;
m_title = title;
m_subTitle = subTitle;
Expand All @@ -347,6 +354,7 @@ public CmsContainerPageElementPanel(
m_elementView = elementView;
getElement().setPropertyBoolean(PROP_IS_MODEL_GROUP, modelGroupId != null);
getElement().setPropertyBoolean(PROP_WAS_MODEL_GROUP, wasModelGroup);
getElement().setPropertyString(PROP_ELEMENT_OBJECT_ID, m_objectId);
m_iconClasses = iconClasses;
}

Expand Down Expand Up @@ -514,6 +522,18 @@ public String getNoEditReason() {
return m_noEditReason;
}

/**
* Gets the random id identifying this widget.
*
* <p>The id is also stored in the element_object_id property of the DOM element for this widget.
*
* @return the random id identifying this widget
*/
public String getObjectId() {

return m_objectId;
}

/**
* @see org.opencms.gwt.client.dnd.I_CmsDraggable#getParentTarget()
*/
Expand Down
105 changes: 105 additions & 0 deletions src-gwt/org/opencms/ade/containerpage/client/ui/CmsListAddDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package org.opencms.ade.containerpage.client.ui;

import org.opencms.ade.containerpage.client.Messages;
import org.opencms.gwt.client.ui.CmsListItem;
import org.opencms.gwt.client.ui.CmsListItemWidget;
import org.opencms.gwt.client.ui.CmsPopup;
import org.opencms.gwt.client.ui.CmsPushButton;
import org.opencms.gwt.client.ui.I_CmsButton;
import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
import org.opencms.gwt.client.ui.I_CmsButton.Size;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import org.opencms.gwt.shared.CmsListElementCreationDialogData;
import org.opencms.gwt.shared.CmsListElementCreationOption;
import org.opencms.gwt.shared.CmsListInfoBean;
import org.opencms.util.CmsUUID;

import java.util.function.Consumer;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;

/**
* Dialog that allows the user to choose the resource type of a new content to be created.
*/
public class CmsListAddDialog extends CmsPopup {

/**
* Creates a new instance.
*
* @param elementId the container element id
* @param listAddData the data about the creatable resource types
* @param optionHandler the handler to call with the selected option
*/
public CmsListAddDialog(
CmsUUID elementId,
CmsListElementCreationDialogData listAddData,
Consumer<CmsListElementCreationOption> optionHandler) {

super();
setCaption(listAddData.getCaption());
CmsPushButton cancel = new CmsPushButton();
cancel.setUseMinWidth(true);
cancel.setText(Messages.get().key(Messages.GUI_BUTTON_CANCEL_TEXT_0));
cancel.addClickHandler(event -> CmsListAddDialog.this.hide());
addButton(cancel);
CmsListItemWidget listConfigInfoWidget = new CmsListItemWidget(listAddData.getListInfo());
add(listConfigInfoWidget);
if (listAddData.getOptions().size() == 0) {
FlowPanel labelContainer = new FlowPanel();
labelContainer.addStyleName(I_CmsLayoutBundle.INSTANCE.listAddCss().labelContainer());
Label label = new Label(listAddData.getMessage());
labelContainer.add(label);
add(labelContainer);
} else {
final FlowPanel optionContainer = new FlowPanel();
add(optionContainer);

optionContainer.addStyleName(I_CmsLayoutBundle.INSTANCE.listAddCss().optionContainer());

listAddData.getOptions().stream().forEach(option -> {
CmsListInfoBean listInfo = option.getInfo();
CmsListItemWidget itemWidget = new CmsListItemWidget(listInfo);
CmsPushButton plusButton = new CmsPushButton();
plusButton.setImageClass(I_CmsButton.ADD_SMALL);
plusButton.setButtonStyle(ButtonStyle.FONT_ICON, null);
plusButton.setSize(Size.big);
plusButton.addClickHandler(event -> {
CmsListAddDialog.this.hide();
optionHandler.accept(option);
});
itemWidget.getButtonPanel().add(plusButton);
CmsListItem item = new CmsListItem(itemWidget);
optionContainer.add(item);
});
}
}

}
Loading

0 comments on commit b7b381c

Please sign in to comment.