IDEMPIERE-669 Zk: User Feedback Service. Make more extensible.

This commit is contained in:
Heng Sin Low 2013-04-02 21:01:58 +08:00
parent 2bfa8b0e03
commit e30f4dca4e
4 changed files with 76 additions and 54 deletions

View File

@ -676,6 +676,14 @@ public final class MLookup extends Lookup implements Serializable
return false; return false;
} }
/**
* @return lookup info
*/
public MLookupInfo getLookupInfo()
{
return m_info;
}
/************************************************************************** /**************************************************************************
* MLookup Loader * MLookup Loader
*/ */

View File

@ -75,12 +75,12 @@ public class FeedbackRequestWindow extends Window implements EventListener<Event
private static CLogger log = CLogger.getCLogger(FeedbackRequestWindow.class); private static CLogger log = CLogger.getCLogger(FeedbackRequestWindow.class);
private WTableDirEditor requestTypeField, priorityField, salesRepField; protected WTableDirEditor requestTypeField, priorityField, salesRepField;
private Textbox txtSummary; protected Textbox txtSummary;
private ConfirmPanel confirmPanel; protected ConfirmPanel confirmPanel;
private List<DataSource> attachments = new ArrayList<DataSource>(); protected List<DataSource> attachments = new ArrayList<DataSource>();
private Div attachmentBox; protected Div attachmentBox;
public FeedbackRequestWindow() { public FeedbackRequestWindow() {
@ -224,51 +224,7 @@ public class FeedbackRequestWindow extends Window implements EventListener<Event
if (salesRepField.getValue() == null || salesRepField.getValue().equals("0")) if (salesRepField.getValue() == null || salesRepField.getValue().equals("0"))
throw new WrongValueException(salesRepField.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory")); throw new WrongValueException(salesRepField.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
Trx trx = Trx.get(Trx.createTrxName("SaveNewRequest"), true); saveRequest();
try {
trx.start();
MRequest request = new MRequest(Env.getCtx(), 0, trx.getTrxName());
request.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
request.setR_RequestType_ID((Integer) requestTypeField.getValue());
request.setPriority((String) priorityField.getValue());
request.setSummary(txtSummary.getText());
request.setSalesRep_ID((Integer) salesRepField.getValue());
boolean success = request.save();
if (success)
{
MAttachment attachment = null;
for(DataSource ds : attachments)
{
if (attachment == null)
{
attachment = new MAttachment(Env.getCtx(), 0, request.get_TrxName());
attachment.setAD_Table_ID(request.get_Table_ID());
attachment.setRecord_ID(request.get_ID());
}
attachment.addEntry(ds.getName(), IOUtils.toByteArray(ds.getInputStream()));
}
if (attachment != null)
success = attachment.save();
if (success)
success = trx.commit();
}
if (success)
{
FDialog.info(0, null, Msg.getMsg(Env.getCtx(), "Saved"));
}
else
{
trx.rollback();
FDialog.error(0, this, Msg.getMsg(Env.getCtx(), "SaveError"));
}
} finally {
trx.close();
}
this.detach(); this.detach();
} }
@ -290,6 +246,59 @@ public class FeedbackRequestWindow extends Window implements EventListener<Event
} }
} }
protected void saveRequest() throws IOException {
Trx trx = Trx.get(Trx.createTrxName("SaveNewRequest"), true);
try {
trx.start();
MRequest request = createMRequest(trx);
boolean success = request.save();
if (success)
{
MAttachment attachment = null;
for(DataSource ds : attachments)
{
if (attachment == null)
{
attachment = new MAttachment(Env.getCtx(), 0, request.get_TrxName());
attachment.setAD_Table_ID(request.get_Table_ID());
attachment.setRecord_ID(request.get_ID());
}
attachment.addEntry(ds.getName(), IOUtils.toByteArray(ds.getInputStream()));
}
if (attachment != null)
success = attachment.save();
if (success)
success = trx.commit();
}
if (success)
{
FDialog.info(0, null, Msg.getMsg(Env.getCtx(), "Saved"));
}
else
{
trx.rollback();
FDialog.error(0, this, Msg.getMsg(Env.getCtx(), "SaveError"));
}
} finally {
trx.close();
}
}
protected MRequest createMRequest(Trx trx) {
MRequest request = new MRequest(Env.getCtx(), 0, trx.getTrxName());
request.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
request.setR_RequestType_ID((Integer) requestTypeField.getValue());
request.setPriority((String) priorityField.getValue());
request.setSummary(txtSummary.getText());
request.setSalesRep_ID((Integer) salesRepField.getValue());
return request;
}
public void addAttachment(DataSource dataSource, boolean removable) { public void addAttachment(DataSource dataSource, boolean removable) {
attachments.add(dataSource); attachments.add(dataSource);
AttachmentItem item = new AttachmentItem(dataSource, attachments, removable); AttachmentItem item = new AttachmentItem(dataSource, attachments, removable);

View File

@ -467,6 +467,11 @@ ContextMenuListener, IZoomableEditor
} }
} }
public Lookup getLookup()
{
return lookup;
}
private void onNewRecord() { private void onNewRecord() {
try try
{ {

View File

@ -62,7 +62,7 @@ public class DefaultFeedbackService implements IFeedbackService {
new CreateNewRequestAction(); new CreateNewRequestAction();
} }
private static class EmailSupportAction implements EventListener<Event>{ protected static class EmailSupportAction implements EventListener<Event>{
private boolean errorOnly; private boolean errorOnly;
@ -96,7 +96,7 @@ public class DefaultFeedbackService implements IFeedbackService {
showEmailDialog(imageBytes); showEmailDialog(imageBytes);
} }
private void showEmailDialog(byte[] imageBytes) { protected void showEmailDialog(byte[] imageBytes) {
DataSource ds = FeedbackManager.getLogAttachment(errorOnly); DataSource ds = FeedbackManager.getLogAttachment(errorOnly);
WEMailDialog dialog = new WEMailDialog( WEMailDialog dialog = new WEMailDialog(
@ -122,7 +122,7 @@ public class DefaultFeedbackService implements IFeedbackService {
} }
} }
private static class CreateNewRequestAction implements EventListener<Event>{ protected static class CreateNewRequestAction implements EventListener<Event>{
protected CreateNewRequestAction() { protected CreateNewRequestAction() {
SessionManager.getAppDesktop().getComponent().addEventListener("onCreateFeedbackRequest", this); SessionManager.getAppDesktop().getComponent().addEventListener("onCreateFeedbackRequest", this);
@ -152,7 +152,7 @@ public class DefaultFeedbackService implements IFeedbackService {
showRequestDialog(imageBytes); showRequestDialog(imageBytes);
} }
private void showRequestDialog(byte[] imageBytes) { protected void showRequestDialog(byte[] imageBytes) {
FeedbackRequestWindow window = new FeedbackRequestWindow(); FeedbackRequestWindow window = new FeedbackRequestWindow();
AEnv.showWindow(window); AEnv.showWindow(window);