Contact informations can now be edited

git-svn-id: https://svn.libreccm.org/ccm/trunk@4125 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2016-06-01 08:59:17 +00:00
parent b1a35b0ed9
commit 1320957bfc
7 changed files with 267 additions and 97 deletions

View File

@ -173,3 +173,4 @@ cms.ui.edit_assoc=Edit
cms.contenttypes.ui.person.contact.type=Contact Type
cms.contenttypes.ui.person.contact.title=Title
cms.contenttypes.ui.contact.person.confirm_remove=Remove address
cms.contenttypes.ui.contact.contactEntry.edit=Edit

View File

@ -183,3 +183,4 @@ cms.ui.edit_assoc=Bearbeiten
cms.contenttypes.ui.person.contact.type=Art des Kontaktes
cms.contenttypes.ui.person.contact.title=Titel
cms.contenttypes.ui.contact.person.confirm_remove=Addresse l\u00f6schen
cms.contenttypes.ui.contact.contactEntry.edit=Bearbeiten

View File

@ -0,0 +1,113 @@
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ui.ControlButton;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.ContentItem;
/**
* Panel for managing contact informations
*/
public class GenericContactEntriesEditor extends BoxPanel {
private final ItemSelectionModel itemModel;
private final AuthoringKitWizard parent;
private final StringParameter selectedEntryParam;
private final ParameterSingleSelectionModel selectedEntry;
private final Form contactEntryForm;
private final GenericContactEntriesTable contactEntriesTable;
public GenericContactEntriesEditor(final ItemSelectionModel itemModel,
final AuthoringKitWizard parent) {
super(BoxPanel.VERTICAL);
this.itemModel = itemModel;
this.parent = parent;
selectedEntryParam = new StringParameter("selectedContactEntry");
selectedEntry = new ParameterSingleSelectionModel(selectedEntryParam);
contactEntryForm = new Form("contactEntryForm");
contactEntryForm.add(new GenericContactEntryAddForm(itemModel, this, selectedEntry));
add(contactEntryForm);
contactEntriesTable = new GenericContactEntriesTable(itemModel,
this,
selectedEntry);
add(contactEntriesTable);
final ActionLink addButton = new AddButton();
addButton.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
final PageState state = event.getPageState();
showContactEntryForm(state);
}
});
add(addButton);
}
@Override
public void register(final Page page) {
super.register(page);
page.addGlobalStateParam(selectedEntryParam);
page.setVisibleDefault(contactEntriesTable, true);
page.setVisibleDefault(contactEntryForm, false);
}
protected void showContactEntryForm(final PageState state) {
contactEntryForm.setVisible(state, true);
contactEntriesTable.setVisible(state, false);
}
protected void hideContactEntryForm(final PageState state) {
contactEntryForm.setVisible(state, false);
contactEntriesTable.setVisible(state, true);
selectedEntry.clearSelection(state);
}
private class AddButton extends ActionLink {
public AddButton() {
super(new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.add_contactEntry")));
}
@Override
public boolean isVisible(final PageState state) {
if (super.isVisible(state)) {
final SecurityManager securityManager =
Utilities.getSecurityManager(state);
final ContentItem item = (ContentItem) itemModel.getSelectedObject(state);
return securityManager.canAccess(state.getRequest(),
SecurityManager.EDIT_ITEM,
item);
} else {
return false;
}
}
}
}

View File

@ -25,51 +25,43 @@ import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
/**
* A UI step to manipulate <code>Phones </code> for the Contact object
* which is retrieved from the ItemSelectionModel.
*
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: PhoBaseContactEntriesPropertiesStepva 287 2005-02-22 00:29:02Z sskracic $
*/
public class GenericContactEntriesPropertiesStep extends SimpleEditStep {
/** The name of the editing sheet added to this step */
private static String ADD_CONTACT_ENTRY_SHEET_NAME = "addContactEntry";
/**
*
*
* @param itemModel
* @param parent
* @param parent
*/
public GenericContactEntriesPropertiesStep(ItemSelectionModel itemModel,
public GenericContactEntriesPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
this(itemModel, parent, null);
}
/**
*
*
* @param itemModel
* @param parent
* @param prefix
* @param prefix
*/
public GenericContactEntriesPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent,
public GenericContactEntriesPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent,
String prefix) {
super(itemModel, parent, prefix);
BasicItemForm addContactEntrySheet = new GenericContactEntryAddForm(itemModel);
add(ADD_CONTACT_ENTRY_SHEET_NAME,
add(ADD_CONTACT_ENTRY_SHEET_NAME,
ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.add_contactEntry"),
new WorkflowLockedComponentAccess(addContactEntrySheet,
itemModel),
"cms.contenttypes.ui.contact.add_contactEntry"),
new WorkflowLockedComponentAccess(addContactEntrySheet,
itemModel),
addContactEntrySheet.getSaveCancelSection().getCancelButton());
GenericContactEntriesTable contactEntriesTable = new GenericContactEntriesTable(itemModel);
setDisplayComponent(contactEntriesTable);
}
}
}

