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)

This commit is contained in:
Carlos Ruiz 2016-08-15 11:33:27 +08:00
parent bef0a30f90
commit 139de8e0cd
6 changed files with 703 additions and 185 deletions

View File

@ -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
;

View File

@ -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
;

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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("<html>\n<body>\n<div class=\"help-content\">\n");
sb.append("<div class=\"help-content\">\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) + "<br>\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("<i>(" + Msg.getMsg(Env.getCtx(), "NotAvailable") + ")</i>");
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("<br><br>\n<b>" + nameMsg + "</b>");
translatedContent.append("<p><strong>" + nameMsg + "</strong></p>\n");
descMsg = tab.get_Translation("Description");
descMsg = tab.get_Translation("Description", false);
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = tab.get_Translation("Help");
helpMsg = tab.get_Translation("Help", false);
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\n" + helpMsg);
}
else {
if (tab != null && tab.getName() != null
&& tab.getName().length() != 0) {
sb.append("<br><br>\n<b>" + tab.getName() + "</b>");
if (tab.getDescription() != null
&& tab.getDescription().length() != 0)
sb.append("<br><br>\n<i>" + tab.getDescription()
+ "</i>");
if (tab.getHelp() != null
&& tab.getHelp().length() != 0)
sb.append("<br><br>\n" + tab.getHelp());
translatedContent.append("<p>" + helpMsg + "</p>\n");
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
}
if (tab != null && tab.getName() != null
&& tab.getName().length() != 0)
baseContent.append("<p><strong>" + tab.getName() + "</strong></p>\n");
if (tab.getDescription() != null
&& tab.getDescription().length() != 0)
baseContent.append("<p><em>" + tab.getDescription() + "</em></p>\n");
if (tab.getHelp() != null
&& tab.getHelp().length() != 0)
baseContent.append("<p>" + tab.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<br><br>\n<b>" + nameMsg + "</b>");
translatedContent.append("<p><strong>" + nameMsg + "</strong></p>\n");
descMsg = process.get_Translation("Description");
descMsg = process.get_Translation("Description", false);
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = process.get_Translation("Help");
helpMsg = process.get_Translation("Help", false);
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\n" + helpMsg);
translatedContent.append("<p>" + helpMsg + "</p>\n");
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
} else {
}
if (process != null && process.getName() != null
&& process.getName().length() != 0)
sb.append("<br><br>\n<b>" + process.getName() + "</b>");
if (process != null && process.getName() != null
&& process.getName().length() != 0)
baseContent.append("<p><strong>" + process.getName() + "</strong></p>\n");
if (process.getDescription() != null
&& process.getDescription().length() != 0)
sb.append("<br><br>\n<i>" + process.getDescription()
+ "</i>");
if (process.getHelp() != null
&& process.getHelp().length() != 0)
sb.append("<br><br>\n" + process.getHelp());
if (process.getDescription() != null
&& process.getDescription().length() != 0)
baseContent.append("<p><em>" + process.getDescription() + "</em></p>\n");
if (process.getHelp() != null
&& process.getHelp().length() != 0)
baseContent.append("<p>" + process.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<br><br>\n<b>" + nameMsg + "</b>");
translatedContent.append("<p><strong>" + nameMsg + "</strong></p>\n");
descMsg = form.get_Translation("Description");
descMsg = form.get_Translation("Description",false);
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = form.get_Translation("Help");
helpMsg = form.get_Translation("Help",false);
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\n" + helpMsg);
translatedContent.append("<p>" + helpMsg + "</p>\n");
} else {
if (form != null && form.getName() != null
&& form.getName().length() != 0) {
sb.append("<br><br>\n<b>" + form.getName() + "</b>");
if (form.getDescription() != null
&& form.getDescription().length() != 0)
sb.append("<br><br>\n<i>" + form.getDescription()
+ "</i>");
if (form.getHelp() != null
&& form.getHelp().length() != 0)
sb.append("<br><br>\n" + form.getHelp());
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
}
if (form != null && form.getName() != null
&& form.getName().length() != 0)
baseContent.append("<p><strong>" + form.getName() + "</strong></p>\n");
if (form.getDescription() != null
&& form.getDescription().length() != 0)
baseContent.append("<p><em>" + form.getDescription() + "</em></p>\n");
if (form.getHelp() != null
&& form.getHelp().length() != 0)
baseContent.append("<p>" + form.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<br><br>\n<b>" + nameMsg + "</b>");
&& nameMsg.length() != 0)
translatedContent.append("<p><strong>" + nameMsg + "</strong></p>\n");
descMsg = info.get_Translation("Description");
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
helpMsg = info.get_Translation("Help");
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\n" + helpMsg);
} else {
if (info != null && info.getName() != null
&& info.getName().length() != 0)
sb.append("<br><br>\n<b>" + info.getName() + "</b>");
if (info.getDescription() != null
&& info.getDescription().length() != 0)
sb.append("<br><br>\n<i>" + info.getDescription()
+ "</i>");
if (info.getHelp() != null
&& info.getHelp().length() != 0)
sb.append("<br><br>\n" + info.getHelp());
descMsg = info.get_Translation("Description",false);
if (descMsg != null && descMsg.length() != 0)
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = info.get_Translation("Help",false);
if (helpMsg != null && helpMsg.length() != 0)
translatedContent.append("<p>" + helpMsg + "</p>\n");
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
}
if (info != null && info.getName() != null
&& info.getName().length() != 0)
baseContent.append("<p><strong>" + info.getName() + "</strong></p>\n");
if (info.getDescription() != null
&& info.getDescription().length() != 0)
baseContent.append("<p><em>" + info.getDescription() + "</em></p>\n");
if (info.getHelp() != null
&& info.getHelp().length() != 0)
baseContent.append("<p>" + info.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<p><strong>" + nameMsg + "</strong></p>\n");
boolean trl = !Env.getLoginLanguage(Env.getCtx()).isBaseLanguage();
nameMsg = workflow.getName(trl);
if (workflow != null && nameMsg != null
&& nameMsg.length() != 0) {
sb.append("<br><br>\n<b>" + nameMsg + "</b>");
descMsg = workflow.getDescription(trl);
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
helpMsg = workflow.getHelp(trl);
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\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("<br><br>\n<b>" + nameMsg + "</b>");
descMsg = task.get_Translation("Description");
descMsg = workflow.get_Translation("Description",false);
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = task.get_Translation("Help");
helpMsg = workflow.get_Translation("Help", false);
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\n" + helpMsg);
translatedContent.append("<p>" + helpMsg + "</p>\n");
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
}
} else {
if (workflow != null && workflow.getName() != null
&& workflow.getName().length() != 0)
baseContent.append("<p><strong>" + workflow.getName() + "</strong></p>\n");
if (workflow.getDescription() != null
&& workflow.getDescription().length() != 0)
baseContent.append("<p><em>" + workflow.getDescription() + "</em></p>\n");
if (workflow.getHelp() != null
&& workflow.getHelp().length() != 0)
baseContent.append("<p>" + workflow.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<p><strong>" + nameMsg + "</strong></p>\n");
descMsg = task.get_Translation("Description",false);
if (descMsg != null && descMsg.length() != 0)
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = task.get_Translation("Help",false);
if (helpMsg != null && helpMsg.length() != 0)
translatedContent.append("<p>" + helpMsg + "</p>\n");
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
}
if (task != null && task.getName() != null
&& task.getName().length() != 0) {
sb.append("<br><br>\n<b>" + task.getName() + "</b>");
if (task.getDescription() != null
&& task.getDescription().length() != 0)
sb.append("<br><br>\n<i>" + task.getDescription()
+ "</i>");
if (task.getHelp() != null
&& task.getHelp().length() != 0)
sb.append("<br><br>\n" + task.getHelp());
&& task.getName().length() != 0)
baseContent.append("<p><strong>" + task.getName() + "</strong></p>\n");
if (task.getDescription() != null
&& task.getDescription().length() != 0)
baseContent.append("<p><em>" + task.getDescription() + "</em></p>\n");
if (task.getHelp() != null
&& task.getHelp().length() != 0)
baseContent.append("<p>" + task.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<p><strong>" + nameMsg + "</strong></p>\n");
descMsg = node.get_Translation("Description",false);
if (descMsg != null && descMsg.length() != 0)
translatedContent.append("<p><em>" + descMsg + "</em></p>\n");
helpMsg = node.get_Translation("Help", false);
if (helpMsg != null && helpMsg.length() != 0)
translatedContent.append("<p>" + helpMsg + "</p>\n");
if (translatedContent.length() > 0)
{
translatedContent.insert(0, "<p>\n");
translatedContent.append("</p>");
}
}
if (node != null && node.getName() != null
&& node.getName().length() != 0)
baseContent.append("<p><strong>" + node.getName() + "</strong></p>\n");
if (node.getDescription() != null
&& node.getDescription().length() != 0)
baseContent.append("<p><em>" + node.getDescription() + "</em></p>\n");
if (node.getHelp() != null
&& node.getHelp().length() != 0)
baseContent.append("<p>" + node.getHelp() + "</p>\n");
if (baseContent.length() > 0)
{
baseContent.insert(0, "<p>\n");
baseContent.append("</p>");
}
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("<br><br>\n<b>" + nameMsg + "</b>");
descMsg = node.getDescription(trl);
if (descMsg != null && descMsg.length() != 0)
sb.append("<br><br>\n<i>" + descMsg + "</i>");
helpMsg = node.getHelp(trl);
if (helpMsg != null && helpMsg.length() != 0)
sb.append("<br><br>\n" + helpMsg);
}
}
else
{
translatedContent.append("<p><em>(" + Msg.getMsg(Env.getCtx(), "NotAvailable") + ")</em></p>");
baseContent.append("<p><em>(" + Msg.getMsg(Language.getBaseAD_Language(), "NotAvailable") + ")</em></p>");
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("</div>\n</body>\n</html>");
sb.append("</div>");
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();
}

View File

@ -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<Event> {
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<Event> {
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<Event> {
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<Event> {
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<Event> {
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<Event> {
}
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<Object> params = new ArrayList<Object>();
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<Object> params = new ArrayList<Object>();
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<Event> {
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<Event> {
.replace("</head>", "");
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);
}
}
}