IDEMPIERE-5482 - Field Style Scope HTML Element (#1572)

* IDEMPIERE-5482 - Field Style Scope HTML Element

* IDEMPIERE-5482 - implemented in report engine, removed the new field

* IDEMPIERE-5482 - add IsWrapWithSpan to AD_Style

* IDEMPIERE-5482 -  pr1572 patch
This commit is contained in:
Peter Takács 2023-04-11 16:22:10 +02:00 committed by GitHub
parent ea6c44b913
commit 89a093ca49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 214 additions and 40 deletions

View File

@ -0,0 +1,30 @@
-- IDEMPIERE-5482
SELECT register_migration_script('202304111343_IDEMPIERE-5482.sql') FROM dual;
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Apr 11, 2023, 1:43:46 PM CEST
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203805,0,0,'Y',TO_TIMESTAMP('2023-04-11 13:43:45','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-04-11 13:43:45','YYYY-MM-DD HH24:MI:SS'),100,'IsWrapWithSpan','Wrap With Span','Wrap content in Span and apply the Style to it.','Wrap With Span','D','8c87a12e-eded-48c5-89d4-7c49fd29f4fa')
;
-- Apr 11, 2023, 1:46:32 PM CEST
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,ColumnName,DefaultValue,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (215834,0,'Wrap With Span','Wrap content in Span and apply the Style to it.',200207,'IsWrapWithSpan','N',1,'N','N','Y','N','N',0,'N',20,0,0,'Y',TO_TIMESTAMP('2023-04-11 13:46:32','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-04-11 13:46:32','YYYY-MM-DD HH24:MI:SS'),100,203805,'Y','N','D','N','N','N','Y','5ca5f2d0-6f43-4643-b63d-6e299d20f869','Y',0,'N','N','N','N')
;
-- Apr 11, 2023, 1:46:36 PM CEST
ALTER TABLE AD_Style ADD IsWrapWithSpan CHAR(1) DEFAULT 'N' CHECK (IsWrapWithSpan IN ('Y','N')) NOT NULL
;
-- Apr 11, 2023, 1:46:55 PM CEST
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,XPosition,ColumnSpan) VALUES (207618,'Wrap With Span','Wrap content in Span and apply the Style to it.',200213,215834,'Y',1,70,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-04-11 13:46:55','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-04-11 13:46:55','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','7ee72596-5bcd-47ea-a2ad-b6631a969034','Y',50,2,2)
;
-- Apr 11, 2023, 1:47:29 PM CEST
UPDATE AD_Field SET IsDisplayed='Y', SeqNo=60, XPosition=2,Updated=TO_TIMESTAMP('2023-04-11 13:47:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207618
;
-- Apr 11, 2023, 1:47:29 PM CEST
UPDATE AD_Field SET IsDisplayed='Y', SeqNo=70, XPosition=5,Updated=TO_TIMESTAMP('2023-04-11 13:47:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204202
;

View File

@ -0,0 +1,27 @@
-- IDEMPIERE-5482
SELECT register_migration_script('202304111343_IDEMPIERE-5482.sql') FROM dual;
-- Apr 11, 2023, 1:43:46 PM CEST
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203805,0,0,'Y',TO_TIMESTAMP('2023-04-11 13:43:45','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-04-11 13:43:45','YYYY-MM-DD HH24:MI:SS'),100,'IsWrapWithSpan','Wrap With Span','Wrap content in Span and apply the Style to it.','Wrap With Span','D','8c87a12e-eded-48c5-89d4-7c49fd29f4fa')
;
-- Apr 11, 2023, 1:46:32 PM CEST
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,ColumnName,DefaultValue,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (215834,0,'Wrap With Span','Wrap content in Span and apply the Style to it.',200207,'IsWrapWithSpan','N',1,'N','N','Y','N','N',0,'N',20,0,0,'Y',TO_TIMESTAMP('2023-04-11 13:46:32','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-04-11 13:46:32','YYYY-MM-DD HH24:MI:SS'),100,203805,'Y','N','D','N','N','N','Y','5ca5f2d0-6f43-4643-b63d-6e299d20f869','Y',0,'N','N','N','N')
;
-- Apr 11, 2023, 1:46:36 PM CEST
ALTER TABLE AD_Style ADD COLUMN IsWrapWithSpan CHAR(1) DEFAULT 'N' CHECK (IsWrapWithSpan IN ('Y','N')) NOT NULL
;
-- Apr 11, 2023, 1:46:55 PM CEST
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,XPosition,ColumnSpan) VALUES (207618,'Wrap With Span','Wrap content in Span and apply the Style to it.',200213,215834,'Y',1,70,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-04-11 13:46:55','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-04-11 13:46:55','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','7ee72596-5bcd-47ea-a2ad-b6631a969034','Y',50,2,2)
;
-- Apr 11, 2023, 1:47:29 PM CEST
UPDATE AD_Field SET IsDisplayed='Y', SeqNo=60, XPosition=2,Updated=TO_TIMESTAMP('2023-04-11 13:47:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=207618
;
-- Apr 11, 2023, 1:47:29 PM CEST
UPDATE AD_Field SET IsDisplayed='Y', SeqNo=70, XPosition=5,Updated=TO_TIMESTAMP('2023-04-11 13:47:29','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=204202
;

View File

@ -22,7 +22,7 @@ import org.compiere.util.KeyNamePair;
/** Generated Interface for AD_Style
* @author iDempiere (generated)
* @version Release 10
* @version Release 11
*/
public interface I_AD_Style
{
@ -145,6 +145,19 @@ public interface I_AD_Style
*/
public boolean isActive();
/** Column name IsWrapWithSpan */
public static final String COLUMNNAME_IsWrapWithSpan = "IsWrapWithSpan";
/** Set Wrap With Span.
* Wrap content in Span and apply the Style to it.
*/
public void setIsWrapWithSpan (boolean IsWrapWithSpan);
/** Get Wrap With Span.
* Wrap content in Span and apply the Style to it.
*/
public boolean isWrapWithSpan();
/** Column name Name */
public static final String COLUMNNAME_Name = "Name";

View File

@ -22,7 +22,7 @@ import java.util.Properties;
/** Generated Model for AD_Style
* @author iDempiere (generated)
* @version Release 10 - $Id$ */
* @version Release 11 - $Id$ */
@org.adempiere.base.Model(table="AD_Style")
public class X_AD_Style extends PO implements I_AD_Style, I_Persistent
{
@ -30,7 +30,7 @@ public class X_AD_Style extends PO implements I_AD_Style, I_Persistent
/**
*
*/
private static final long serialVersionUID = 20221224L;
private static final long serialVersionUID = 20230411L;
/** Standard Constructor */
public X_AD_Style (Properties ctx, int AD_Style_ID, String trxName)
@ -42,6 +42,8 @@ public class X_AD_Style extends PO implements I_AD_Style, I_Persistent
setAD_Style_UU (null);
setEntityType (null);
// @SQL=SELECT CASE WHEN '@P|AdempiereSys:N@'='Y' THEN 'D' ELSE get_sysconfig('DEFAULT_ENTITYTYPE','U',0,0) END FROM Dual
setIsWrapWithSpan (false);
// N
setName (null);
} */
}
@ -56,6 +58,40 @@ public class X_AD_Style extends PO implements I_AD_Style, I_Persistent
setAD_Style_UU (null);
setEntityType (null);
// @SQL=SELECT CASE WHEN '@P|AdempiereSys:N@'='Y' THEN 'D' ELSE get_sysconfig('DEFAULT_ENTITYTYPE','U',0,0) END FROM Dual
setIsWrapWithSpan (false);
// N
setName (null);
} */
}
/** Standard Constructor */
public X_AD_Style (Properties ctx, String AD_Style_UU, String trxName)
{
super (ctx, AD_Style_UU, trxName);
/** if (AD_Style_UU == null)
{
setAD_Style_ID (0);
setAD_Style_UU (null);
setEntityType (null);
// @SQL=SELECT CASE WHEN '@P|AdempiereSys:N@'='Y' THEN 'D' ELSE get_sysconfig('DEFAULT_ENTITYTYPE','U',0,0) END FROM Dual
setIsWrapWithSpan (false);
// N
setName (null);
} */
}
/** Standard Constructor */
public X_AD_Style (Properties ctx, String AD_Style_UU, String trxName, String ... virtualColumns)
{
super (ctx, AD_Style_UU, trxName, virtualColumns);
/** if (AD_Style_UU == null)
{
setAD_Style_ID (0);
setAD_Style_UU (null);
setEntityType (null);
// @SQL=SELECT CASE WHEN '@P|AdempiereSys:N@'='Y' THEN 'D' ELSE get_sysconfig('DEFAULT_ENTITYTYPE','U',0,0) END FROM Dual
setIsWrapWithSpan (false);
// N
setName (null);
} */
}
@ -161,6 +197,29 @@ public class X_AD_Style extends PO implements I_AD_Style, I_Persistent
return (String)get_Value(COLUMNNAME_EntityType);
}
/** Set Wrap With Span.
@param IsWrapWithSpan Wrap content in Span and apply the Style to it.
*/
public void setIsWrapWithSpan (boolean IsWrapWithSpan)
{
set_Value (COLUMNNAME_IsWrapWithSpan, Boolean.valueOf(IsWrapWithSpan));
}
/** Get Wrap With Span.
@return Wrap content in Span and apply the Style to it.
*/
public boolean isWrapWithSpan()
{
Object oo = get_Value(COLUMNNAME_IsWrapWithSpan);
if (oo != null)
{
if (oo instanceof Boolean)
return ((Boolean)oo).booleanValue();
return "Y".equals(oo);
}
return false;
}
/** Set Name.
@param Name Alphanumeric identifier of the entity
*/

View File

@ -63,9 +63,11 @@ import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pdf.Document;
import org.adempiere.print.export.PrintDataExcelExporter;
import org.adempiere.print.export.PrintDataXLSXExporter;
import org.apache.ecs.MultiPartElement;
import org.apache.ecs.XhtmlDocument;
import org.apache.ecs.xhtml.a;
import org.apache.ecs.xhtml.script;
import org.apache.ecs.xhtml.span;
import org.apache.ecs.xhtml.style;
import org.apache.ecs.xhtml.table;
import org.apache.ecs.xhtml.tbody;
@ -994,29 +996,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
{
td td = new td();
tr.addElement(td);
//set style
int AD_FieldStyle_ID = item.getAD_FieldStyle_ID();
if(AD_FieldStyle_ID > 0) {
MStyle style = MStyle.get(Env.getCtx(), AD_FieldStyle_ID);
X_AD_StyleLine[] lines = style.getStyleLines();
StringBuilder styleBuilder = new StringBuilder();
for (X_AD_StyleLine line : lines)
{
String inlineStyle = line.getInlineStyle().trim();
String displayLogic = line.getDisplayLogic();
if (!Util.isEmpty(displayLogic))
{
if (!Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), displayLogic))
continue;
}
if (styleBuilder.length() > 0 && !(styleBuilder.charAt(styleBuilder.length()-1)==';'))
styleBuilder.append("; ");
styleBuilder.append(inlineStyle);
}
if(styleBuilder.length() > 0)
td.setStyle(styleBuilder.toString());
}
//
MStyle style = item.getAD_FieldStyle_ID() > 0 ? MStyle.get(Env.getCtx(), item.getAD_FieldStyle_ID()) : null;
Object obj = instanceAttributeColumn != null ? instanceAttributeColumn.getPrintDataElement(row)
: m_printData.getNodeByPrintFormatItemId(item.getAD_PrintFormatItem_ID());
if (obj == null || !isDisplayPFItem(item)){
@ -1122,15 +1102,40 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
href.addElement(Util.maskHTML(value));
if (cssPrefix != null)
href.setClass(cssPrefix + "-href");
// Set Style
if(style != null && style.isWrapWithSpan())
setStyle(href, style);
else
setStyle(td, style);
extension.extendIDColumn(row, td, href, pde);
} else {
td.addElement(Util.maskHTML(value));
// Set Style
if(style != null && style.isWrapWithSpan()) {
span span = new span();
setStyle(span, style);
span.addElement(Util.maskHTML(value));
td.addElement(span);
}
else {
setStyle(td, style);
td.addElement(Util.maskHTML(value));
}
}
}
else
{
td.addElement(Util.maskHTML(value));
// Set Style
if(style != null && style.isWrapWithSpan()) {
span span = new span();
setStyle(span, style);
span.addElement(Util.maskHTML(value));
td.addElement(span);
}
else {
setStyle(td, style);
td.addElement(Util.maskHTML(value));
}
}
if (cssPrefix != null)
{
@ -2764,4 +2769,28 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
instance.setReportType(type);
}
}
private void setStyle(MultiPartElement element, MStyle style) {
if (style == null || style.getAD_Style_ID() == 0)
return;
X_AD_StyleLine[] lines = style.getStyleLines();
StringBuilder styleBuilder = new StringBuilder();
for (X_AD_StyleLine line : lines)
{
String inlineStyle = line.getInlineStyle().trim();
String displayLogic = line.getDisplayLogic();
if (!Util.isEmpty(displayLogic))
{
if (!Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), displayLogic))
continue;
}
if (styleBuilder.length() > 0 && !(styleBuilder.charAt(styleBuilder.length()-1)==';'))
styleBuilder.append("; ");
styleBuilder.append(inlineStyle);
}
if(styleBuilder.length() > 0)
element.setStyle(styleBuilder.toString());
//
}
} // ReportEngine

