From c24270615e91224c47b05d9b23a182da7731e3bc Mon Sep 17 00:00:00 2001 From: muriloht Date: Thu, 7 Oct 2021 10:10:57 -0300 Subject: [PATCH] IDEMPIERE-1386 - email from attachments dialog (#909) * IDEMPIERE-1386 - email from attachments dialog * IDEMPIERE-1386 - fix mobile suggested by CarlosRuiz-globalqss --- .../adempiere/webui/panel/WAttachment.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java index cf5a99faec..8171f37295 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java @@ -26,6 +26,8 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Level; +import javax.activation.FileDataSource; + import org.adempiere.exceptions.AdempiereException; import org.adempiere.util.Callback; import org.adempiere.webui.AdempiereWebUI; @@ -39,17 +41,20 @@ import org.adempiere.webui.component.ListItem; import org.adempiere.webui.component.Listbox; import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Textbox; +import org.adempiere.webui.component.ToolBar; import org.adempiere.webui.component.Window; import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.util.ZKUpdateUtil; import org.adempiere.webui.window.FDialog; +import org.adempiere.webui.window.WEMailDialog; import org.adempiere.webui.window.WTextEditorDialog; import org.compiere.model.MAttachment; import org.compiere.model.MAttachmentEntry; import org.compiere.model.MSysConfig; import org.compiere.model.MTable; +import org.compiere.model.MUser; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Msg; @@ -113,12 +118,13 @@ public class WAttachment extends Window implements EventListener private Button bCancel = ButtonFactory.createNamedButton(ConfirmPanel.A_CANCEL, false, true); private Button bOk = ButtonFactory.createNamedButton(ConfirmPanel.A_OK, false, true); private Button bPreview = new Button(); + private Button bEmail = new Button(); private Panel previewPanel = new Panel(); private Borderlayout mainPanel = new Borderlayout(); - private Hbox toolBar = new Hbox(); + private ToolBar toolBar = new ToolBar(); private Hlayout confirmPanel = new Hlayout(); @@ -269,11 +275,12 @@ public class WAttachment extends Window implements EventListener cbContent.addEventListener(Events.ON_SELECT, this); toolBar.setAlign("center"); - toolBar.setPack("start"); + toolBar.setOverflowPopup(true); toolBar.appendChild(bLoad); toolBar.appendChild(bDelete); toolBar.appendChild(bSave); toolBar.appendChild(bSaveAllAsZip); + toolBar.appendChild(bEmail); toolBar.appendChild(cbContent); toolBar.appendChild(sizeLabel); @@ -317,6 +324,15 @@ public class WAttachment extends Window implements EventListener bDelete.addEventListener(Events.ON_CLICK, this); + bEmail.setEnabled(false); + if (ThemeManager.isUseFontIconForImage()) + bEmail.setIconSclass("z-icon-SendMail"); + else + bEmail.setImage(ThemeManager.getThemeResource("images/SendMail24.png")); + bLoad.setSclass("img-btn"); + bEmail.setTooltiptext(Msg.getMsg(Env.getCtx(), "EMail")); + bEmail.addEventListener(Events.ON_CLICK, this); + previewPanel.appendChild(preview); ZKUpdateUtil.setVflex(preview, "1"); ZKUpdateUtil.setHflex(preview, "1"); @@ -452,6 +468,7 @@ public class WAttachment extends Window implements EventListener bSave.setEnabled(true); bSaveAllAsZip.setEnabled(true); bDelete.setEnabled(true); + bEmail.setEnabled(true); if (autoPreviewList.contains(mimeType)) { @@ -492,6 +509,7 @@ public class WAttachment extends Window implements EventListener bSaveAllAsZip.setEnabled(false); bDelete.setEnabled(false); sizeLabel.setText(""); + bEmail.setEnabled(false); return false; } } @@ -640,6 +658,8 @@ public class WAttachment extends Window implements EventListener displayData(cbContent.getSelectedIndex(), true); } else if (e.getTarget() == bSaveAllAsZip) { saveAllAsZip(); + } else if(e.getTarget()==bEmail){ + sendMail(); } } // onEvent @@ -823,4 +843,19 @@ public class WAttachment extends Window implements EventListener Filedownload.save(media); } } + + private void sendMail() + { + int index = cbContent.getSelectedIndex(); + + MUser from = MUser.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx())); + String fileName = System.getProperty("java.io.tmpdir") + + System.getProperty("file.separator") + m_attachment.getEntryName(index); + File attachment = new File(fileName); + m_attachment.getEntryFile(index, attachment); + + WEMailDialog dialog = new WEMailDialog (Msg.getMsg(Env.getCtx(), "SendMail"), + from, "", "", "", new FileDataSource(attachment)); + AEnv.showWindow(dialog); + } }