From 139de8e0cd905855e1c47db5b0a65b7e9826330a Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 15 Aug 2016 11:33:27 +0800 Subject: [PATCH] 1006079 Ease edit of OnLine Context Help. Make processed, approved and save as tenant customization field readonly. Allow suggestion when context help is not available. / IDEMPIERE-3438 (integrating contribution from hengsin) --- .../oracle/201608121400_Ticket_1006079.sql | 53 ++ .../201608121400_Ticket_1006079.sql | 50 ++ .../src/org/compiere/model/MCtxHelp.java | 8 + .../src/org/compiere/model/PO.java | 35 +- .../adempiere/webui/panel/HelpController.java | 499 ++++++++++++------ .../webui/window/WCtxHelpSuggestion.java | 243 ++++++++- 6 files changed, 703 insertions(+), 185 deletions(-) create mode 100644 migration/i4.1z/oracle/201608121400_Ticket_1006079.sql create mode 100644 migration/i4.1z/postgresql/201608121400_Ticket_1006079.sql diff --git a/migration/i4.1z/oracle/201608121400_Ticket_1006079.sql b/migration/i4.1z/oracle/201608121400_Ticket_1006079.sql new file mode 100644 index 0000000000..4dd78fc7ce --- /dev/null +++ b/migration/i4.1z/oracle/201608121400_Ticket_1006079.sql @@ -0,0 +1,53 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Aug 12, 2016 3:56:58 PM MYT +-- 1006079 Ease edit of OnLine Context Help +UPDATE AD_Field SET SeqNo=90, IsDisplayed='Y', XPosition=2,Updated=TO_DATE('2016-08-12 15:56:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204258 +; + +-- Aug 12, 2016 3:56:58 PM MYT +UPDATE AD_Field SET SeqNo=100, IsDisplayed='Y', XPosition=5,Updated=TO_DATE('2016-08-12 15:56:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204259 +; + +-- Aug 12, 2016 3:56:59 PM MYT +UPDATE AD_Field SET SeqNo=110,Updated=TO_DATE('2016-08-12 15:56:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204262 +; + +-- Aug 12, 2016 3:56:59 PM MYT +UPDATE AD_Field SET SeqNo=120,Updated=TO_DATE('2016-08-12 15:56:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204261 +; + +-- Aug 12, 2016 3:56:59 PM MYT +UPDATE AD_Field SET SeqNo=130,Updated=TO_DATE('2016-08-12 15:56:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204260 +; + +-- Aug 12, 2016 3:57:40 PM MYT +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_DATE('2016-08-12 15:57:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204258 +; + +-- Aug 12, 2016 3:57:49 PM MYT +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_DATE('2016-08-12 15:57:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204259 +; + +UPDATE AD_Tab SET IsInsertRecord='N',Updated=TO_DATE('2016-08-12 17:51:27','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=200216 +; + +UPDATE AD_Field SET SeqNo=110, IsDisplayed='Y', XPosition=2,Updated=TO_DATE('2016-08-15 11:24:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204263 +; + +UPDATE AD_Field SET SeqNo=120,Updated=TO_DATE('2016-08-15 11:24:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204262 +; + +UPDATE AD_Field SET SeqNo=130,Updated=TO_DATE('2016-08-15 11:24:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204261 +; + +UPDATE AD_Field SET SeqNo=140,Updated=TO_DATE('2016-08-15 11:24:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204260 +; + +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_DATE('2016-08-15 11:25:25','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204263 +; + +SELECT register_migration_script('201608121400_Ticket_1006079.sql') FROM dual +; + diff --git a/migration/i4.1z/postgresql/201608121400_Ticket_1006079.sql b/migration/i4.1z/postgresql/201608121400_Ticket_1006079.sql new file mode 100644 index 0000000000..2ac4a12e89 --- /dev/null +++ b/migration/i4.1z/postgresql/201608121400_Ticket_1006079.sql @@ -0,0 +1,50 @@ +-- Aug 12, 2016 3:56:58 PM MYT +-- 1006079 Ease edit of OnLine Context Help +UPDATE AD_Field SET SeqNo=90, IsDisplayed='Y', XPosition=2,Updated=TO_TIMESTAMP('2016-08-12 15:56:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204258 +; + +-- Aug 12, 2016 3:56:58 PM MYT +UPDATE AD_Field SET SeqNo=100, IsDisplayed='Y', XPosition=5,Updated=TO_TIMESTAMP('2016-08-12 15:56:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204259 +; + +-- Aug 12, 2016 3:56:59 PM MYT +UPDATE AD_Field SET SeqNo=110,Updated=TO_TIMESTAMP('2016-08-12 15:56:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204262 +; + +-- Aug 12, 2016 3:56:59 PM MYT +UPDATE AD_Field SET SeqNo=120,Updated=TO_TIMESTAMP('2016-08-12 15:56:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204261 +; + +-- Aug 12, 2016 3:56:59 PM MYT +UPDATE AD_Field SET SeqNo=130,Updated=TO_TIMESTAMP('2016-08-12 15:56:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204260 +; + +-- Aug 12, 2016 3:57:40 PM MYT +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2016-08-12 15:57:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204258 +; + +-- Aug 12, 2016 3:57:49 PM MYT +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2016-08-12 15:57:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204259 +; + +UPDATE AD_Tab SET IsInsertRecord='N',Updated=TO_TIMESTAMP('2016-08-12 17:51:27','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Tab_ID=200216 +; + +UPDATE AD_Field SET SeqNo=110, IsDisplayed='Y', XPosition=2,Updated=TO_TIMESTAMP('2016-08-15 11:24:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204263 +; + +UPDATE AD_Field SET SeqNo=120,Updated=TO_TIMESTAMP('2016-08-15 11:24:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204262 +; + +UPDATE AD_Field SET SeqNo=130,Updated=TO_TIMESTAMP('2016-08-15 11:24:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204261 +; + +UPDATE AD_Field SET SeqNo=140,Updated=TO_TIMESTAMP('2016-08-15 11:24:56','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204260 +; + +UPDATE AD_Field SET IsReadOnly='Y',Updated=TO_TIMESTAMP('2016-08-15 11:25:25','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204263 +; + +SELECT register_migration_script('201608121400_Ticket_1006079.sql') FROM dual +; + diff --git a/org.adempiere.base/src/org/compiere/model/MCtxHelp.java b/org.adempiere.base/src/org/compiere/model/MCtxHelp.java index 05d0851590..496fba0de4 100644 --- a/org.adempiere.base/src/org/compiere/model/MCtxHelp.java +++ b/org.adempiere.base/src/org/compiere/model/MCtxHelp.java @@ -59,4 +59,12 @@ public class MCtxHelp extends X_AD_CtxHelp { super(ctx, rs, trxName); } // MCtxHelp + /* (non-Javadoc) + * @see org.compiere.model.PO#setClientOrg(int, int) + */ + @Override + public void setClientOrg(int AD_Client_ID, int AD_Org_ID) { + super.setClientOrg(AD_Client_ID, AD_Org_ID); + } + } // MCtxHelp diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index f68152093b..2e6be94e03 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -1882,7 +1882,7 @@ public abstract class PO public String get_Translation (String columnName, String AD_Language) { - return get_Translation(columnName, AD_Language, false); + return get_Translation(columnName, AD_Language, false, true); } /** @@ -1891,11 +1891,12 @@ public abstract class PO * If there is no translation then it fallback to original value. * @param columnName * @param AD_Language - * @boolean reload + * @param reload don't use cache, reload from DB + * @param fallback fallback to base if no translation found * @return translated string * @throws IllegalArgumentException if columnName or AD_Language is null or model has multiple PK */ - public String get_Translation (String columnName, String AD_Language, boolean reload) + public String get_Translation (String columnName, String AD_Language, boolean reload, boolean fallback) { // // Check if columnName, AD_Language is valid or table support translation (has 1 PK) => error @@ -1933,7 +1934,7 @@ public abstract class PO } // // If no translation found or not translated, fallback to original: - if (retValue == null) { + if (retValue == null && fallback) { Object val = get_Value(columnName); retValue = (val != null ? val.toString() : null); } @@ -1949,13 +1950,33 @@ public abstract class PO /** * Get Translation of column - * @param ctx context * @param columnName - * @return translation */ public String get_Translation (String columnName) { - return get_Translation(columnName, Env.getAD_Language(getCtx())); + return get_Translation(columnName, true); + } + + /** + * Get Translation of column + * @param columnName + * @param AD_Language + * @param reload don't use cache, reload from DB + */ + public String get_Translation (String columnName, String AD_Language, boolean reload) + { + return get_Translation(columnName, AD_Language, reload, true); + } + + /** + * Get Translation of column + * @param columnName + * @param fallback fallback to base if no translation found + * @return translation + */ + public String get_Translation (String columnName, boolean fallback) + { + return get_Translation(columnName, Env.getAD_Language(getCtx()), false, fallback); } /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java index d89cef3d84..d3b398c596 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java @@ -23,15 +23,21 @@ import org.adempiere.webui.window.WCtxHelpSuggestion; import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.model.I_AD_CtxHelpMsg; +import org.compiere.model.I_AD_InfoWindow; +import org.compiere.model.I_AD_WF_Node; +import org.compiere.model.I_AD_Workflow; import org.compiere.model.MCtxHelpMsg; import org.compiere.model.MForm; import org.compiere.model.MInfoWindow; import org.compiere.model.MProcess; import org.compiere.model.MTab; import org.compiere.model.MTask; +import org.compiere.model.PO; import org.compiere.model.X_AD_CtxHelp; import org.compiere.util.Env; +import org.compiere.util.Language; import org.compiere.util.Msg; +import org.compiere.util.Util; import org.compiere.wf.MWFNode; import org.compiere.wf.MWorkflow; import org.zkoss.zk.au.out.AuScript; @@ -227,11 +233,14 @@ public class HelpController pnlContextHelp.setTitle(ctxType.equals(X_AD_CtxHelp.CTXTYPE_Home) ? Msg.getMsg(Env.getCtx(), "GettingStarted") : Msg.getMsg(Env.getCtx(), "HowTo")); StringBuilder sb = new StringBuilder(); - sb.append("\n\n
\n"); + sb.append("
\n"); MCtxHelpMsg ctxHelpMsg = getCtxHelpMsg(ctxType, recordId); String helpMsg, nameMsg, descMsg; - + Component previousPopup = (Component) pnlContextHelp.removeAttribute("contextMenu"); + if (previousPopup != null) + previousPopup.detach(); + pnlContextHelp.setContext((Popup)null); if (ctxHelpMsg != null) { sb.append(stripHtml(ctxHelpMsg.get_Translation(I_AD_CtxHelpMsg.COLUMNNAME_MsgText), false) + "
\n"); @@ -242,234 +251,373 @@ public class HelpController } else { - Component popup = (Component) pnlContextHelp.removeAttribute("contextMenu"); - if (popup != null) - popup.detach(); - pnlContextHelp.setContext((Popup)null); - sb.append("(" + Msg.getMsg(Env.getCtx(), "NotAvailable") + ")"); - + StringBuilder baseContent = new StringBuilder(); + StringBuilder translatedContent = new StringBuilder(); + ContextHelpMenupopup popup = null; if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Tab)) { MTab tab = new MTab(Env.getCtx(), recordId, null); if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab")) { - nameMsg = tab.get_Translation("Name"); + nameMsg = tab.get_Translation("Name", false); if (tab != null && nameMsg != null && nameMsg.length() != 0) - sb.append("

\n" + nameMsg + ""); + translatedContent.append("

" + nameMsg + "

\n"); - descMsg = tab.get_Translation("Description"); + descMsg = tab.get_Translation("Description", false); if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); + translatedContent.append("

" + descMsg + "

\n"); - helpMsg = tab.get_Translation("Help"); + helpMsg = tab.get_Translation("Help", false); if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); - - } - - else { - if (tab != null && tab.getName() != null - && tab.getName().length() != 0) { - sb.append("

\n" + tab.getName() + ""); - - if (tab.getDescription() != null - && tab.getDescription().length() != 0) - sb.append("

\n" + tab.getDescription() - + ""); - - if (tab.getHelp() != null - && tab.getHelp().length() != 0) - sb.append("

\n" + tab.getHelp()); + translatedContent.append("

" + helpMsg + "

\n"); + + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); } + } + + if (tab != null && tab.getName() != null + && tab.getName().length() != 0) + baseContent.append("

" + tab.getName() + "

\n"); + + if (tab.getDescription() != null + && tab.getDescription().length() != 0) + baseContent.append("

" + tab.getDescription() + "

\n"); + + if (tab.getHelp() != null + && tab.getHelp().length() != 0) + baseContent.append("

" + tab.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); + } + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(tab, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); } else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Process)) { MProcess process = MProcess.get(Env.getCtx(), recordId); if (!Env.isBaseLanguage(Env.getCtx(), "AD_Process")) { - nameMsg = process.get_Translation("Name"); + nameMsg = process.get_Translation("Name", false); if (process != null && nameMsg != null && nameMsg.length() != 0) - sb.append("

\n" + nameMsg + ""); + translatedContent.append("

" + nameMsg + "

\n"); - descMsg = process.get_Translation("Description"); + descMsg = process.get_Translation("Description", false); if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); + translatedContent.append("

" + descMsg + "

\n"); - helpMsg = process.get_Translation("Help"); + helpMsg = process.get_Translation("Help", false); if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); + translatedContent.append("

" + helpMsg + "

\n"); + + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); + } - } else { + } - if (process != null && process.getName() != null - && process.getName().length() != 0) - sb.append("

\n" + process.getName() + ""); + if (process != null && process.getName() != null + && process.getName().length() != 0) + baseContent.append("

" + process.getName() + "

\n"); - if (process.getDescription() != null - && process.getDescription().length() != 0) - sb.append("

\n" + process.getDescription() - + ""); - - if (process.getHelp() != null - && process.getHelp().length() != 0) - sb.append("

\n" + process.getHelp()); + if (process.getDescription() != null + && process.getDescription().length() != 0) + baseContent.append("

" + process.getDescription() + "

\n"); + if (process.getHelp() != null + && process.getHelp().length() != 0) + baseContent.append("

" + process.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); } - + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(process, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); } else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Form)) { MForm form = new MForm(Env.getCtx(), recordId, null); if (!Env.isBaseLanguage(Env.getCtx(), "AD_Form")) { - nameMsg = form.get_Translation("Name"); - + nameMsg = form.get_Translation("Name",false); if (form != null && nameMsg != null && nameMsg.length() != 0) - sb.append("

\n" + nameMsg + ""); + translatedContent.append("

" + nameMsg + "

\n"); - descMsg = form.get_Translation("Description"); + descMsg = form.get_Translation("Description",false); if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); + translatedContent.append("

" + descMsg + "

\n"); - helpMsg = form.get_Translation("Help"); + helpMsg = form.get_Translation("Help",false); if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); + translatedContent.append("

" + helpMsg + "

\n"); - } else { - - if (form != null && form.getName() != null - && form.getName().length() != 0) { - sb.append("

\n" + form.getName() + ""); - - if (form.getDescription() != null - && form.getDescription().length() != 0) - sb.append("

\n" + form.getDescription() - + ""); - - if (form.getHelp() != null - && form.getHelp().length() != 0) - sb.append("

\n" + form.getHelp()); + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); } + } + if (form != null && form.getName() != null + && form.getName().length() != 0) + baseContent.append("

" + form.getName() + "

\n"); + + if (form.getDescription() != null + && form.getDescription().length() != 0) + baseContent.append("

" + form.getDescription() + "

\n"); + + if (form.getHelp() != null + && form.getHelp().length() != 0) + baseContent.append("

" + form.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); } + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(form, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); } else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Info)) { MInfoWindow info = new MInfoWindow(Env.getCtx(), recordId, null); - if (!Env.getLoginLanguage(Env.getCtx()).isBaseLanguage()) { - - nameMsg = info.get_Translation("Name"); + if (!Env.isBaseLanguage(Env.getCtx(), I_AD_InfoWindow.Table_Name)) { + nameMsg = info.get_Translation("Name",false); if (info != null && nameMsg != null - && nameMsg.length() != 0) { - sb.append("

\n" + nameMsg + ""); + && nameMsg.length() != 0) + translatedContent.append("

" + nameMsg + "

\n"); - descMsg = info.get_Translation("Description"); - if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); - - helpMsg = info.get_Translation("Help"); - if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); - - } else { - if (info != null && info.getName() != null - && info.getName().length() != 0) - sb.append("

\n" + info.getName() + ""); - - if (info.getDescription() != null - && info.getDescription().length() != 0) - sb.append("

\n" + info.getDescription() - + ""); - - if (info.getHelp() != null - && info.getHelp().length() != 0) - sb.append("

\n" + info.getHelp()); + descMsg = info.get_Translation("Description",false); + if (descMsg != null && descMsg.length() != 0) + translatedContent.append("

" + descMsg + "

\n"); + helpMsg = info.get_Translation("Help",false); + if (helpMsg != null && helpMsg.length() != 0) + translatedContent.append("

" + helpMsg + "

\n"); + + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); } } + + if (info != null && info.getName() != null + && info.getName().length() != 0) + baseContent.append("

" + info.getName() + "

\n"); + + if (info.getDescription() != null + && info.getDescription().length() != 0) + baseContent.append("

" + info.getDescription() + "

\n"); + + if (info.getHelp() != null + && info.getHelp().length() != 0) + baseContent.append("

" + info.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); + } + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(info, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); } - else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Workflow)) { - MWorkflow workflow = MWorkflow.get(Env.getCtx(), recordId); + else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Workflow)) + { + MWorkflow workflow = MWorkflow.get(Env.getCtx(), recordId); + if (!Env.isBaseLanguage(Env.getCtx(), I_AD_Workflow.Table_Name)) { + nameMsg = workflow.get_Translation("Name", false); + if (workflow != null && nameMsg != null + && nameMsg.length() != 0) + translatedContent.append("

" + nameMsg + "

\n"); - boolean trl = !Env.getLoginLanguage(Env.getCtx()).isBaseLanguage(); - - nameMsg = workflow.getName(trl); - - if (workflow != null && nameMsg != null - && nameMsg.length() != 0) { - sb.append("

\n" + nameMsg + ""); - - descMsg = workflow.getDescription(trl); - if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); - - helpMsg = workflow.getHelp(trl); - if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); - } - - } else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Task)) { - MTask task = new MTask(Env.getCtx(), recordId, null); - - if (!Env.getLoginLanguage(Env.getCtx()).isBaseLanguage()) { - - nameMsg = task.get_Translation("Name"); - - if (task != null && nameMsg != null - && nameMsg.length() != 0) { - sb.append("

\n" + nameMsg + ""); - - descMsg = task.get_Translation("Description"); + descMsg = workflow.get_Translation("Description",false); if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); + translatedContent.append("

" + descMsg + "

\n"); - helpMsg = task.get_Translation("Help"); + helpMsg = workflow.get_Translation("Help", false); if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); + translatedContent.append("

" + helpMsg + "

\n"); + + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); + } } - } else { + + if (workflow != null && workflow.getName() != null + && workflow.getName().length() != 0) + baseContent.append("

" + workflow.getName() + "

\n"); + if (workflow.getDescription() != null + && workflow.getDescription().length() != 0) + baseContent.append("

" + workflow.getDescription() + "

\n"); + + if (workflow.getHelp() != null + && workflow.getHelp().length() != 0) + baseContent.append("

" + workflow.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); + } + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(workflow, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); + + } + else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Task)) + { + MTask task = new MTask(Env.getCtx(), recordId, null); + + if (!Env.getLoginLanguage(Env.getCtx()).isBaseLanguage()) { + + nameMsg = task.get_Translation("Name",false); + if (task != null && nameMsg != null + && nameMsg.length() != 0) + translatedContent.append("

" + nameMsg + "

\n"); + + descMsg = task.get_Translation("Description",false); + if (descMsg != null && descMsg.length() != 0) + translatedContent.append("

" + descMsg + "

\n"); + + helpMsg = task.get_Translation("Help",false); + if (helpMsg != null && helpMsg.length() != 0) + translatedContent.append("

" + helpMsg + "

\n"); + + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); + } + } + if (task != null && task.getName() != null - && task.getName().length() != 0) { - sb.append("

\n" + task.getName() + ""); - - if (task.getDescription() != null - && task.getDescription().length() != 0) - sb.append("

\n" + task.getDescription() - + ""); - - if (task.getHelp() != null - && task.getHelp().length() != 0) - sb.append("

\n" + task.getHelp()); + && task.getName().length() != 0) + baseContent.append("

" + task.getName() + "

\n"); + + if (task.getDescription() != null + && task.getDescription().length() != 0) + baseContent.append("

" + task.getDescription() + "

\n"); + + if (task.getHelp() != null + && task.getHelp().length() != 0) + baseContent.append("

" + task.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); } + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(task, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); + } + else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Node)) + { + MWFNode node = MWFNode.get(Env.getCtx(), recordId); + + if (!Env.isBaseLanguage(Env.getCtx(), I_AD_WF_Node.Table_Name)) { + nameMsg = node.get_Translation("Name", false); + if (node != null && nameMsg != null + && nameMsg.length() != 0) + translatedContent.append("

" + nameMsg + "

\n"); + + descMsg = node.get_Translation("Description",false); + if (descMsg != null && descMsg.length() != 0) + translatedContent.append("

" + descMsg + "

\n"); + + helpMsg = node.get_Translation("Help", false); + if (helpMsg != null && helpMsg.length() != 0) + translatedContent.append("

" + helpMsg + "

\n"); + + if (translatedContent.length() > 0) + { + translatedContent.insert(0, "

\n"); + translatedContent.append("

"); + } + } + + if (node != null && node.getName() != null + && node.getName().length() != 0) + baseContent.append("

" + node.getName() + "

\n"); + + if (node.getDescription() != null + && node.getDescription().length() != 0) + baseContent.append("

" + node.getDescription() + "

\n"); + + if (node.getHelp() != null + && node.getHelp().length() != 0) + baseContent.append("

" + node.getHelp() + "

\n"); + + if (baseContent.length() > 0) + { + baseContent.insert(0, "

\n"); + baseContent.append("

"); + } + + sb.append(Util.isEmpty(translatedContent.toString()) ? baseContent.toString() : translatedContent.toString()); + + popup = new ContextHelpMenupopup(node, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); } - } else if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Node)) { - MWFNode node = MWFNode.get(Env.getCtx(), recordId); - - boolean trl = !Env.getLoginLanguage(Env.getCtx()).isBaseLanguage(); - - nameMsg = node.getName(trl); - - if (node != null && nameMsg != null - && nameMsg.length() != 0) { - sb.append("

\n" + nameMsg + ""); - - descMsg = node.getDescription(trl); - if (descMsg != null && descMsg.length() != 0) - sb.append("

\n" + descMsg + ""); - - helpMsg = node.getHelp(trl); - if (helpMsg != null && helpMsg.length() != 0) - sb.append("

\n" + helpMsg); - } - - } + else + { + translatedContent.append("

(" + Msg.getMsg(Env.getCtx(), "NotAvailable") + ")

"); + baseContent.append("

(" + Msg.getMsg(Language.getBaseAD_Language(), "NotAvailable") + ")

"); + sb.append(translatedContent.toString()); + popup = new ContextHelpMenupopup(null, baseContent.toString(), translatedContent.toString()); + pnlContextHelp.setAttribute("contextMenu", popup); + pnlContextHelp.setContext(popup); + popup.setPage(pnlContextHelp.getPage()); + } } - sb.append("
\n\n"); + sb.append("
"); htmlContextHelp.setContent(sb.toString()); } @@ -558,11 +706,25 @@ public class HelpController */ private static final long serialVersionUID = 5957266862632509358L; private MCtxHelpMsg ctxHelpMsg; + private PO po; + private String baseContent, translatedContent; + private ContextHelpMenupopup(MCtxHelpMsg ctxHelpMsg) { super(); this.ctxHelpMsg = ctxHelpMsg; + init(); + } + + private ContextHelpMenupopup(PO po, String baseContent, String translatedContent) { + this.po = po; + this.baseContent = baseContent; + this.translatedContent = translatedContent; + init(); + } + + private void init() { Menuitem item = new Menuitem(); - if (ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { + if (ctxHelpMsg != null && ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { item.setLabel(Msg.getMsg(Env.getCtx(), "edit")); } else { item.setLabel(Msg.getElement(Env.getCtx(), "AD_CtxHelpSuggestion_ID")); @@ -570,9 +732,14 @@ public class HelpController appendChild(item); item.addEventListener(Events.ON_CLICK, this); } + @Override public void onEvent(Event event) throws Exception { - WCtxHelpSuggestion suggestion = new WCtxHelpSuggestion(ctxHelpMsg); + WCtxHelpSuggestion suggestion = null; + if (ctxHelpMsg != null) + suggestion = new WCtxHelpSuggestion(ctxHelpMsg); + else + suggestion = new WCtxHelpSuggestion(po, baseContent, translatedContent); suggestion.setPage(this.getPage()); suggestion.doHighlighted(); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WCtxHelpSuggestion.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WCtxHelpSuggestion.java index 279e4252da..9d51e0e344 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WCtxHelpSuggestion.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WCtxHelpSuggestion.java @@ -3,14 +3,29 @@ */ package org.adempiere.webui.window; +import java.util.ArrayList; +import java.util.List; + import org.adempiere.webui.component.ConfirmPanel; import org.adempiere.webui.component.Window; import org.compiere.model.I_AD_CtxHelpMsg; +import org.compiere.model.MCtxHelp; import org.compiere.model.MCtxHelpMsg; import org.compiere.model.MCtxHelpSuggestion; +import org.compiere.model.MForm; +import org.compiere.model.MInfoWindow; +import org.compiere.model.MProcess; +import org.compiere.model.MTab; +import org.compiere.model.MTask; +import org.compiere.model.PO; +import org.compiere.model.X_AD_CtxHelp; import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; +import org.compiere.util.Trx; +import org.compiere.util.Util; +import org.compiere.wf.MWFNode; +import org.compiere.wf.MWorkflow; import org.zkforge.ckez.CKeditor; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; @@ -39,6 +54,12 @@ public class WCtxHelpSuggestion extends Window implements EventListener { private CKeditor helpTextbox; + private PO po; + + private String baseContent; + + private String translatedContent; + /** * default constructor */ @@ -47,6 +68,13 @@ public class WCtxHelpSuggestion extends Window implements EventListener { layout(); } + public WCtxHelpSuggestion(PO po, String baseContent, String translatedContent) { + this.po = po; + this.baseContent = baseContent; + this.translatedContent = translatedContent; + layout(); + } + private void layout() { Borderlayout borderlayout = new Borderlayout(); appendChild(borderlayout); @@ -77,7 +105,7 @@ public class WCtxHelpSuggestion extends Window implements EventListener { cell = new Cell(); cell.setWidth("85%"); cell.setAlign("left"); - cell.appendChild(new Label(ctxHelpMsg.getAD_CtxHelp().getName())); + cell.appendChild(new Label(ctxHelpMsg != null ? ctxHelpMsg.getAD_CtxHelp().getName() : getContextHelpName(po))); hlayout.appendChild(cell); vlayout.appendChild(hlayout); @@ -94,7 +122,7 @@ public class WCtxHelpSuggestion extends Window implements EventListener { helpTextbox = new CKeditor(); helpTextbox.setCustomConfigurationsPath("/js/ckeditor/config-min.js"); helpTextbox.setToolbar("MyToolbar"); - String msgText = ctxHelpMsg.get_Translation("MsgText"); + String msgText = ctxHelpMsg != null ? ctxHelpMsg.get_Translation("MsgText") : (Util.isEmpty(translatedContent) ? baseContent : translatedContent); msgText = removeHeaderTag(msgText); helpTextbox.setValue(msgText); helpTextbox.setWidth("99%"); @@ -123,7 +151,7 @@ public class WCtxHelpSuggestion extends Window implements EventListener { this.setAttribute(Window.MODE_KEY, Window.MODE_HIGHLIGHTED); this.setSizable(true); - if (ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { + if (ctxHelpMsg != null && ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { setTitle(Msg.getMsg(Env.getCtx(), "edit") + " " + Msg.getElement(Env.getCtx(), "AD_CtxHelpMsg_ID")); } else { setTitle(Msg.getElement(Env.getCtx(), "AD_CtxHelpSuggestion_ID")); @@ -140,21 +168,90 @@ public class WCtxHelpSuggestion extends Window implements EventListener { } private void onSave() { - if (ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { + String trxName = Trx.createTrxName(); + Trx trx = Trx.get(trxName, true); + try { + trx.start(); + onSave0(trx); + trx.commit(true); + if (ctxHelpMsg != null && ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { + FDialog.info(0, this, "Your changes have been saved."); + } else { + FDialog.info(0, this, "Your suggestions have been submitted for review"); + } + } catch (Exception e) { + trx.rollback(); + if (e instanceof RuntimeException) + throw (RuntimeException)e; + else + throw new RuntimeException(e); + } finally { + trx.close(); + } + } + + private void onSave0(Trx trx) { + if (ctxHelpMsg != null && ctxHelpMsg.getAD_Client_ID() == Env.getAD_Client_ID(Env.getCtx())) { if (Env.isBaseLanguage(Env.getCtx(), I_AD_CtxHelpMsg.Table_Name)) { ctxHelpMsg.setMsgText(helpTextbox.getValue()); - ctxHelpMsg.saveEx(); + ctxHelpMsg.saveEx(trx.getTrxName()); } StringBuilder update = new StringBuilder("UPDATE AD_CtxHelpMsg_Trl SET MsgText=? "); update.append("WHERE AD_CtxHelpMsg_ID=? AND AD_Client_ID=? AND AD_Language=? AND IsActive='Y' "); Object[] params = new Object[]{helpTextbox.getValue(), ctxHelpMsg.get_ID(), ctxHelpMsg.getAD_Client_ID(), Env.getAD_Language(Env.getCtx())}; - DB.executeUpdateEx(update.toString(), params, null); - FDialog.info(0, this, "Your changes have been saved."); + DB.executeUpdateEx(update.toString(), params, trx.getTrxName()); } else { - MCtxHelpSuggestion suggestion = new MCtxHelpSuggestion(Env.getCtx(), 0, null); + MCtxHelpSuggestion suggestion = new MCtxHelpSuggestion(Env.getCtx(), 0, trx.getTrxName()); suggestion.setClientOrg(0, 0); - suggestion.setAD_CtxHelp_ID(ctxHelpMsg.getAD_CtxHelp_ID()); - suggestion.setAD_CtxHelpMsg_ID(ctxHelpMsg.get_ID()); + if (ctxHelpMsg != null) { + suggestion.setAD_CtxHelp_ID(ctxHelpMsg.getAD_CtxHelp_ID()); + suggestion.setAD_CtxHelpMsg_ID(ctxHelpMsg.get_ID()); + } else { + MCtxHelp ctxHelp = new MCtxHelp(Env.getCtx(), 0, trx.getTrxName()); + setContextHelpInfo(po, ctxHelp); + ctxHelp.setClientOrg(0, 0); + ctxHelp.saveEx(); + + if (po != null) { + po.set_ValueOfColumn("AD_CtxHelp_ID", ctxHelp.getAD_CtxHelp_ID()); + po.saveEx(trx.getTrxName()); + } + + suggestion.setAD_CtxHelp_ID(ctxHelp.getAD_CtxHelp_ID()); + MCtxHelpMsg msg = new MCtxHelpMsg(Env.getCtx(), 0, trx.getTrxName()); + msg.setAD_CtxHelp_ID(ctxHelp.getAD_CtxHelp_ID()); + msg.setClientOrg(0, 0); + msg.setMsgText(baseContent); + msg.saveEx(); + suggestion.setAD_CtxHelpMsg_ID(msg.getAD_CtxHelpMsg_ID()); + if (!Util.isEmpty(translatedContent) && !Env.isBaseLanguage(Env.getCtx(), I_AD_CtxHelpMsg.Table_Name)) { + int id = DB.getSQLValueEx(trx.getTrxName(), "SELECT AD_CtxHelpMsg_ID FROM AD_CtxHelpMsg_Trl WHERE AD_CtxHelpMsg_ID=? AND AD_Client_ID=? " + + "AND IsActive='Y' AND AD_Language=?", msg.getAD_CtxHelpMsg_ID(), 0, Env.getAD_Language(Env.getCtx())); + if (id == msg.getAD_CtxHelpMsg_ID()) { + List params = new ArrayList(); + StringBuilder update = new StringBuilder("UPDATE AD_CtxHelpMsg_Trl SET MsgText=? "); + update.append("WHERE AD_CtxHelpMsg_ID=? AND AD_Language=? AND AD_Client_ID=?"); + params.add(translatedContent); + params.add(id); + params.add(Env.getAD_Language(Env.getCtx())); + params.add(0); + DB.executeUpdateEx(update.toString(), params.toArray(), trx.getTrxName()); + } else { + StringBuilder insert = new StringBuilder("Insert Into AD_CtxHelpMsg_Trl (AD_Client_ID, AD_Org_ID, AD_CtxHelpMsg_ID, IsActive, IsTranslated, AD_Language, MsgText,"); + insert.append("Created, CreatedBy, Updated, UpdatedBy, AD_CtxHelpMsg_Trl_UU)") + .append(" Values (?, ?, ?, 'Y', 'N', ?, ?, now(), ?, now(), ?, generate_uuid()) "); + List params = new ArrayList(); + params.add(0); + params.add(0); + params.add(msg.getAD_CtxHelpMsg_ID()); + params.add(Env.getAD_Language(Env.getCtx())); + params.add(translatedContent); + params.add(Env.getAD_User_ID(Env.getCtx())); + params.add(Env.getAD_User_ID(Env.getCtx())); + DB.executeUpdateEx(insert.toString(), params.toArray(), trx.getTrxName()); + } + } + } suggestion.setAD_Language(Env.getAD_Language(Env.getCtx())); suggestion.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); suggestion.setAD_UserClient_ID(Env.getAD_Client_ID(Env.getCtx())); @@ -163,8 +260,7 @@ public class WCtxHelpSuggestion extends Window implements EventListener { suggestion.setMsgText(helpTextbox.getValue()); suggestion.setIsSaveAsTenantCustomization(false); - suggestion.saveEx(); - FDialog.info(0, this, "Your suggestions have been submitted for review"); + suggestion.saveEx(); } this.detach(); } @@ -179,4 +275,127 @@ public class WCtxHelpSuggestion extends Window implements EventListener { .replace("", ""); return htmlString; } + + private String getContextHelpName(PO po) { + if (po == null) { + return "Home"; + } else if (po instanceof MTab) { + MTab tab = (MTab) po; + return tab.getAD_Window().getName() + " / " + tab.getName(); + } else if (po instanceof MProcess) { + MProcess process = (MProcess) po; + String name = process.getName(); + return "Report/Process " + name; + } else if (po instanceof MForm) { + MForm form = (MForm) po; + String name = form.getName(); + return "Form " + name; + } else if (po instanceof MWorkflow) { + MWorkflow wf = (MWorkflow) po; + String name = wf.getName(); + return "Workflow " + name; + } else if (po instanceof MInfoWindow) { + MInfoWindow info = (MInfoWindow) po; + String name = info.getName(); + return "Info " + name; + } else if (po instanceof MWFNode) { + MWFNode node = (MWFNode) po; + String name = "node"; + return node.getAD_Workflow().getName() + " / " + name; + } else if (po instanceof MTask) { + MTask task = (MTask) po; + String name = task.getName(); + return "Task " + name; + } else { + return po.get_ValueAsString("Name"); + } + } + + private void setContextHelpInfo(PO po, MCtxHelp ctxHelp) { + if (po == null) { + ctxHelp.setName("Home"); + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Home); + } else if (po instanceof MTab) { + MTab tab = (MTab) po; + String name = tab.getName(); + String fullName = tab.getAD_Window().getName() + " / " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + String lname = "Tab " + name; + if (lname.length() <= 60) { + ctxHelp.setName(lname); + } + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Tab); + } else if (po instanceof MProcess) { + MProcess process = (MProcess) po; + String name = process.getName(); + String fullName = "Report/Process " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + ctxHelp.setName(name); + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Process); + } else if (po instanceof MForm) { + MForm form = (MForm) po; + String name = form.getName(); + String fullName = "Form " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + ctxHelp.setName(name); + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Form); + } else if (po instanceof MWorkflow) { + MWorkflow wf = (MWorkflow) po; + String name = wf.getName(); + String fullName = "Workflow " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + ctxHelp.setName(name); + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Workflow); + } else if (po instanceof MInfoWindow) { + MInfoWindow info = (MInfoWindow) po; + String name = info.getName(); + String fullName = "Info " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + ctxHelp.setName(name); + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Info); + } else if (po instanceof MWFNode) { + MWFNode node = (MWFNode) po; + String name = "node"; + String fullName = node.getAD_Workflow().getName() + " / " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + ctxHelp.setName(name); + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Node); + } else if (po instanceof MTask) { + MTask task = (MTask) po; + String name = task.getName(); + String fullName = "Task " + name; + if (fullName.length() <= 60) { + ctxHelp.setName(fullName); + } else { + ctxHelp.setDescription(fullName); + ctxHelp.setName(name); + } + ctxHelp.setCtxType(X_AD_CtxHelp.CTXTYPE_Task); + } + } + }