View File

@ -38,7 +38,10 @@ import org.compiere.model.MStyle;
import org.compiere.util.Env;
import org.compiere.util.Evaluatee;
import org.compiere.util.KeyNamePair;
import org.zkoss.zhtml.Text;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Span;
/**
* List item renderer for Info Window list box.
@ -165,14 +168,15 @@ public class WInfoWindowListItemRenderer extends WListItemRenderer
return value;
}
});
if (styleStr != null && styleStr.startsWith(MStyle.SCLASS_PREFIX)) {
String sclass = styleStr.substring(MStyle.SCLASS_PREFIX.length());
listcell.setSclass(sclass);
} else if (style != null && styleStr.startsWith(MStyle.ZCLASS_PREFIX)) {
String zclass = styleStr.substring(MStyle.ZCLASS_PREFIX.length());
listcell.setZclass(zclass);
} else {
ZkCssHelper.appendStyle(listcell, styleStr);
if(style.isWrapWithSpan()) {
Span span = new Span();
span.appendChild(new Text(listcell.getValue()));
listcell.setLabel(null);
listcell.appendChild(span);
setStyle(span, styleStr);
}
else {
setStyle(listcell, styleStr);
}
}
}
@ -182,4 +186,16 @@ public class WInfoWindowListItemRenderer extends WListItemRenderer
return listcell;
}
private void setStyle(HtmlBasedComponent component, String style) {
if (style != null && style.startsWith(MStyle.SCLASS_PREFIX)) {
String sclass = style.substring(MStyle.SCLASS_PREFIX.length());
component.setSclass(sclass);
} else if (style != null && style.startsWith(MStyle.ZCLASS_PREFIX)) {
String zclass = style.substring(MStyle.ZCLASS_PREFIX.length());
component.setZclass(zclass);
} else {
ZkCssHelper.appendStyle(component, style);
}
}
}