Adds some localization strings
Refactored and reimplemented IndexItemSelectionForm git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4558 8810af33-2d31-482b-a856-94f89814c4df
parent
ecb3a5c2ab
commit
d64f8c5b30
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 com.arsdigita.cms.ui.category;
|
||||
|
||||
import com.arsdigita.bebop.*;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.RadioGroup;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.parameters.ParameterData;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
|
||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ui.CMSForm;
|
||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.categorization.Categorization;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryManager;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.CcmObject;
|
||||
import org.librecms.contentsection.*;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
import org.librecms.dispatcher.ItemResolver;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Allows the user to select an index item to display when the front end user is
|
||||
* browsing by Category
|
||||
*
|
||||
* @author Randy Graebner (randyg@alum.mit.edu)
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
+ */
|
||||
public class IndexItemSelectionForm extends CMSForm {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CategoryEditForm.class);
|
||||
|
||||
private final CategoryRequestLocal m_category;
|
||||
private RadioGroup m_options;
|
||||
private static final String NULL_OPTION_VALUE = "";
|
||||
private static final String NONE_OPTION_VALUE = "None";
|
||||
|
||||
private FormErrorDisplay m_errors;
|
||||
private SaveCancelSection m_saveCancelSection;
|
||||
|
||||
public IndexItemSelectionForm(CategoryRequestLocal m) {
|
||||
super("EditCategory");
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentSectionManager sectionManager =
|
||||
cdiUtil.findBean(ContentSectionManager.class);
|
||||
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
|
||||
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
|
||||
final ContentItemManager contentItemManager = cdiUtil.findBean(ContentItemManager.class);
|
||||
final ContentItemRepository contentItemRepository = cdiUtil.findBean(ContentItemRepository.class);
|
||||
|
||||
setMethod(Form.POST);
|
||||
|
||||
m_category = m;
|
||||
|
||||
// Form header
|
||||
Label header = new Label(GlobalizationUtil.globalize("cms.ui.category.select_index_item"));
|
||||
header.setFontWeight(Label.BOLD);
|
||||
add(header, ColumnPanel.FULL_WIDTH);
|
||||
|
||||
// Form errors
|
||||
m_errors = new FormErrorDisplay(this);
|
||||
add(m_errors, ColumnPanel.FULL_WIDTH);
|
||||
|
||||
// Option Group
|
||||
m_options = new RadioGroup(new StringParameter("items"));
|
||||
try {
|
||||
m_options.addPrintListener(event -> {
|
||||
RadioGroup group = (RadioGroup) event.getTarget();
|
||||
PageState state = event.getPageState();
|
||||
Category category = getCategory(event.getPageState());
|
||||
java.util.List<Categorization> children = category.getObjects();
|
||||
|
||||
group.clearOptions();
|
||||
|
||||
// option for NO index Object
|
||||
group.addOption(new Option(NONE_OPTION_VALUE,
|
||||
new Label(GlobalizationUtil.globalize("cms.ui.category.non_option"))));
|
||||
|
||||
// option for inheriting from the parent category
|
||||
if (category.getParentCategory() != null) {
|
||||
group.addOption(new Option(NULL_OPTION_VALUE,
|
||||
new Label(GlobalizationUtil.globalize("cms.ui.category.inherit_parent"))));
|
||||
}
|
||||
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
final ItemResolver itemResolver = sectionManager.getItemResolver(
|
||||
section);
|
||||
for (Categorization child : children) {
|
||||
ContentItem item = (ContentItem) child.getCategorizedObject();
|
||||
Link link = new Link(
|
||||
item.getDisplayName(),
|
||||
itemResolver.generateItemURL(
|
||||
state,
|
||||
item.getObjectId(),
|
||||
item.getDisplayName(),
|
||||
section,
|
||||
item.getVersion().name()
|
||||
)
|
||||
);
|
||||
Component linkComponent = link;
|
||||
//add the option with the link
|
||||
group.addOption(new Option(item.getItemUuid(), //TODO
|
||||
linkComponent));
|
||||
}
|
||||
|
||||
// get currently selected item
|
||||
Optional<CcmObject> optionalIndexObject = categoryManager.getIndexObject(category);
|
||||
if (optionalIndexObject.isPresent()) {
|
||||
ContentItem indexItem = (ContentItem) optionalIndexObject.get();
|
||||
group.setValue(
|
||||
state,
|
||||
contentItemManager.getDraftVersion(indexItem, ContentItem.class).getItemUuid()
|
||||
);
|
||||
} else {
|
||||
String value = category.getParentCategory() != null
|
||||
? NULL_OPTION_VALUE
|
||||
: NONE_OPTION_VALUE;
|
||||
group.setValue(state, value);
|
||||
}
|
||||
});
|
||||
} catch (java.util.TooManyListenersException e) {
|
||||
LOGGER.error("Error adding init listener to Radio Group", e);
|
||||
throw new UncheckedWrapperException(e);
|
||||
}
|
||||
m_options.setLayout(RadioGroup.VERTICAL);
|
||||
add(m_options);
|
||||
|
||||
// Save and cancel buttons
|
||||
m_saveCancelSection = new SaveCancelSection();
|
||||
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||
|
||||
addSubmissionListener(new FormSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES));
|
||||
|
||||
// Process listener
|
||||
addProcessListener(new FormProcessListener() {
|
||||
public void process(FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
PageState state = event.getPageState();
|
||||
FormData data = event.getFormData();
|
||||
ParameterData param = data.getParameter(m_options.getParameterModel().getName());
|
||||
String selectedValue = (String) param.getValue();
|
||||
|
||||
Category category
|
||||
= getCategory(event.getPageState());
|
||||
|
||||
if (selectedValue != null) {
|
||||
Optional<ContentItem> optionalItem = contentItemRepository.findById(Long.parseLong(selectedValue));
|
||||
if (optionalItem.isPresent()) {
|
||||
ContentItem item = contentItemManager.getDraftVersion(optionalItem.get(), ContentItem.class);
|
||||
//category.setIndexObject(item); TODO
|
||||
categoryRepository.save(category);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cancel button.
|
||||
*
|
||||
* @return The cancel button
|
||||
*/
|
||||
protected Submit getCancelButton() {
|
||||
return m_saveCancelSection.getCancelButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the selected category.
|
||||
*
|
||||
* @param state The page state
|
||||
* @return The selected category
|
||||
* @pre ( state != null )
|
||||
*/
|
||||
protected Category getCategory(PageState state) {
|
||||
Category category = m_category.getCategory(state);
|
||||
Assert.exists(category);
|
||||
return category;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,222 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 com.arsdigita.cms.ui.category;
|
||||
|
||||
import com.arsdigita.bebop.ColumnPanel;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.Link;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.RadioGroup;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.parameters.ParameterData;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.categorization.Category;
|
||||
import com.arsdigita.categorization.CategorizedCollection;
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
import com.arsdigita.cms.SecurityManager;
|
||||
import com.arsdigita.cms.dispatcher.ItemResolver;
|
||||
import com.arsdigita.cms.ui.CMSForm;
|
||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||
import com.arsdigita.kernel.ACSObject;
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Allows the user to select an index item to display when the front end user is
|
||||
* browsing by Category
|
||||
*
|
||||
* @author Randy Graebner (randyg@alum.mit.edu)
|
||||
* @version $Revision: #18 $ $DateTime: 2004/08/17 23:15:09 $
|
||||
*/
|
||||
public class IndexItemSelectionForm extends CMSForm {
|
||||
|
||||
private static org.apache.log4j.Logger s_log
|
||||
= org.apache.log4j.Logger.getLogger(
|
||||
IndexItemSelectionForm.class);
|
||||
private final CategoryRequestLocal m_category;
|
||||
private RadioGroup m_options;
|
||||
private static final String NULL_OPTION_VALUE = "";
|
||||
private static final String NONE_OPTION_VALUE = "None";
|
||||
private FormErrorDisplay m_errors;
|
||||
private SaveCancelSection m_saveCancelSection;
|
||||
|
||||
public IndexItemSelectionForm(CategoryRequestLocal m) {
|
||||
super("EditCategory");
|
||||
setMethod(Form.POST);
|
||||
|
||||
m_category = m;
|
||||
|
||||
// Form header
|
||||
Label header = new Label(GlobalizationUtil.globalize("cms.ui.category.select_index_item"));
|
||||
header.setFontWeight(Label.BOLD);
|
||||
add(header, ColumnPanel.FULL_WIDTH);
|
||||
|
||||
// Form errors
|
||||
m_errors = new FormErrorDisplay(this);
|
||||
add(m_errors, ColumnPanel.FULL_WIDTH);
|
||||
|
||||
// Option Group
|
||||
m_options = new RadioGroup(new StringParameter("items"));
|
||||
try {
|
||||
m_options.addPrintListener(new PrintListener() {
|
||||
public void prepare(PrintEvent event) {
|
||||
RadioGroup group = (RadioGroup) event.getTarget();
|
||||
PageState state = event.getPageState();
|
||||
Category category = getCategory(event.getPageState());
|
||||
CategorizedCollection children = category.getObjects(
|
||||
ContentItem.BASE_DATA_OBJECT_TYPE);
|
||||
|
||||
group.clearOptions();
|
||||
|
||||
// option for NO index Object
|
||||
group.addOption(new Option(NONE_OPTION_VALUE,
|
||||
new Label(NONE_OPTION_VALUE)));
|
||||
|
||||
// option for inheriting from the parent category
|
||||
if (category.getParentCategoryCount() > 0) {
|
||||
group.addOption(new Option(NULL_OPTION_VALUE,
|
||||
new Label("Inherit Index from Parent Category")));
|
||||
}
|
||||
|
||||
while (children.next()) {
|
||||
ACSObject item
|
||||
= (ACSObject) children.getDomainObject();
|
||||
|
||||
if ((item instanceof ContentItem) && ((ContentItem) item).getVersion().
|
||||
equals(ContentItem.DRAFT)) {
|
||||
|
||||
//create a link to the item:
|
||||
ContentBundle bundleItem = (ContentBundle) item;
|
||||
ContentSection section = bundleItem.getContentSection();
|
||||
ItemResolver resolver = section.getItemResolver();
|
||||
|
||||
Link link = new Link(
|
||||
bundleItem.getDisplayName(),
|
||||
resolver.generateItemURL(state,
|
||||
((ContentBundle) bundleItem.getDraftVersion()).getPrimaryInstance(),
|
||||
section,
|
||||
((ContentBundle) bundleItem.getDraftVersion()).getPrimaryInstance().getVersion()));
|
||||
Component linkComponent = link;
|
||||
//add the option with the link
|
||||
group.addOption(new Option(item.getID().toString(),
|
||||
linkComponent));
|
||||
}
|
||||
}
|
||||
// get currently selected item
|
||||
ACSObject indexItem = category.getDirectIndexObject();
|
||||
if (indexItem != null && indexItem instanceof ContentItem) {
|
||||
group.setValue(state, ((ContentItem) indexItem)
|
||||
.getWorkingVersion()
|
||||
.getID().toString());
|
||||
} else {
|
||||
String value = NONE_OPTION_VALUE;
|
||||
if (!category.ignoreParentIndexItem()
|
||||
&& category.getParentCategoryCount() > 0) {
|
||||
value = NULL_OPTION_VALUE;
|
||||
}
|
||||
group.setValue(state, value);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
} catch (java.util.TooManyListenersException e) {
|
||||
s_log.error("Error adding init listener to Radio Group", e);
|
||||
throw new UncheckedWrapperException(e);
|
||||
}
|
||||
m_options.setLayout(RadioGroup.VERTICAL);
|
||||
add(m_options);
|
||||
|
||||
// Save and cancel buttons
|
||||
m_saveCancelSection = new SaveCancelSection();
|
||||
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||
|
||||
addSubmissionListener(new FormSecurityListener(SecurityManager.CATEGORY_ADMIN));
|
||||
|
||||
// Process listener
|
||||
addProcessListener(new FormProcessListener() {
|
||||
public void process(FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
PageState state = event.getPageState();
|
||||
FormData data = event.getFormData();
|
||||
ParameterData param = data.getParameter(m_options.getParameterModel().getName());
|
||||
String selectedValue = (String) param.getValue();
|
||||
|
||||
Category category
|
||||
= getCategory(event.getPageState());
|
||||
|
||||
ContentItem item = null;
|
||||
if (selectedValue != null) {
|
||||
if (NULL_OPTION_VALUE.equals(selectedValue)) {
|
||||
category.setIgnoreParentIndexItem(false);
|
||||
selectedValue = null;
|
||||
} else if (NONE_OPTION_VALUE.equals(selectedValue)) {
|
||||
category.setIgnoreParentIndexItem(true);
|
||||
selectedValue = null;
|
||||
|
||||
} else {
|
||||
item = new ContentItem(new BigDecimal(selectedValue));
|
||||
item = item.getWorkingVersion();
|
||||
}
|
||||
}
|
||||
category.setIndexObject(item);
|
||||
category.save();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cancel button.
|
||||
*
|
||||
* @return The cancel button
|
||||
*/
|
||||
protected Submit getCancelButton() {
|
||||
return m_saveCancelSection.getCancelButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the selected category.
|
||||
*
|
||||
* @param state The page state
|
||||
* @return The selected category
|
||||
* @pre ( state != null )
|
||||
*/
|
||||
protected Category getCategory(PageState state) {
|
||||
Category category = m_category.getCategory(state);
|
||||
Assert.exists(category);
|
||||
return category;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -44,10 +44,8 @@ import javax.servlet.ServletException;
|
|||
* "up" arrow n/2 times where n is the number of items in the list.
|
||||
* This clearly is not a good setup.
|
||||
*
|
||||
|
||||
* @author Randy Graebner (randyg@alum.mit.edu)
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
|
||||
*/
|
||||
abstract class SortableCategoryList extends SortableList {
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
* The item resolver would be asked to map the URL stub {@code /cheese} in the
|
||||
* content section mounted at {@code /cms} to a content item. To this end, the
|
||||
* dispatcher calls the {@link #getItem} method, passing in the
|
||||
* {@link com.arsdigita.cms.ContentSection} and the URL stub for the item within
|
||||
* {@link ContentSection} and the URL stub for the item within
|
||||
* the section, {@code /cheese} in our example. As a final argument, the
|
||||
* dispatcher passes either {@link ContentItemVersion#DRAFT} or
|
||||
* {@link ContentItemVersion#LIVE} to the {@code ItemResolver}, depending on
|
||||
|
|
@ -92,9 +92,9 @@ public interface ItemResolver {
|
|||
/**
|
||||
* Generates a URL for a content item.
|
||||
*
|
||||
* @param state The page state
|
||||
* @param itemId The item ID
|
||||
* @param name The name of the content page
|
||||
* @param state The page state
|
||||
* @param section the content section to which the item belongs
|
||||
* @param context the context of the URL, such as "live" or "admin"
|
||||
*
|
||||
|
|
|
|||
|
|
@ -41,3 +41,7 @@ cms.ui.folder_browser=Folders
|
|||
cms.ui.permissions.table.actions.remove_all=Remove all permissions
|
||||
cms.ui.permissions.table.actions.remove_all.confirm=Are you sure to remove all permissions for this role from the current object?
|
||||
cms.ui.permissions.table.remove_all.header=Remove all
|
||||
|
||||
cms.ui.category.select_index_item=Select index item for category
|
||||
cms.ui.category.non_option=None
|
||||
cms.ui.category.inherit_parent=Inherit Index from Parent Category
|
||||
|
|
@ -41,3 +41,6 @@ cms.ui.folder_browser=Ordner
|
|||
cms.ui.permissions.table.actions.remove_all=Alle Berechtigungen entfernen
|
||||
cms.ui.permissions.table.actions.remove_all.confirm=Sind Sie sicher, dass Sie alle Berechtigungen f\u00fcr diese Rolle von dem aktuellen Objekt entfernen wollen?
|
||||
cms.ui.permissions.table.remove_all.header=Alle entfernen
|
||||
|
||||
cms.ui.category.select_index_item=Index Element f\u00fcr diese Kategorie ausw\u00e4hlen
|
||||
cms.ui.category.inherit_parent=Inherit Index from Parent Category
|
||||
|
|
@ -16,6 +16,9 @@ cms.ui.admin_center=Admin Center
|
|||
cms.ui.contentcenter.section_hint=All documents are organized in one or more contect sections. Each content section may have its own system of permission and its own administrators, independent from each other. Select a section where you will edit a document or create a new one.
|
||||
cms.ui.contentcenter.location=Location
|
||||
cms.ui.contentcenter.location_hint=In Legacy mode links to public pages.
|
||||
cms.ui.category.select_index_item=S\u00e9lectionnez la page d'accueil de la rubrique
|
||||
cms.ui.category.non_option=Aucun
|
||||
cms.ui.category.inherit_parent=Inherit Index from Parent Category
|
||||
cms.ui.browse=Documents
|
||||
cms.ui.search=Search
|
||||
cms.ui.roles=Roles
|
||||
|
|
|
|||
Loading…
Reference in New Issue