CCM NG/ccm-cms: Renaming folders
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4595 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
99799c832c
commit
40910eeab7
|
|
@ -22,44 +22,52 @@ import com.arsdigita.bebop.FormData;
|
|||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
|
||||
|
||||
/**
|
||||
* Implements functionality for renaming a folder. Most code taken from FolderCreator. Need to refactor out base
|
||||
* functionality of FolderEditor & Creator.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens >Pelzetter</a>
|
||||
* @author <a href="mailto:jorris@arsdigita.com">Jon Orris</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens >Pelzetter</a>
|
||||
*
|
||||
*/
|
||||
|
||||
public class FolderEditor extends FolderForm {
|
||||
|
||||
public FolderEditor(String name, FolderSelectionModel folder) {
|
||||
public FolderEditor(final String name, final FolderSelectionModel folder) {
|
||||
super(name, folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the form with name & label of folder being edited.
|
||||
* @param e
|
||||
* @param event
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void init(FormSectionEvent e) throws FormProcessException {
|
||||
PageState s = e.getPageState();
|
||||
FormData data = e.getFormData();
|
||||
Category folder = getCurrentFolder(s);
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
final PageState state = event.getPageState();
|
||||
final FormData data = event.getFormData();
|
||||
final Category folder = getCurrentFolder(state);
|
||||
data.put(NAME, folder.getName());
|
||||
data.put(TITLE, folder.getDisplayName());
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ConfigurationManager confManager = cdiUtil.findBean(ConfigurationManager.class);
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
data.put(TITLE,
|
||||
folder.getTitle().getValue(kernelConfig.getDefaultLocale()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void process(FormSectionEvent e) throws FormProcessException {
|
||||
PageState s = e.getPageState();
|
||||
FormData data = e.getFormData();
|
||||
Category folder = getCurrentFolder(s);
|
||||
public void process(final FormSectionEvent event) throws FormProcessException {
|
||||
final PageState state = event.getPageState();
|
||||
final FormData data = event.getFormData();
|
||||
final Category folder = getCurrentFolder(state);
|
||||
|
||||
updateFolder(folder, (String)data.get(NAME), (String)data.get(TITLE));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
|||
import com.arsdigita.bebop.parameters.URLTokenValidationListener;
|
||||
import com.arsdigita.cms.ui.authoring.BasicItemForm;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.util.Assert;
|
||||
import com.arsdigita.web.Web;
|
||||
import com.arsdigita.xml.Element;
|
||||
|
|
@ -46,6 +47,8 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
/**
|
||||
|
|
@ -62,9 +65,9 @@ import org.librecms.CmsConstants;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public abstract class FolderForm extends FormSection
|
||||
implements FormInitListener,
|
||||
FormProcessListener,
|
||||
FormValidationListener {
|
||||
implements FormInitListener,
|
||||
FormProcessListener,
|
||||
FormValidationListener {
|
||||
|
||||
public static final Logger LOGGER = LogManager.getLogger(FolderForm.class);
|
||||
|
||||
|
|
@ -81,16 +84,16 @@ public abstract class FolderForm extends FormSection
|
|||
* Currently, to insert javascript code the Label Widget is "abused".
|
||||
*/
|
||||
private final Label m_script = new Label(String.format(
|
||||
"<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\"></script>",
|
||||
Web.getWebappContextPath()),
|
||||
"<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\"></script>",
|
||||
Web.getWebappContextPath()),
|
||||
false);
|
||||
|
||||
/**
|
||||
* Create a new folder form.
|
||||
*
|
||||
* @param name Name of the form
|
||||
* @param name Name of the form
|
||||
* @param currentFolder SelectionModel containing the current folder being
|
||||
* operated on.
|
||||
* operated on.
|
||||
*
|
||||
* @pre name != null && folder != null
|
||||
*/
|
||||
|
|
@ -137,7 +140,7 @@ public abstract class FolderForm extends FormSection
|
|||
super(columnPanel);
|
||||
|
||||
widgetSection = new FormSection(
|
||||
new ColumnPanel(columnPanel.getNumCols()));
|
||||
new ColumnPanel(columnPanel.getNumCols()));
|
||||
super.add(widgetSection, ColumnPanel.INSERT);
|
||||
this.currentFolder = currentFolder;
|
||||
|
||||
|
|
@ -169,20 +172,20 @@ public abstract class FolderForm extends FormSection
|
|||
// it breaks URLs & potentially overwrites the user's
|
||||
// customizations.
|
||||
final TextField titleWidget = new TextField(new TrimmedStringParameter(
|
||||
TITLE));
|
||||
TITLE));
|
||||
titleWidget.setLabel(getTitleLabel());
|
||||
titleWidget.setHint(getTitleHint());
|
||||
titleWidget.addValidationListener(new NotNullValidationListener());
|
||||
titleWidget.setOnFocus("if (this.form." + NAME + ".value == '') { "
|
||||
+ " defaulting = true; this.form." + NAME
|
||||
+ ".value = urlize(this.value); }");
|
||||
+ " defaulting = true; this.form." + NAME
|
||||
+ ".value = urlize(this.value); }");
|
||||
titleWidget.setOnKeyUp(
|
||||
"if (defaulting) { this.form." + NAME
|
||||
+ ".value = urlize(this.value) }");
|
||||
"if (defaulting) { this.form." + NAME
|
||||
+ ".value = urlize(this.value) }");
|
||||
add(titleWidget);
|
||||
|
||||
final TextField nameWidget = new TextField(new TrimmedStringParameter(
|
||||
NAME));
|
||||
NAME));
|
||||
nameWidget.setLabel(getNameLabel());
|
||||
nameWidget.setHint(getNameHint());
|
||||
|
||||
|
|
@ -195,11 +198,11 @@ public abstract class FolderForm extends FormSection
|
|||
nameWidget.setMaxLength(190);
|
||||
nameWidget.setOnFocus("defaulting = false");
|
||||
nameWidget.setOnBlur(
|
||||
"if (this.value == '') "
|
||||
+ "{ defaulting = true; this.value = urlize(this.form."
|
||||
+ TITLE
|
||||
+ ".value) } "
|
||||
+ " else { this.value = urlize(this.value); }");
|
||||
"if (this.value == '') "
|
||||
+ "{ defaulting = true; this.value = urlize(this.form."
|
||||
+ TITLE
|
||||
+ ".value) } "
|
||||
+ " else { this.value = urlize(this.value); }");
|
||||
add(nameWidget);
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +228,7 @@ public abstract class FolderForm extends FormSection
|
|||
*/
|
||||
@Override
|
||||
public abstract void init(final FormSectionEvent event)
|
||||
throws FormProcessException;
|
||||
throws FormProcessException;
|
||||
|
||||
/**
|
||||
* Process the form. Children have to override this method to save the
|
||||
|
|
@ -237,7 +240,7 @@ public abstract class FolderForm extends FormSection
|
|||
*/
|
||||
@Override
|
||||
public abstract void process(final FormSectionEvent event)
|
||||
throws FormProcessException;
|
||||
throws FormProcessException;
|
||||
|
||||
/**
|
||||
* Validates the form. Checks for name uniqueness.
|
||||
|
|
@ -248,9 +251,9 @@ public abstract class FolderForm extends FormSection
|
|||
*/
|
||||
@Override
|
||||
public void validate(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
throws FormProcessException {
|
||||
Category folder = (Category) currentFolder.getSelectedObject(event
|
||||
.getPageState());
|
||||
.getPageState());
|
||||
Assert.exists(folder);
|
||||
// validateNameUniqueness(folder, event);
|
||||
}
|
||||
|
|
@ -271,9 +274,9 @@ public abstract class FolderForm extends FormSection
|
|||
* Layout constraints are defined in each layout container as static ints.
|
||||
* Use a bitwise OR to specify multiple constraints.
|
||||
*
|
||||
* @param component the component to add to this container
|
||||
* @param component the component to add to this container
|
||||
* @param constraints layout constraints (a bitwise OR of static ints in the
|
||||
* particular layout)
|
||||
* particular layout)
|
||||
*/
|
||||
@Override
|
||||
public void add(final Component component, final int constraints) {
|
||||
|
|
@ -345,8 +348,8 @@ public abstract class FolderForm extends FormSection
|
|||
*
|
||||
* @param folder The folder to update
|
||||
* @param parent The new parent folder. May be null.
|
||||
* @param name The new name of the folder
|
||||
* @param label The new label for the folder
|
||||
* @param name The new name of the folder
|
||||
* @param label The new label for the folder
|
||||
*/
|
||||
final protected void updateFolder(final Category folder,
|
||||
final Category parent,
|
||||
|
|
@ -360,32 +363,36 @@ public abstract class FolderForm extends FormSection
|
|||
* Updates a folder with a new name and label.
|
||||
*
|
||||
* @param folder The folder to update
|
||||
* @param name The new name of the folder
|
||||
* @param label The new label for the folder
|
||||
* @param name The new name of the folder
|
||||
* @param label The new label for the folder
|
||||
*/
|
||||
final protected void updateFolder(final Category folder,
|
||||
final String name,
|
||||
final String label) {
|
||||
folder.setName(name);
|
||||
folder.setDisplayName(label);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ConfigurationManager confManager = cdiUtil.findBean(ConfigurationManager.class);
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
|
||||
folder.setName(name);
|
||||
folder.setDisplayName(name);
|
||||
folder.getTitle().addValue(kernelConfig.getDefaultLocale(), label);
|
||||
|
||||
final CategoryRepository categoryRepo = cdiUtil.findBean(
|
||||
CategoryRepository.class);
|
||||
CategoryRepository.class);
|
||||
categoryRepo.save(folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current folder being operated on.
|
||||
*
|
||||
* @param state
|
||||
* @return The current folder
|
||||
*
|
||||
* @pre state != null
|
||||
* @post return != null
|
||||
*/
|
||||
final protected Category getCurrentFolder(final PageState state) {
|
||||
final Category folder = (Category) currentFolder
|
||||
.getSelectedObject(state);
|
||||
.getSelectedObject(state);
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import com.arsdigita.bebop.tree.TreeModel;
|
|||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
||||
import com.arsdigita.bebop.tree.TreeNode;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.ui.admin.applications.ApplicationInstanceTreeNode;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
|
|
@ -40,6 +40,7 @@ import org.librecms.contentsection.Folder;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
|
||||
/**
|
||||
* A {@link com.arsdigita.bebop.tree.TreeModelBuilder} that produces trees
|
||||
|
|
@ -51,17 +52,17 @@ import java.util.stream.Collectors;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class FolderTreeModelBuilder extends LockableImpl
|
||||
implements TreeModelBuilder {
|
||||
implements TreeModelBuilder {
|
||||
|
||||
/**
|
||||
* Make a tree model that lists the hierarchy of folders underneath the
|
||||
* folder returned by {@link #getRoot getRoot}.
|
||||
*
|
||||
* @param tree the tree in which the model is used
|
||||
* @param tree the tree in which the model is used
|
||||
* @param state represents the current request
|
||||
*
|
||||
* @return a tree model that lists the hierarchy of folders underneath the
|
||||
* folder returned by {@link #getRoot getRoot}.
|
||||
* folder returned by {@link #getRoot getRoot}.
|
||||
*/
|
||||
@Override
|
||||
public TreeModel makeModel(final Tree tree, final PageState state) {
|
||||
|
|
@ -77,19 +78,19 @@ public class FolderTreeModelBuilder extends LockableImpl
|
|||
final PageState state) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final FolderTreeModelController controller = cdiUtil.findBean(
|
||||
FolderTreeModelController.class);
|
||||
FolderTreeModelController.class);
|
||||
|
||||
return controller.hasChildren(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<TreeNode> getChildren(final TreeNode node,
|
||||
final PageState state) {
|
||||
final PageState state) {
|
||||
final String nodeKey = node.getKey().toString();
|
||||
|
||||
// Always expand root node
|
||||
if (nodeKey.equals(getRoot(state).getKey().toString())
|
||||
&& tree.isCollapsed(nodeKey, state)) {
|
||||
&& tree.isCollapsed(nodeKey, state)) {
|
||||
tree.expand(nodeKey, state);
|
||||
}
|
||||
|
||||
|
|
@ -99,24 +100,22 @@ public class FolderTreeModelBuilder extends LockableImpl
|
|||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final FolderTreeModelController controller = cdiUtil.findBean(
|
||||
FolderTreeModelController.class);
|
||||
FolderTreeModelController.class);
|
||||
|
||||
final List<Folder> subFolders = controller.getChildren(node);
|
||||
return subFolders.stream()
|
||||
.map(folder -> generateTreeNode(folder))
|
||||
.collect(Collectors.toList())
|
||||
.iterator();
|
||||
.map(folder -> generateTreeNode(folder))
|
||||
.collect(Collectors.toList())
|
||||
.iterator();
|
||||
}
|
||||
|
||||
private TreeNode generateTreeNode(final Folder folder) {
|
||||
final FolderTreeNode node = new FolderTreeNode(folder);
|
||||
final FolderTreeNode node = new FolderTreeNode(folder);
|
||||
|
||||
return node;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*return new DataQueryTreeModel(getRoot(state).getID(),
|
||||
"com.arsdigita.cms.getRootFolder",
|
||||
"com.arsdigita.cms.getSubFolders") {
|
||||
|
|
@ -171,7 +170,7 @@ public class FolderTreeModelBuilder extends LockableImpl
|
|||
*
|
||||
*/
|
||||
protected Folder getRootFolder(final PageState state)
|
||||
throws IllegalStateException {
|
||||
throws IllegalStateException {
|
||||
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
return section.getRootDocumentsFolder();
|
||||
|
|
@ -194,12 +193,17 @@ public class FolderTreeModelBuilder extends LockableImpl
|
|||
public Object getElement() {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil.findBean(
|
||||
GlobalizationHelper.class);
|
||||
GlobalizationHelper.class);
|
||||
final Locale locale = globalizationHelper.getNegotiatedLocale();
|
||||
if (folder.getTitle().hasValue(locale)) {
|
||||
return folder.getTitle().getValue(locale);
|
||||
} else {
|
||||
final String value = folder.getTitle().getValue();
|
||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
||||
ConfigurationManager.class);
|
||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
||||
KernelConfig.class);
|
||||
final String value = folder.getTitle().getValue(kernelConfig.
|
||||
getDefaultLocale());
|
||||
if (value == null) {
|
||||
return folder.getName();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -118,3 +118,5 @@ cms.ui.edit_folder=Rename the current folder
|
|||
cms.ui.authoring.create_new=Create new
|
||||
cms.ui.authoring.go=Go
|
||||
empty_text=
|
||||
cms.contenttypes.ui.title=Title
|
||||
cms.contenttypes.ui.name=Name (URL fragment)
|
||||
|
|
|
|||
|
|
@ -117,3 +117,5 @@ cms.ui.edit_folder=Aktuellen Ordner umbenennen
|
|||
cms.ui.authoring.create_new=Neuer Inhalt
|
||||
cms.ui.authoring.go=Anlegen
|
||||
empty_text=
|
||||
cms.contenttypes.ui.title=Titel
|
||||
cms.contenttypes.ui.name=Name (URL-Fragment)
|
||||
|
|
|
|||
|
|
@ -86,3 +86,5 @@ cms.ui.edit_folder=Rename the current folder
|
|||
cms.ui.authoring.create_new=Create new
|
||||
cms.ui.authoring.go=Go
|
||||
empty_text=
|
||||
cms.contenttypes.ui.title=Title
|
||||
cms.contenttypes.ui.name=Name (URL fragment)
|
||||
|
|
|
|||
Loading…
Reference in New Issue