Hi ,
Im trying to add a new action for a dialog , this is going to be email action
where user can supply email information as part of dialog and send an email
with the content of the page that was selected . Im pretty new to Magnolia so
Im not sure if I'am doing this correctly .
I created a new class based on SaveConfigDialogAction that basically executes
an email action. Here is the code below .
One thing I noticed is that this works perfectly fine in Pages browse toolbar
but when I add this to pages detail preview toolbar what I notice is that I
have to save the dialog first and then try again with my email dialog action .
I'm not sure why in the first case the content gets saved in the repository
before my method is called but not when I have the same dialog action for the
page detail preview which caused the email to fail since the node content
empty. Im new to Magnolia so any suggestion or best practices would help .
EmailConfigDialogAction
----------------------
public class EmailConfigDialogAction extends
AbstractAction<EmailConfigDialogActionDefinition> {
private static final Logger log =
LoggerFactory.getLogger(EmailConfigDialogAction.class);
protected final Item item;
protected final EditorValidator validator;
protected final EditorCallback callback;
private final EventBus subAppEventBus;
private CommandsManager commandsManager;
@Inject
public EmailConfigDialogAction(EmailConfigDialogActionDefinition
definition, Item item,final CommandsManager commandsManager, EditorValidator
validator, EditorCallback callback, final @Named(SubAppEventBus.NAME) EventBus
subAppEventBus) {
super(definition);
this.item = item;
this.validator = validator;
this.callback = callback;
this.subAppEventBus = subAppEventBus;
this.commandsManager = commandsManager;
}
public void execute() throws ActionExecutionException {
// First Validate
validator.showValidation(true);
if (validator.isValid()) {
subAppEventBus.fireEvent(new ItemEditedEvent(item));
callback.onSuccess(getDefinition().getName());
//custom method used to send content of the page
emailPage();
} else {
log.debug("Validation error(s) occurred. No save performed.");
}
}
/*
* Retrieves email address and page path and email this
*/
private void emailPage()
{
String path = "";
String emailTo= "";
String emailFrom ="";
String emailSubject = "";
String emailCC = "";
final JcrNodeAdapter itemChanged = (JcrNodeAdapter) item;
try {
path = itemChanged.getJcrItem().getPath();
emailTo =
itemChanged.getJcrItem().getProperty("toMail").getString();
emailFrom =
itemChanged.getJcrItem().getProperty("fromMail").getString();
emailSubject =
itemChanged.getJcrItem().getProperty("emailSubject").getString();
emailCC =
(itemChanged.getJcrItem().hasProperty("ccMail")?itemChanged.getJcrItem().getProperty("ccMail").getString():"");
log.info("Mailing Page:"+path);
log.info("path:"+path);
log.info("emailTo:"+emailTo);
log.info("emailFrom:"+emailFrom);
log.info("emailCC:"+emailCC);
log.info("emailSubject:"+emailSubject);
HashMap<String, Object> params = new HashMap<String,
Object>();
final Command command =
this.commandsManager.getCommand("sendMail");
params.put("templateFile",path);
params.put("type","magnolia");
params.put("contentType","html");
params.put("to",emailTo);
params.put("cc",emailCC);
params.put("from",emailFrom);
params.put("subject",emailSubject);
try {
commandsManager.executeCommand(command,params);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
EmailConfigDialogActionDefinition
-----------------------------
public class EmailConfigDialogActionDefinition extends
ConfiguredActionDefinition{
public EmailConfigDialogActionDefinition() {
setImplementationClass(EmailConfigDialogAction.class);
}
}
Dialog configuration
------------------
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="Email" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>mgnl:contentNode</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">
<sv:value>mix:lockable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>156ab4db-f958-4cda-ade2-7ebc2ab9dbc3</sv:value>
</sv:property>
<sv:property sv:name="class" sv:type="String">
<sv:value>com.apple.ist.coecms.newsletter.EmailConfigDialogActionDefinition</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="label" sv:type="String">
<sv:value>Send Mail</sv:value>
</sv:property>
<sv:property sv:name="mgnl:activationStatus" sv:type="Boolean">
<sv:value>false</sv:value>
</sv:property>
<sv:property sv:name="mgnl:created" sv:type="Date">
<sv:value>2012-06-18T13:22:25.362+02:00</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModified" sv:type="Date">
<sv:value>2013-08-10T23:30:44.696-07:00</sv:value>
</sv:property>
<sv:property sv:name="mgnl:lastModifiedBy" sv:type="String">
<sv:value>superuser</sv:value>
</sv:property>
</sv:node>
--
Context is everything:
http://forum.magnolia-cms.com/forum/thread.html?threadId=4e32b762-5ff6-4723-b610-8e62c0f34115
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------