View File

@ -42,6 +42,7 @@ import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
/**
* Lists all existing contact entries for a selected contact.
@ -50,13 +51,21 @@ import java.math.BigDecimal;
*/
public class GenericContactEntriesTable extends Table implements TableActionListener {
private final int COL_KEY = 0;
private final int COL_VALUE = 1;
private final int COL_DESC = 2;
private final int COL_EDIT = 3;
private final int COL_DEL = 4;
private final String TABLE_COL_EDIT = "table_col_edit";
private final String TABLE_COL_DEL = "table_col_del";
private ItemSelectionModel m_itemModel;
private GenericContactEntriesEditor m_editor;
private ParameterSingleSelectionModel m_selectedEntry;
/**
* Creates a new instance of GenericContactEntriesTable.
*
*
* @param itemModel
*/
public GenericContactEntriesTable(final ItemSelectionModel itemModel) {
@ -71,33 +80,45 @@ public class GenericContactEntriesTable extends Table implements TableActionList
// define columns
tab_model.add(new TableColumn(
0,
COL_KEY,
new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.contactEntry.key")),
TABLE_COL_EDIT));
"cms.contenttypes.ui.contact.contactEntry.key"))));
tab_model.add(new TableColumn(
1,
COL_VALUE,
new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.contactEntry.value"))));
tab_model.add(new TableColumn(
2,
COL_DESC,
new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.contactEntry.description"))));
tab_model.add(new TableColumn(
3,
COL_EDIT,
new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.contactEntry.edit"))));
tab_model.add(new TableColumn(
COL_DEL,
new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.contactEntry.action")),
TABLE_COL_DEL));
setModelBuilder(new ContactTableModelBuilder(itemModel));
tab_model.get(0).setCellRenderer(new EditCellRenderer());
tab_model.get(3).setCellRenderer(new DeleteCellRenderer());
tab_model.get(COL_EDIT).setCellRenderer(new EditCellRenderer());
tab_model.get(COL_DEL).setCellRenderer(new DeleteCellRenderer());
addTableActionListener(this);
}
public GenericContactEntriesTable(final ItemSelectionModel itemModel,
final GenericContactEntriesEditor editor,
final ParameterSingleSelectionModel selectedEntry) {
this(itemModel);
m_editor = editor;
m_selectedEntry = selectedEntry;
}
/**
* XXXX
*
@ -144,7 +165,7 @@ public class GenericContactEntriesTable extends Table implements TableActionList
/**
* Check collection for the existence of another row.
*
*
* If exists, fetch the value of current GenericContactEntryCollection object
* into m_contactEntry class variable.
*/
@ -168,7 +189,7 @@ public class GenericContactEntriesTable extends Table implements TableActionList
@Override
public Object getElementAt(int columnIndex) {
switch (columnIndex) {
case 0:
case COL_KEY:
GenericContactEntryKeys keys = new GenericContactEntryKeys(m_contactEntry.getKey());
keys.addLanguageFilter(
GlobalizationHelper.getNegotiatedLocale()
@ -182,15 +203,17 @@ public class GenericContactEntriesTable extends Table implements TableActionList
return key;
}
return m_contactEntry.getKey();
case 1:
case COL_VALUE:
return m_contactEntry.getValue();
case 2:
case COL_DESC:
return (m_contactEntry.getDescription() != null
&& m_contactEntry.getDescription().length() > MAX_DESC_LENGTH)
? m_contactEntry.getDescription().substring(
0, MAX_DESC_LENGTH)
: m_contactEntry.getDescription();
case 3:
case COL_EDIT:
return new Label(GlobalizationUtil.globalize("cms.ui.edit"));
case COL_DEL:
return new Label(GlobalizationUtil.globalize("cms.ui.delete"));
default:
return null;
@ -217,20 +240,18 @@ public class GenericContactEntriesTable extends Table implements TableActionList
boolean isSelected, Object key,
int row, int column) {
return new Label(value.toString());
// SecurityManager sm = Utilities.getSecurityManager(state);
// GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
//
// boolean canEdit = sm.canAccess(state.getRequest(),
// SecurityManager.EDIT_ITEM,
// contact);
// if (canEdit) {
// ControlLink link = new ControlLink(value.toString());
// return link;
// } else {
// return new Label(value.toString());
// }
SecurityManager sm = Utilities.getSecurityManager(state);
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
boolean canEdit = sm.canAccess(state.getRequest(),
SecurityManager.EDIT_ITEM,
contact);
if (canEdit) {
ControlLink link = new ControlLink((Label)value);
return link;
} else {
return (Label) value;
}
}
}
@ -284,15 +305,15 @@ public class GenericContactEntriesTable extends Table implements TableActionList
// Get selected column
TableColumn col = getColumnModel().get(evt.getColumn().intValue());
// Edit
if (col.getHeaderKey().toString().equals(TABLE_COL_EDIT)) {
switch(evt.getColumn()) {
case COL_EDIT:
m_selectedEntry.setSelectedKey(state, evt.getRowKey().toString());
m_editor.showContactEntryForm(state);
break;
case COL_DEL:
contact.removeContactEntry(contactEntry);
break;
}
// Delete
if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
contact.removeContactEntry(contactEntry);
}
}
/**

View File

@ -26,8 +26,10 @@ import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.RelationAttributeResourceBundleControl;
@ -41,6 +43,7 @@ import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.UncheckedWrapperException;
import java.math.BigDecimal;
import java.util.TooManyListenersException;
import org.apache.log4j.Logger;
@ -53,6 +56,8 @@ public class GenericContactEntryAddForm extends BasicItemForm {
private static final Logger s_log = Logger.getLogger(GenericContactEntryAddForm.class);
private ItemSelectionModel m_itemModel;
private ParameterSingleSelectionModel m_selectedEntry;
private GenericContactEntriesEditor m_editor;
/**
* Creates a new instance of CategoryLocalizationAddForm.
@ -66,6 +71,15 @@ public class GenericContactEntryAddForm extends BasicItemForm {
}
public GenericContactEntryAddForm(ItemSelectionModel itemModel,
GenericContactEntriesEditor editor,
ParameterSingleSelectionModel selectedEntry) {
this(itemModel);
m_selectedEntry = selectedEntry;
m_editor = editor;
}
@Override
protected void addWidgets() {
@ -134,7 +148,18 @@ public class GenericContactEntryAddForm extends BasicItemForm {
*/
@Override
public void init(FormSectionEvent fse) {
final PageState state = fse.getPageState();
if (m_selectedEntry.getSelectedKey(state) != null) {
final GenericContactEntry entry =
new GenericContactEntry(new BigDecimal((String) m_selectedEntry.getSelectedKey(state)));
final FormData data = fse.getFormData();
data.put(GenericContactEntry.KEY, entry.getKey());
data.put(GenericContactEntry.VALUE, entry.getValue());
data.put(GenericContactEntry.DESCRIPTION, entry.getDescription());
}
}
/**
@ -143,6 +168,7 @@ public class GenericContactEntryAddForm extends BasicItemForm {
*/
@Override
public void process(FormSectionEvent fse) {
final PageState state = fse.getPageState();
FormData data = fse.getFormData();
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(fse.getPageState());
@ -151,13 +177,27 @@ public class GenericContactEntryAddForm extends BasicItemForm {
&& getSaveCancelSection().getSaveButton()
.isSelected(fse.getPageState())) {
GenericContactEntry contactEntry = new GenericContactEntry(
contact,
(String) data.get(GenericContactEntry.KEY),
(String) data.get(GenericContactEntry.VALUE),
(String) data.get(GenericContactEntry.DESCRIPTION));
if (m_selectedEntry.getSelectedKey(state) == null) {
GenericContactEntry contactEntry = new GenericContactEntry(
contact,
(String) data.get(GenericContactEntry.KEY),
(String) data.get(GenericContactEntry.VALUE),
(String) data.get(GenericContactEntry.DESCRIPTION));
contact.addContactEntry(contactEntry);
contact.addContactEntry(contactEntry);
} else {
final GenericContactEntry entry =
new GenericContactEntry(new BigDecimal((String) m_selectedEntry.getSelectedKey(state)));
entry.setKey((String) data.get(GenericContactEntry.KEY));
entry.setValue((String) data.get(GenericContactEntry.VALUE));
entry.setDescription((String) data.get(GenericContactEntry.DESCRIPTION));
entry.save();
}
}
if (m_editor != null) {
m_editor.hideContactEntryForm(fse.getPageState());
}
}

View File

@ -36,17 +36,17 @@ import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import org.apache.log4j.Logger;
/**
* Central entry point into the AuthoringStep for the basic properties of a
* basic contact (GenericContact). This class has to be specified in the
* content type's definition XML.
*
* Central entry point into the AuthoringStep for the basic properties of a
* basic contact (GenericContact). This class has to be specified in the
* content type's definition XML.
*
* It uses a segmented Panel to provide several components in one editing step.
* Handles the basic contentpage properties (title, name) and additional
* Handles the basic contentpage properties (title, name) and additional
* basic properties
* - Person
* - Address
* - Various contact entries.
*
*
* @author quasi <quasi@quasiweb.de>
*/
public class GenericContactPropertiesStep extends SimpleEditStep {
@ -64,7 +64,7 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
* @param itemModel
* @param parent
*/
public GenericContactPropertiesStep(ItemSelectionModel itemModel,
public GenericContactPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
// Construct a new SimpleEditComponent with basic funtionality
@ -84,37 +84,37 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
* - attached person
* - attached address
* - contact entries for this contact
*
*
* @param itemModel
* @param parent
* @return
* @return
*/
protected SegmentedPanel createEditSheet(ItemSelectionModel itemModel,
protected SegmentedPanel createEditSheet(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
/* Use a Segmented Panel for the multiple parts of data */
SegmentedPanel segmentedPanel = new SegmentedPanel();
/* The different parts of information are displayed in seperated
/* The different parts of information are displayed in seperated
* segments each containing a SimpleEditStep */
/* Well, not so simple anymore... */
/* A new SimpleEditStep for basic properties */
SimpleEditStep basicProperties = new SimpleEditStep(itemModel,
parent,
SimpleEditStep basicProperties = new SimpleEditStep(itemModel,
parent,
EDIT_BASIC_SHEET_NAME);
/* Create the edit component for this SimpleEditStep and the
/* Create the edit component for this SimpleEditStep and the
* corresponding link */
BasicPageForm editBasicSheet = new GenericContactPropertyForm(itemModel,
BasicPageForm editBasicSheet = new GenericContactPropertyForm(itemModel,
this);
basicProperties.add(
EDIT_BASIC_SHEET_NAME,
EDIT_BASIC_SHEET_NAME,
ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericcontact.edit_basic_properties"),
"cms.contenttypes.ui.genericcontact.edit_basic_properties"),
new WorkflowLockedComponentAccess(
editBasicSheet,
itemModel),
editBasicSheet,
itemModel),
editBasicSheet.getSaveCancelSection().getCancelButton());
/* Set the displayComponent for this step */
@ -122,7 +122,7 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
/* Add the basic properties SimpleEditStep to the segmented panel with
* provided title */
segmentedPanel.addSegment(new
segmentedPanel.addSegment(new
Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericcontact.basic_properties")),
basicProperties);
@ -131,12 +131,12 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
// If not disabled via registry, add the ui for attaching a person
if (!GenericContact.getConfig().getHidePerson()) {
GenericContactPersonPropertiesStep personProperties = new
GenericContactPersonPropertiesStep personProperties = new
GenericContactPersonPropertiesStep(itemModel, parent);
// Add step to segmented panel with the provided title
segmentedPanel.addSegment(new
segmentedPanel.addSegment(new
Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericcontact.person")),
"cms.contenttypes.ui.genericcontact.person")),
personProperties);
}
@ -145,23 +145,25 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
// If not disabled via registry, add the ui for attaching an address
if (!GenericContact.getConfig().getHideAddress()) {
GenericContactAddressPropertiesStep addressProperties = new
GenericContactAddressPropertiesStep addressProperties = new
GenericContactAddressPropertiesStep(itemModel, parent);
// Add step to segmented panel with the provided title
segmentedPanel.addSegment(new
segmentedPanel.addSegment(new
Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericcontact.address")),
"cms.contenttypes.ui.genericcontact.address")),
addressProperties);
}
// Add UI for adding several contact entries.
GenericContactEntriesPropertiesStep contactEntries = new
GenericContactEntriesPropertiesStep(itemModel, parent);
//GenericContactEntriesPropertiesStep contactEntries = new
// GenericContactEntriesPropertiesStep(itemModel, parent);
GenericContactEntriesEditor contactEntries =
new GenericContactEntriesEditor(itemModel, parent);
// Add step to segmented panel with the provided title
segmentedPanel.addSegment(new
segmentedPanel.addSegment(new
Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.genericcontact.contactEntry")),
"cms.contenttypes.ui.genericcontact.contactEntry")),
contactEntries);
return segmentedPanel;
@ -170,7 +172,7 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
/**
* Creates and returns the sheet for editing the basic properties
* of a contact. (@see GenericContactPropertyForm).
*
*
* @param itemModel
* @return The sheet for editing the properties of the contact.
*/
@ -180,9 +182,9 @@ public class GenericContactPropertiesStep extends SimpleEditStep {
/* The DisplayComponent for the Basic Properties */
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.title"),
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.title"),
"title");
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.name"),
sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.name"),
"name");
if (!ContentSection.getConfig().getHideLaunchDate()) {