From e6aca4f4b7ea95c07da2e2cc6dac44bd5f57dc1d Mon Sep 17 00:00:00 2001 From: Seak Chiew Lee Date: Thu, 14 Sep 2023 01:27:16 +0800 Subject: [PATCH] fix issue with renderring the email content item --- ...ontent_library_conditional_alternative.xml | 2 +- .../widgets/emailContentLibraryContent.cfc | 10 +++---- ...ontent_library_conditional_alternative.cfc | 2 +- services/ContentLibraryService.cfc | 27 +++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/forms/preside-objects/content_library_conditional_alternative.xml b/forms/preside-objects/content_library_conditional_alternative.xml index 64faaae..1176ee9 100644 --- a/forms/preside-objects/content_library_conditional_alternative.xml +++ b/forms/preside-objects/content_library_conditional_alternative.xml @@ -2,7 +2,7 @@
- +
diff --git a/handlers/widgets/emailContentLibraryContent.cfc b/handlers/widgets/emailContentLibraryContent.cfc index d7dc4cc..b02e229 100644 --- a/handlers/widgets/emailContentLibraryContent.cfc +++ b/handlers/widgets/emailContentLibraryContent.cfc @@ -5,16 +5,16 @@ component { private function index( event, rc, prc, args={} ) { var item = args.content_item ?: ""; - if ( contentLibraryService.contentHasAlternatives( item ) ) { - return renderViewlet( event="widgets.contentLibraryContent._nonCacheable", args=args ); + if ( contentLibraryService.emailContentHasAlternatives( item ) ) { + return renderViewlet( event="widgets.emailContentLibraryContent._nonCacheable", args=args ); } - return renderContent( "richeditor", contentLibraryService.getContent( item ) ); + return renderContent( "richeditor", contentLibraryService.getEmailContent( item ) ); } private function placeholder( event, rc, prc, args={} ) { var item = args.content_item ?: ""; - var itemLabel = renderLabel( "content_library_content", item ); + var itemLabel = renderLabel( "email_content_library_content", item ); return translateResource( uri="widgets.contentLibraryContent:placeholder", data=[ itemLabel ] ); } @@ -26,6 +26,6 @@ component { private function _nonCacheable( event, rc, prc, args={} ) { var item = args.content_item ?: ""; - return renderContent( "richeditor", contentLibraryService.getContent( item ) ); + return renderContent( "richeditor", contentLibraryService.getEmailContent( item ) ); } } diff --git a/preside-objects/email_content_library_conditional_alternative.cfc b/preside-objects/email_content_library_conditional_alternative.cfc index 28b38e9..66b6866 100644 --- a/preside-objects/email_content_library_conditional_alternative.cfc +++ b/preside-objects/email_content_library_conditional_alternative.cfc @@ -7,7 +7,7 @@ * @feature emailContentLibrary */ component { - property name="content_library_content" relationship="many-to-one" relatedto="content_library_content" required=true uniqueindexes="content|1" ondelete="cascade" cloneable=true adminRenderer="none" batcheditable=false; + property name="email_content_library_content" relationship="many-to-one" relatedto="email_content_library_content" required=true uniqueindexes="content|1" ondelete="cascade" cloneable=true adminRenderer="none" batcheditable=false; property name="condition" relationship="many-to-one" relatedto="rules_engine_condition" required=true uniqueindexes="content|2" cloneable=true adminViewGroup="system" sortorder=0 batcheditable=false; property name="content" type="string" dbtype="text" required=true adminRenderer="none" batcheditable=false widgetCategories="email" linkPickerCategory="email" toolbar="email"; diff --git a/services/ContentLibraryService.cfc b/services/ContentLibraryService.cfc index ba21688..c620d12 100644 --- a/services/ContentLibraryService.cfc +++ b/services/ContentLibraryService.cfc @@ -37,12 +37,39 @@ component { return record.content ?: ""; } + public string function getEmailContent( required string itemId ) { + var conditionService = _getRulesEngineConditionService(); + var conditionalAlternatives = $getPresideObject( "email_content_library_conditional_alternative" ).selectData( + filter = { email_content_library_content = arguments.itemId } + , selectFields = [ "condition", "content" ] + , orderBy = "sort_order" + ); + + for( var alternative in conditionalAlternatives ) { + if ( conditionService.evaluateCondition( alternative.condition, "webrequest" ) ) { + return alternative.content; + } + } + + var record = $getPresideObject( "email_content_library_content" ).selectData( + id = arguments.itemId + , selectFields = [ "content" ] + ); + return record.content ?: ""; + } + public boolean function contentHasAlternatives( required string itemId ) { return $getPresideObject( "content_library_conditional_alternative" ).dataExists( filter = { content_library_content = arguments.itemId } ); } + public boolean function emailContentHasAlternatives( required string itemId ) { + return $getPresideObject( "email_content_library_conditional_alternative" ).dataExists( + filter = { email_content_library_content = arguments.itemId } + ); + } + public void function validateRichContent( required string recordId , required string richContent