diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index fd0e318d1a..634a4a5dd2 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -674,6 +674,9 @@ action_copy=Copy to action_extract_metadata=Extract metadata from content action_move=Move to action_mail=Send email to +action_mail_message_text=Enter message text +action_mail_template_text=Or select an email template for the message body +action_mail_template=Template action_check_in=Check in content as ''{0}'' with comment ''{1}'' action_check_out=Check out content to action_set_property_value=Sets property diff --git a/source/java/org/alfresco/web/app/Application.java b/source/java/org/alfresco/web/app/Application.java index 050017ef29..cd443e61f1 100644 --- a/source/java/org/alfresco/web/app/Application.java +++ b/source/java/org/alfresco/web/app/Application.java @@ -66,6 +66,7 @@ public class Application private static String glossaryFolderName; private static String spaceTemplatesFolderName; private static String contentTemplatesFolderName; + private static String emailTemplatesFolderName; private static String savedSearchesFolderName; /** @@ -323,6 +324,22 @@ public class Application return getContentTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context)); } + /** + * @return Returns the Email templates folder name + */ + public static String getEmailTemplatesFolderName(ServletContext context) + { + return getEmailTemplatesFolderName(WebApplicationContextUtils.getRequiredWebApplicationContext(context)); + } + + /** + * @return Returns the Email templates folder name + */ + public static String getEmailTemplatesFolderName(FacesContext context) + { + return getEmailTemplatesFolderName(FacesContextUtils.getRequiredWebApplicationContext(context)); + } + /** * @return Return the Saved Searches folder name */ @@ -634,6 +651,24 @@ public class Application return contentTemplatesFolderName; } + /** + * Returns the Email Templates folder name + * + * @param context The spring context + * @return The email folder name + */ + private static String getEmailTemplatesFolderName(WebApplicationContext context) + { + if (emailTemplatesFolderName == null) + { + ImporterBootstrap bootstrap = (ImporterBootstrap)context.getBean(BEAN_IMPORTER_BOOTSTRAP); + Properties configuration = bootstrap.getConfiguration(); + emailTemplatesFolderName = configuration.getProperty("spaces.templates.email.childname"); + } + + return emailTemplatesFolderName; + } + /** * Returns the Saved Searches folder name * diff --git a/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java b/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java index 16ce49a939..a71ccf360b 100644 --- a/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java +++ b/source/java/org/alfresco/web/bean/wizard/BaseActionWizard.java @@ -41,6 +41,8 @@ import org.alfresco.repo.action.executer.MoveActionExecuter; import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter; import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter; import org.alfresco.repo.action.executer.TransformActionExecuter; +import org.alfresco.repo.cache.ExpiringValueCache; +import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.service.cmr.action.ActionDefinition; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.dictionary.AspectDefinition; @@ -85,11 +87,16 @@ public abstract class BaseActionWizard extends AbstractWizardBean public static final String PROP_MESSAGE = "message"; public static final String PROP_SUBJECT = "subject"; public static final String PROP_TO = "to"; + public static final String PROP_FROM = "from"; + public static final String PROP_TEMPLATE = "template"; public static final String PROP_OBJECT_TYPE = "objecttype"; private static final Log logger = LogFactory.getLog(BaseActionWizard.class); private static final String IMPORT_ENCODING = "UTF-8"; + /** no selection marker for SelectItem lists */ + private static final String NO_SELECTION = "none"; + // new rule/action wizard specific properties protected boolean multiActionMode = false; protected String action; @@ -105,6 +112,8 @@ public abstract class BaseActionWizard extends AbstractWizardBean protected Map actionDescriptions; protected Map currentActionProperties; protected List objectTypes; + /** cache of email templates that last 10 seconds - enough for a couple of page refreshes */ + protected ExpiringValueCache> cachedTemplates = new ExpiringValueCache>(1000*10); /** * Initialises the wizard @@ -323,6 +332,17 @@ public abstract class BaseActionWizard extends AbstractWizardBean // add the subject for the email actionParams.put(MailActionExecuter.PARAM_SUBJECT, this.currentActionProperties.get(PROP_SUBJECT)); + + // add the from address + String from = Application.getClientConfig(FacesContext.getCurrentInstance()).getFromEmailAddress(); + actionParams.put(MailActionExecuter.PARAM_FROM, from); + + // add the template if one was selected by the user + String template = (String)this.currentActionProperties.get(PROP_TEMPLATE); + if (template != null && template.equals(NO_SELECTION) == false) + { + actionParams.put(MailActionExecuter.PARAM_TEMPLATE, new NodeRef(Repository.getStoreRef(), template)); + } } else if (this.action.equals(ImporterActionExecuter.NAME)) { @@ -911,4 +931,62 @@ public abstract class BaseActionWizard extends AbstractWizardBean return this.users; } + + /** + * @return the list of available Content Templates that can be applied to the current document. + */ + public List getTemplates() + { + List templates = cachedTemplates.get(); + if (templates == null) + { + // get the template from the special Content Templates folder + FacesContext context = FacesContext.getCurrentInstance(); + String xpath = Application.getRootPath(context) + "/" + + Application.getGlossaryFolderName(context) + "/" + + Application.getEmailTemplatesFolderName(context) + "//*"; + try + { + NodeRef rootNodeRef = this.nodeService.getRootNode(Repository.getStoreRef()); + NamespaceService resolver = Repository.getServiceRegistry(context).getNamespaceService(); + List results = this.searchService.selectNodes(rootNodeRef, xpath, null, resolver, false); + + templates = new ArrayList(results.size() + 1); + if (results.size() != 0) + { + DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService(); + for (NodeRef ref : results) + { + if (nodeService.exists(ref) == true) + { + Node childNode = new Node(ref); + if (dd.isSubClass(childNode.getType(), ContentModel.TYPE_CONTENT)) + { + templates.add(new SelectItem(childNode.getId(), childNode.getName())); + } + } + } + + // make sure the list is sorted by the label + QuickSort sorter = new QuickSort(templates, "label", true, IDataContainer.SORT_CASEINSENSITIVE); + sorter.sort(); + } + } + catch (AccessDeniedException accessErr) + { + // ignore the result if we cannot access the root + } + + // add an entry (at the start) to instruct the user to select a template + if (templates == null) + { + templates = new ArrayList(1); + } + templates.add(0, new SelectItem(NO_SELECTION, Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template"))); + + cachedTemplates.put(templates); + } + + return templates; + } } diff --git a/source/web/jsp/wizard/create-action/action-email.jsp b/source/web/jsp/wizard/create-action/action-email.jsp index 90b8d505b6..f67cba1739 100644 --- a/source/web/jsp/wizard/create-action/action-email.jsp +++ b/source/web/jsp/wizard/create-action/action-email.jsp @@ -146,9 +146,12 @@ + onkeyup="javascript:checkButtonState();"/> * + + + : @@ -156,6 +159,19 @@ rows="5" cols="75" /> + + + + : + + <%-- Templates drop-down selector --%> + + + + + + + : diff --git a/source/web/jsp/wizard/new-rule/action-email.jsp b/source/web/jsp/wizard/new-rule/action-email.jsp index df9209bee5..44218ef0d0 100644 --- a/source/web/jsp/wizard/new-rule/action-email.jsp +++ b/source/web/jsp/wizard/new-rule/action-email.jsp @@ -126,15 +126,19 @@ + : + onkeyup="javascript:checkButtonState();"/> * + + + : @@ -142,6 +146,19 @@ rows="5" cols="75" /> + + + + : + + <%-- Templates drop-down selector --%> + + + + + + + : @@ -151,6 +168,7 @@ + <% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "white"); %>