incorporate APLAWS patch
r1689 | chrisg23 | 2007-10-26 13:06:23 +0200 (Fr, 26 Okt 2007) Sourceforge Patch [1820586] - allow contact content items to be added as an asset to other content items git-svn-id: https://svn.libreccm.org/ccm/trunk@37 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
fbaf37a9ca
commit
5c56527e40
|
|
@ -2,7 +2,7 @@
|
|||
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
|
||||
name="ccm-cms-types-contact"
|
||||
prettyName="Red Hat CCM Content Types"
|
||||
version="6.5.0"
|
||||
version="6.5.1"
|
||||
release="1"
|
||||
webapp="ROOT">
|
||||
<ccm:dependencies>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
model com.arsdigita.cms.contenttypes;
|
||||
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
|
||||
// object type to hold Contact content type
|
||||
object type Contact extends ContentPage {
|
||||
|
|
@ -43,3 +44,46 @@ object type Contact extends ContentPage {
|
|||
|
||||
reference key ( ct_contacts.contact_id );
|
||||
}
|
||||
|
||||
association {
|
||||
|
||||
Contact[0..1] associatedContactForItem =
|
||||
join cms_items.item_id to contact_content_item_map.item_id,
|
||||
join contact_content_item_map.contact_id to ct_contacts.contact_id;
|
||||
ContentItem[0..n] associatedContentItemsForContact =
|
||||
join ct_contacts.contact_id to contact_content_item_map.contact_id,
|
||||
join contact_content_item_map.item_id to cms_items.item_id;
|
||||
|
||||
}
|
||||
|
||||
// the above association works fine for adding but for some strange reason when
|
||||
// you try to remove an item from the association it also tries to delete it
|
||||
// so instead you have to use a data operation
|
||||
|
||||
data operation removeContactFromContentItemAssociation {
|
||||
do {
|
||||
delete from contact_content_item_map where item_id = :itemID
|
||||
}
|
||||
}
|
||||
|
||||
data operation removeContactFromAllAssociations {
|
||||
do {
|
||||
delete from contact_content_item_map where contact_id = :contactID
|
||||
}
|
||||
}
|
||||
|
||||
query getContactForItem {
|
||||
BigDecimal contactID;
|
||||
BigDecimal itemID;
|
||||
do {
|
||||
select contact_id, item_id
|
||||
from
|
||||
contact_content_item_map
|
||||
where
|
||||
item_id = :itemID
|
||||
} map {
|
||||
contactID = contact_id;
|
||||
itemID = item_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
create table contact_content_item_map (
|
||||
item_id INTEGER not null
|
||||
constraint cont_con_ite_map_ite_i_p_scqe9
|
||||
primary key,
|
||||
-- referential constraint for item_id deferred due to circular dependencies
|
||||
contact_id INTEGER not null
|
||||
-- referential constraint for contact_id deferred due to circular dependencies
|
||||
);
|
||||
|
||||
|
||||
alter table contact_content_item_map add
|
||||
constraint cont_con_ite_map_con_i_f_lanid foreign key (contact_id)
|
||||
references ct_contacts(contact_id);
|
||||
alter table contact_content_item_map add
|
||||
constraint cont_con_ite_map_ite_i_f_fr0po foreign key (item_id)
|
||||
references cms_items(item_id);
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
--
|
||||
-- Copyright (C) 2007 Magpie. 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
|
||||
--
|
||||
|
||||
@@ ../default/upgrade/6.5.0-6.5.1/contact_content_item_map_table.sql
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
--
|
||||
-- Copyright (C) 2007 Magpie. All Rights Reserved.
|
||||
--
|
||||
-- The contents of this file are subject to the CCM Public
|
||||
-- License (the "License"); you may not use this file except in
|
||||
-- compliance with the License. You may obtain a copy of the
|
||||
-- License at http://www.redhat.com/licenses/ccmpl.html.
|
||||
--
|
||||
-- Software distributed under the License is distributed on an
|
||||
-- "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
||||
-- or implied. See the License for the specific language governing
|
||||
-- rights and limitations under the License.
|
||||
--
|
||||
|
||||
\echo Red Hat Enterprise CMS 6.5.0 -> 6.5.1 Upgrade Script (PostgreSQL)
|
||||
|
||||
begin;
|
||||
|
||||
\i ../default/upgrade/6.5.0-6.5.1/contact_content_item_map_table.sql
|
||||
|
||||
commit;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<upgrade>
|
||||
<version from="6.5.0" to="6.5.1">
|
||||
<script sql="ccm-cms-types-contact/upgrade/::database::-6.5.0-6.5.1.sql"/>
|
||||
</version>
|
||||
</upgrade>
|
||||
|
|
@ -20,13 +20,19 @@ package com.arsdigita.cms.contenttypes;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentType;
|
||||
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||
import com.arsdigita.persistence.DataAssociation;
|
||||
import com.arsdigita.persistence.DataAssociationCursor;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.DataOperation;
|
||||
import com.arsdigita.persistence.DataQuery;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.persistence.SessionManager;
|
||||
import com.arsdigita.util.Assert;
|
||||
/**
|
||||
*
|
||||
|
|
@ -41,8 +47,10 @@ import com.arsdigita.util.Assert;
|
|||
public class Contact extends ContentPage {
|
||||
|
||||
/** PDL property names */
|
||||
/*Flattened out Person object properties.Next 3 properties can be moved
|
||||
* out to seperate object if needed.*/
|
||||
/*
|
||||
* Flattened out Person object properties.Next 3 properties can be moved out
|
||||
* to seperate object if needed.
|
||||
*/
|
||||
public static final String GIVEN_NAME = "givenName";
|
||||
public static final String FAMILY_NAME = "familyName";
|
||||
public static final String SUFFIX = "suffix";
|
||||
|
|
@ -58,15 +66,86 @@ public class Contact extends ContentPage {
|
|||
public static final String CONTACT_ADDRESS = "contactAddress";
|
||||
public static final String PHONES = "phones";
|
||||
|
||||
public static final String ITEMS = "associatedContentItemsForContact";
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(Contact.class);
|
||||
|
||||
/** data object type for this domain object */
|
||||
public static final String BASE_DATA_OBJECT_TYPE =
|
||||
"com.arsdigita.cms.contenttypes.Contact";
|
||||
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Contact";
|
||||
|
||||
/** Default constructor. */
|
||||
public Contact() {
|
||||
super(BASE_DATA_OBJECT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an association between this contact and the given content item.
|
||||
* @param item
|
||||
*/
|
||||
public void addContentItem(ContentItem item) {
|
||||
s_log.debug("item is " + item);
|
||||
item.addToAssociation(getItemsForContact());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the association between this contact and the given content item.
|
||||
* @param item
|
||||
*/
|
||||
public void removeContentItem(ContentItem item) {
|
||||
s_log.debug("item is " + item);
|
||||
DataOperation operation = SessionManager
|
||||
.getSession()
|
||||
.retrieveDataOperation(
|
||||
"com.arsdigita.cms.contenttypes.removeContactFromContentItemAssociation");
|
||||
operation.setParameter("itemID", new Integer(item.getID().intValue()));
|
||||
operation.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all mappings between this contact and any other content item.
|
||||
*
|
||||
*/
|
||||
private void removeItemMappings() {
|
||||
DataOperation operation = SessionManager
|
||||
.getSession()
|
||||
.retrieveDataOperation("com.arsdigita.cms.contenttypes.removeContactFromAllAssociations");
|
||||
operation.setParameter("contactID", new Integer(this.getID().intValue()));
|
||||
operation.execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the DataAssociation that holds the mapping between this contact and any content items.
|
||||
* @return
|
||||
*/
|
||||
public DataAssociation getItemsForContact() {
|
||||
return (DataAssociation) get(ITEMS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Contact for a given content item.
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
public static Contact getContactForItem(ContentItem item) {
|
||||
s_log.debug("getting contact for item " + item);
|
||||
DataQuery query = SessionManager.getSession().retrieveQuery(
|
||||
"com.arsdigita.cms.contenttypes.getContactForItem");
|
||||
query.setParameter("itemID", item.getID());
|
||||
BigDecimal contactID;
|
||||
Contact contact = null;
|
||||
while (query.next()) {
|
||||
contactID = (BigDecimal) query.get("contactID");
|
||||
contact = new Contact(contactID);
|
||||
}
|
||||
s_log.debug("returning contact " + contact);
|
||||
return contact;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Retrieves an object instance with the given id.
|
||||
* @param id the id of the object to retrieve
|
||||
|
|
|
|||
|
|
@ -20,6 +20,14 @@ package com.arsdigita.cms.contenttypes;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
import com.arsdigita.cms.contenttypes.ui.contact.AddContactPropertiesStep;
|
||||
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||
import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.runtime.LegacyInitEvent;
|
||||
|
||||
/**
|
||||
* Initializer class to initialize <code>ContentType <code>Contact</code>.
|
||||
*
|
||||
|
|
@ -61,4 +69,51 @@ public class ContactInitializer extends ContentTypeInitializer {
|
|||
return phoneTypesList;
|
||||
}
|
||||
|
||||
public void init(LegacyInitEvent evt) {
|
||||
super.init(evt);
|
||||
|
||||
if (ContentSection.getConfig().getHasContactsAuthoringStep()) {
|
||||
|
||||
// Add the "Contact"authoring step
|
||||
AuthoringKitWizard.registerAssetStep(getBaseType(),
|
||||
getAuthoringStep(), getAuthoringStepLabel(),
|
||||
getAuthoringStepDescription(), getAuthoringStepSortKey());
|
||||
|
||||
// and sort out the display - at the moment this is just the basic properties, addresses and phones
|
||||
ContentItemTraversalAdapter associatedContactTraversalAdapter = new ContentItemTraversalAdapter();
|
||||
associatedContactTraversalAdapter.addAssociationProperty("/object/phones");
|
||||
associatedContactTraversalAdapter.addAssociationProperty("/object/contactAddress");
|
||||
|
||||
ContentItemTraversalAdapter.registerAssetAdapter(
|
||||
"associatedContactForItem",
|
||||
associatedContactTraversalAdapter,
|
||||
"com.arsdigita.cms.dispatcher.SimpleXMLGenerator");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getAuthoringStepSortKey() {
|
||||
// TODO - workout what this does and possibly make it configurable
|
||||
return 1;
|
||||
}
|
||||
|
||||
private GlobalizedMessage getAuthoringStepDescription() {
|
||||
return new GlobalizedMessage(
|
||||
"com.arsdigita.cms.contenttypes.contact_authoring_step_description",
|
||||
"com.arsdigita.cms.contenttypes.ContactResources");
|
||||
}
|
||||
|
||||
private GlobalizedMessage getAuthoringStepLabel() {
|
||||
return new GlobalizedMessage(
|
||||
"com.arsdigita.cms.contenttypes.contact_authoring_step_label",
|
||||
"com.arsdigita.cms.contenttypes.ContactResources");
|
||||
}
|
||||
|
||||
private Class getAuthoringStep() {
|
||||
return AddContactPropertiesStep.class;
|
||||
}
|
||||
|
||||
private String getBaseType() {
|
||||
return ContentPage.BASE_DATA_OBJECT_TYPE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,3 +19,8 @@ cms.contenttypes.ui.contact_description=Contact Description
|
|||
cms.contenttypes.ui.contact.phone_number=Number
|
||||
cms.contenttypes.ui.phone_type=Types
|
||||
cms.contenttypes.ui.contact_emails=Emails
|
||||
com.arsdigita.cms.contenttypes.contact_authoring_step_description=Contact
|
||||
com.arsdigita.cms.contenttypes.contact_authoring_step_label=Contact
|
||||
cms.contenttypes.ui.name=Name
|
||||
cms.contenttypes.ui.title=Title
|
||||
cms.contenttypes.ui.description=Description
|
||||
|
|
|
|||
|
|
@ -0,0 +1,240 @@
|
|||
package com.arsdigita.cms.contenttypes.ui.contact;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.FormSection;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.RequestLocal;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.contenttypes.Contact;
|
||||
import com.arsdigita.cms.contenttypes.ui.ResettableContainer;
|
||||
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
|
||||
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowLockedContainer;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
public class AddContactPropertiesStep extends ResettableContainer {
|
||||
|
||||
private static final Logger s_log = Logger
|
||||
.getLogger(AddContactPropertiesStep.class);
|
||||
|
||||
public static final String EDIT_SHEET_NAME = "edit";
|
||||
|
||||
public Form m_form;
|
||||
|
||||
private ItemSelectionModel m_itemSelectionModel;
|
||||
|
||||
public ContactSelectionModel m_contactSelectionModel;
|
||||
|
||||
private AuthoringKitWizard m_parent;
|
||||
|
||||
protected Component m_contactPropertySheet;
|
||||
|
||||
private ContactDisplay m_display;
|
||||
|
||||
public AddContactPropertiesStep(ItemSelectionModel itemModel,
|
||||
AuthoringKitWizard parent) {
|
||||
|
||||
m_parent = parent;
|
||||
m_itemSelectionModel = itemModel;
|
||||
m_contactSelectionModel = new ContactSelectionModel(
|
||||
m_itemSelectionModel);
|
||||
|
||||
Form display = new Form("display");
|
||||
display.add(getContactDisplay());
|
||||
add(display);
|
||||
|
||||
m_form = new Form("contactSearchForm");
|
||||
m_form.add(getFindContactSheet());
|
||||
|
||||
WorkflowLockedContainer edit = new WorkflowLockedContainer(itemModel);
|
||||
edit.add(m_form);
|
||||
add(edit);
|
||||
|
||||
}
|
||||
|
||||
protected Component getContactDisplay() {
|
||||
m_display = new ContactDisplay();
|
||||
return m_display;
|
||||
}
|
||||
|
||||
public void toggleDisplay(PageState state) throws FormProcessException {
|
||||
m_display.toggle(state);
|
||||
}
|
||||
|
||||
private Component getFindContactSheet() {
|
||||
return new AddContactToItemForm(this);
|
||||
}
|
||||
|
||||
public ItemSelectionModel getItemSelectionModel() {
|
||||
return m_itemSelectionModel;
|
||||
}
|
||||
|
||||
public ItemSelectionModel getContactSelectionModel() {
|
||||
return m_contactSelectionModel;
|
||||
}
|
||||
|
||||
public AuthoringKitWizard getParent() {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
public ContentItem getItem(PageState state) {
|
||||
return m_itemSelectionModel.getSelectedItem(state);
|
||||
}
|
||||
|
||||
public Contact getContact(PageState state) {
|
||||
return (Contact) m_contactSelectionModel.getSelectedItem(state);
|
||||
}
|
||||
|
||||
protected class ContactSelectionModel extends ItemSelectionModel {
|
||||
|
||||
private RequestLocal m_contact;
|
||||
|
||||
public ContactSelectionModel(ItemSelectionModel m) {
|
||||
super(m);
|
||||
|
||||
m_contact = new RequestLocal() {
|
||||
protected Object initialValue(PageState s) {
|
||||
ContentItem item = (ContentItem) ((ItemSelectionModel) getSingleSelectionModel())
|
||||
.getSelectedObject(s);
|
||||
Assert.assertNotNull(item);
|
||||
return Contact.getContactForItem(item);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Object getSelectedKey(PageState s) {
|
||||
Contact contact = (Contact) getSelectedObject(s);
|
||||
return (contact == null) ? null : contact.getID();
|
||||
}
|
||||
|
||||
public DomainObject getSelectedObject(PageState s) {
|
||||
return (DomainObject) m_contact.get(s);
|
||||
}
|
||||
|
||||
public void setSelectedObject(PageState s, DomainObject o) {
|
||||
m_contact.set(s, o);
|
||||
}
|
||||
|
||||
public void setSelectedKey(PageState s, Object key) {
|
||||
throw new UnsupportedOperationException((String) GlobalizationUtil
|
||||
.globalize("cms.ui.authoring.not_implemented").localize());
|
||||
}
|
||||
|
||||
public boolean isSelected(PageState s) {
|
||||
return (getSelectedObject(s) != null);
|
||||
}
|
||||
}
|
||||
|
||||
private class ContactDisplay extends FormSection implements
|
||||
FormInitListener {
|
||||
|
||||
private Label m_noContact;
|
||||
|
||||
public ContactDisplay() {
|
||||
|
||||
addInitListener(this);
|
||||
addWidgets();
|
||||
}
|
||||
|
||||
public void toggle(PageState state) {
|
||||
s_log.debug("toggle");
|
||||
m_contactPropertySheet.setVisible(state, false);
|
||||
m_noContact.setVisible(state, true);
|
||||
|
||||
}
|
||||
|
||||
private void addWidgets() {
|
||||
m_contactPropertySheet = getContactPropertySheet(m_contactSelectionModel);
|
||||
m_noContact = new Label("This item does not have a contact.");
|
||||
m_noContact.setFontWeight(Label.ITALIC);
|
||||
add(m_contactPropertySheet);
|
||||
add(m_noContact);
|
||||
}
|
||||
|
||||
public void init(FormSectionEvent e) throws FormProcessException {
|
||||
s_log.debug("init");
|
||||
PageState state = e.getPageState();
|
||||
if (m_contactSelectionModel.getSelectedItem(state) != null) {
|
||||
m_contactPropertySheet.setVisible(state, true);
|
||||
m_noContact.setVisible(state, false);
|
||||
} else {
|
||||
m_noContact.setVisible(state, true);
|
||||
m_contactPropertySheet.setVisible(state, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Component getContactPropertySheet(ItemSelectionModel itemModel) {
|
||||
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
|
||||
itemModel);
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.name"), Contact.NAME);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.title"), Contact.TITLE);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_givenname"),
|
||||
Contact.GIVEN_NAME);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_familyname"),
|
||||
Contact.FAMILY_NAME);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_type"),
|
||||
Contact.CONTACT_TYPE,
|
||||
new DomainObjectPropertySheet.AttributeFormatter() {
|
||||
public String format(DomainObject item,
|
||||
String attribute, PageState state) {
|
||||
Contact contact = (Contact) item;
|
||||
if (contact != null
|
||||
&& contact.getContactType() != null) {
|
||||
return contact.getContactTypeName();
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.description"),
|
||||
Contact.DESCRIPTION);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_emails"),
|
||||
Contact.EMAILS);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_suffix"),
|
||||
Contact.SUFFIX);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_orgname"),
|
||||
Contact.ORG_NAME);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_deptname"),
|
||||
Contact.DEPT_NAME);
|
||||
|
||||
sheet.add(ContactGlobalizationUtil
|
||||
.globalize("cms.contenttypes.ui.contact_role"),
|
||||
Contact.ROLE);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
package com.arsdigita.cms.contenttypes.ui.contact;
|
||||
|
||||
import com.arsdigita.bebop.ActionLink;
|
||||
import com.arsdigita.bebop.ColumnPanel;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.FormSection;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
import com.arsdigita.bebop.event.ActionListener;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||
import com.arsdigita.bebop.event.FormValidationListener;
|
||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.contenttypes.Contact;
|
||||
import com.arsdigita.cms.ui.ItemSearchWidget;
|
||||
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||
|
||||
public class AddContactToItemForm extends FormSection implements
|
||||
FormInitListener, FormValidationListener, FormProcessListener,
|
||||
FormSubmissionListener {
|
||||
|
||||
private ContentItem m_item;
|
||||
|
||||
private ItemSearchWidget m_itemSearch;
|
||||
|
||||
private SaveCancelSection m_saveCancelSection;
|
||||
|
||||
private ItemSelectionModel m_itemSelectionModel;
|
||||
|
||||
private final String CONTACT_SEARCH = "contact";
|
||||
|
||||
private Contact m_contact;
|
||||
|
||||
private Label m_searchFormLabel;
|
||||
|
||||
private AddContactPropertiesStep m_step;
|
||||
|
||||
private AuthoringKitWizard m_parent;
|
||||
|
||||
private Label m_removeLinkText = new Label(GlobalizationUtil
|
||||
.globalize("Remove contact"));
|
||||
|
||||
private ActionLink m_removeLink;
|
||||
|
||||
public AddContactToItemForm(AddContactPropertiesStep step) {
|
||||
m_step = step;
|
||||
m_parent = m_step.getParent();
|
||||
|
||||
m_itemSelectionModel = m_step.getItemSelectionModel();
|
||||
addInitListener(this);
|
||||
addWidgets();
|
||||
addSaveCancelSection();
|
||||
addProcessListener(this);
|
||||
addValidationListener(this);
|
||||
addSubmissionListener(this);
|
||||
|
||||
}
|
||||
|
||||
public void addWidgets() {
|
||||
|
||||
m_removeLink = new ActionLink(m_removeLinkText);
|
||||
|
||||
m_removeLink.addActionListener(new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Contact contact = m_step.getContact(e.getPageState());
|
||||
if (contact != null) {
|
||||
PageState state = e.getPageState();
|
||||
contact.removeContentItem(m_step.getItem(state));
|
||||
m_step.m_contactSelectionModel.setSelectedObject(state,
|
||||
null);
|
||||
try {
|
||||
m_step.toggleDisplay(state);
|
||||
} catch (FormProcessException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
add(m_removeLink, ColumnPanel.FULL_WIDTH);
|
||||
|
||||
m_searchFormLabel = new Label("Search for Contact:");
|
||||
add(m_searchFormLabel);
|
||||
m_itemSearch = new ItemSearchWidget(CONTACT_SEARCH,
|
||||
Contact.BASE_DATA_OBJECT_TYPE);
|
||||
add(m_itemSearch);
|
||||
}
|
||||
|
||||
public AddContactToItemForm getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Adds the saveCancelSection */
|
||||
public void addSaveCancelSection() {
|
||||
m_saveCancelSection = new SaveCancelSection();
|
||||
m_saveCancelSection.getSaveButton().setButtonLabel("Add");
|
||||
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH);
|
||||
}
|
||||
|
||||
protected ContentItem getContentItem(PageState s) {
|
||||
return (ContentItem) m_itemSelectionModel.getSelectedObject(s);
|
||||
}
|
||||
|
||||
public void validate(FormSectionEvent e) throws FormProcessException {
|
||||
FormData data = e.getFormData();
|
||||
if (data.get(CONTACT_SEARCH) == null) {
|
||||
throw new FormProcessException("Contact selection is required.");
|
||||
}
|
||||
}
|
||||
|
||||
public void process(FormSectionEvent e) throws FormProcessException {
|
||||
FormData data = e.getFormData();
|
||||
PageState ps = e.getPageState();
|
||||
m_contact = (Contact) data.get(CONTACT_SEARCH);
|
||||
m_contact.addContentItem(getContentItem(ps));
|
||||
init(e);
|
||||
}
|
||||
|
||||
public void submitted(FormSectionEvent e) throws FormProcessException {
|
||||
if (m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) {
|
||||
m_parent.reset(e.getPageState());
|
||||
throw new FormProcessException("cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
public void init(FormSectionEvent e) throws FormProcessException {
|
||||
PageState ps = e.getPageState();
|
||||
m_item = getContentItem(ps);
|
||||
m_contact = Contact.getContactForItem(m_item);
|
||||
if (m_contact != null) {
|
||||
m_removeLink.setVisible(ps, true);
|
||||
m_searchFormLabel.setVisible(ps, false);
|
||||
m_itemSearch.setVisible(ps, false);
|
||||
m_saveCancelSection.setVisible(ps, false);
|
||||
} else {
|
||||
m_removeLink.setVisible(ps, false);
|
||||
m_searchFormLabel.setVisible(ps, true);
|
||||
m_itemSearch.setVisible(ps, true);
|
||||
m_saveCancelSection.setVisible(ps, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -123,6 +123,7 @@ public final class ContentSectionConfig extends AbstractConfig {
|
|||
private final Parameter m_deleteLifecycleWhenComplete;
|
||||
private final Parameter m_deleteExpiryNotificationsWhenSent;
|
||||
private final Parameter m_deleteWorkflowNotificationsWhenSent;
|
||||
private final Parameter m_hasContactsAuthoringStep;
|
||||
private final Parameter m_categoryTreeOrdering;
|
||||
|
||||
/**
|
||||
|
|
@ -353,6 +354,11 @@ public final class ContentSectionConfig extends AbstractConfig {
|
|||
((EnumerationParameter)m_categoryTreeOrdering).put("SortKey", Category.SORT_KEY );
|
||||
((EnumerationParameter)m_categoryTreeOrdering).put("Alphabetical", Category.NAME);
|
||||
|
||||
m_hasContactsAuthoringStep = new BooleanParameter
|
||||
("com.arsdigita.cms.has_contacts_authoring_step",
|
||||
Parameter.REQUIRED, new Boolean(false));
|
||||
|
||||
|
||||
register(m_templateRootPath);
|
||||
register(m_defaultItemTemplatePath);
|
||||
register(m_defaultFolderTemplatePath);
|
||||
|
|
@ -399,6 +405,7 @@ public final class ContentSectionConfig extends AbstractConfig {
|
|||
register(m_deleteExpiryNotificationsWhenSent);
|
||||
register(m_deleteWorkflowNotificationsWhenSent);
|
||||
register(m_categoryTreeOrdering);
|
||||
register(m_hasContactsAuthoringStep);
|
||||
loadInfo();
|
||||
}
|
||||
|
||||
|
|
@ -740,4 +747,9 @@ public final class ContentSectionConfig extends AbstractConfig {
|
|||
public String getCategoryTreeOrder () {
|
||||
return (String)get(m_categoryTreeOrdering);
|
||||
}
|
||||
|
||||
public boolean getHasContactsAuthoringStep() {
|
||||
return ((Boolean) get(m_hasContactsAuthoringStep)).booleanValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,3 +227,8 @@ com.arsdigita.cms.category_tree_order.title=Ordering for nodes in assign categor
|
|||
com.arsdigita.cms.category_tree_order.purpose=Decide whether entries should be ordered alphabetically or according to sort key (maintained in category admin tab in content centre)
|
||||
com.arsdigita.cms.category_tree_order.example=SortKey|Alphabetical
|
||||
com.arsdigita.cms.category_tree_order.format=[string]
|
||||
|
||||
com.arsdigita.cms.has_contacts_authoring_step.title=Contacts for content items
|
||||
com.arsdigita.cms.has_contacts_authoring_step.purpose=Allows you to add a Contact authoring step to all items
|
||||
com.arsdigita.cms.has_contacts_authoring_step.example=false
|
||||
com.arsdigita.cms.has_contacts_authoring_step.format=[boolean]
|
||||
|
|
|
|||
Loading…
Reference in New Issue