From aa31d6f7087c9108da9947098947f332d6cd8fd4 Mon Sep 17 00:00:00 2001 From: haszari Date: Thu, 14 Feb 2019 11:16:39 +1300 Subject: [PATCH] use attributes + DOM (not html snippet) for products empty state suggestions --- assets/js/admin/marketplace-suggestions.js | 136 +++++++++++++-------- 1 file changed, 87 insertions(+), 49 deletions(-) diff --git a/assets/js/admin/marketplace-suggestions.js b/assets/js/admin/marketplace-suggestions.js index 18782ed3780..283ef97d4dd 100644 --- a/assets/js/admin/marketplace-suggestions.js +++ b/assets/js/admin/marketplace-suggestions.js @@ -9,55 +9,54 @@ { slug: 'products-empty-header', context: 'products-list-empty-header', - content: '

Selling something different?

You can install extensions to sell all kinds of things!

' + title: 'Ready to start selling something awesome?', + copy: 'Create your first product, import your product data, or browse extensions' }, { slug: 'products-empty-memberships', context: 'products-list-empty-body', - 'show-if-installed': [ 'woocommerce-subscriptions' ], - content: '
' + - '

Memberships

' + - '

Give members access to restricted content or products

' + - 'From $149' + - '
' - }, - { - slug: 'products-empty-addons', - context: 'products-list-empty-body', - 'show-if-installed': [ - 'woocommerce-subscriptions', - 'woocommerce-memberships' - ], - content: '
' + - '

Product Add-Ons

' + - '

Offer add-ons like gift wrapping, special messages or other special options for your products.

' + - 'From $149' + - '
' - }, - { - slug: 'products-empty-product-bundles', - context: 'products-list-empty-body', - 'hide-if-installed': 'woocommerce-product-bundles', - content: '
' + - '

Product Bundles

' + - '

Offer customizable bundles and assembled products

' + - 'From $49' + - '
' - }, - { - slug: 'products-empty-composite-products', - context: 'products-list-empty-body', - content: '
' + - '

Composite Products

' + - '

Create and offer product kits with configurable components

' + - 'From $79' + - '
' - }, - { - slug: 'products-empty-more', - context: 'products-list-empty-body', - content: '

More Extensions

' + title: 'Selling something else?', + copy: 'Extensions allow you to sell other types of products including bookings, subscriptions, or memberships', + 'button-text': 'Browse extensions', + url: 'https://woocommerce.com/product-category/woocommerce-extensions/product-extensions/', }, + // { + // slug: 'products-empty-addons', + // context: 'products-list-empty-body', + // 'show-if-installed': [ + // 'woocommerce-subscriptions', + // 'woocommerce-memberships' + // ], + // content: '
' + + // '

Product Add-Ons

' + + // '

Offer add-ons like gift wrapping, special messages or other special options for your products.

' + + // 'From $149' + + // '
' + // }, + // { + // slug: 'products-empty-product-bundles', + // context: 'products-list-empty-body', + // 'hide-if-installed': 'woocommerce-product-bundles', + // content: '
' + + // '

Product Bundles

' + + // '

Offer customizable bundles and assembled products

' + + // 'From $49' + + // '
' + // }, + // { + // slug: 'products-empty-composite-products', + // context: 'products-list-empty-body', + // content: '
' + + // '

Composite Products

' + + // '

Create and offer product kits with configurable components

' + + // 'From $79' + + // '
' + // }, + // { + // slug: 'products-empty-more', + // context: 'products-list-empty-body', + // content: '

More Extensions

' + // }, { slug: 'products-list-enhancements-category', context: 'products-list-inline', @@ -67,6 +66,16 @@ } ]; + function renderLinkoutButton( url, buttonText ) { + var linkoutButton = document.createElement( 'a' ); + + linkoutButton.classList.add( 'button' ); + linkoutButton.setAttribute( 'href', url ); + linkoutButton.textContent = buttonText; + + return linkoutButton; + } + function renderTableBanner( title, url, buttonText ) { if ( ! title || ! url ) { return; @@ -91,17 +100,40 @@ var linkoutColumn = document.createElement( 'td' ); linkoutColumn.setAttribute( 'colspan', 4 ); linkoutColumn.classList.add( 'marketplace-list-linkout' ); - var linkoutButton = document.createElement( 'a' ); + var linkoutButton = renderLinkoutButton( url, buttonText ); linkoutColumn.append( linkoutButton ); - linkoutButton.classList.add( 'button' ); - linkoutButton.setAttribute( 'href', url ); - linkoutButton.textContent = buttonText; row.appendChild( linkoutColumn ); return row; } + function renderListItem( title, copy, url, buttonText ) { + if ( ! title || ! url ) { + return; + } + + if ( ! buttonText ) { + buttonText = 'Go'; + } + + var container = document.createElement( 'div' ); + container.classList.add( 'marketplace-list-container' ); + + var titleHeading = document.createElement( 'h4' ); + titleHeading.textContent = title; + container.appendChild( titleHeading ); + + var body = document.createElement( 'p' ); + body.textContent = copy; + container.appendChild( body ); + + var linkoutButton = renderLinkoutButton( url, buttonText ); + container.appendChild( linkoutButton ); + + return container; + } + var visibleSuggestions = []; function getRelevantPromotions( displayContext ) { @@ -139,7 +171,13 @@ // render the promo content for ( var i in promos ) { - $( this ).append( promos[ i ].content ); + var content = renderListItem( + promos[ i ].title, + promos[ i ].copy, + promos[ i ].url, + promos[ i ]['button-text'] + ); + $( this ).append( content ); visibleSuggestions.push( promos[i].context ); } } );