From 52cb1dd8936277ad95fee4489c7b6b1af85cf153 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 28 Aug 2017 09:54:51 -0700 Subject: [PATCH] Correctly handle non-JSON items --- .../qml/hifi/commerce/checkout/Checkout.qml | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml index 7a14b367c1..280937cb2d 100644 --- a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml +++ b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml @@ -33,6 +33,7 @@ Rectangle { property double balanceAfterPurchase: 0; property bool alreadyOwned: false; property int itemPriceFull: 0; + property bool itemIsJson: true; // Style color: hifi.colors.baseGray; Hifi.QmlCommerce { @@ -506,7 +507,7 @@ Rectangle { horizontalAlignment: Text.AlignLeft; verticalAlignment: Text.AlignVCenter; } - // ZRF FIXME: MAKE DROPDOWN + // ZRF FIXME: MAKE DROPDOWN??? RalewayRegular { id: quantityText; text: "1"; @@ -556,7 +557,7 @@ Rectangle { verticalAlignment: Text.AlignVCenter; } RalewayRegular { - id:totalCostText; + id: totalCostText; text: "-- HFC"; // Text size size: totalCostTextLabel.size; @@ -661,7 +662,7 @@ Rectangle { // "Buy" button HifiControlsUit.Button { id: buyButton; - enabled: balanceAfterPurchase >= 0 && purchasesReceived && balanceReceived; + enabled: (balanceAfterPurchase >= 0 && purchasesReceived && balanceReceived) || !itemIsJson; color: hifi.buttons.blue; colorScheme: hifi.colorSchemes.dark; anchors.top: parent.top; @@ -670,12 +671,18 @@ Rectangle { anchors.right: parent.right; anchors.rightMargin: 20; width: parent.width/2 - anchors.rightMargin*2; - text: (purchasesReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Again" : "Buy"): "--"; + text: (itemIsJson ? ((purchasesReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Again" : "Buy"): "--") : "Use Now!"); onClicked: { - buyButton.enabled = false; - commerce.buy(itemId, itemPriceFull); + if (itemIsJson) { + buyButton.enabled = false; + commerce.buy(itemId, itemPriceFull); + } else { + if (urlHandler.canHandleUrl(itemHref)) { + urlHandler.handleUrl(itemHref); + } + } } - } + } // "Purchases" button HifiControlsUit.Button { @@ -939,8 +946,12 @@ Rectangle { itemAuthorText.text = message.params.itemAuthor; root.itemPriceFull = message.params.itemPrice; itemPriceText.text = (parseFloat(root.itemPriceFull/100).toFixed(2)) + " HFC"; - totalCostText.text = "" + (parseFloat(root.itemPriceFull/100).toFixed(2)) + " HFC"; + totalCostText.text = root.itemPriceFull === 0 ? "Free" : "" + (parseFloat(root.itemPriceFull/100).toFixed(2)) + " HFC"; itemHref = message.params.itemHref; + if (itemHref.indexOf('.json') === -1) { + root.itemIsJson = false; + } + setBuyText(); break; default: console.log('Unrecognized message from marketplaces.js:', JSON.stringify(message)); @@ -958,22 +969,26 @@ Rectangle { } function setBuyText() { - if (root.purchasesReceived && root.balanceReceived) { - if (root.balanceAfterPurchase < 0) { - if (root.alreadyOwned) { - buyText.text = "You do not have enough HFC to purchase this item again. Go to your Purchases to view the copy you own."; + if (root.itemIsJson) { + if (root.purchasesReceived && root.balanceReceived) { + if (root.balanceAfterPurchase < 0) { + if (root.alreadyOwned) { + buyText.text = "You do not have enough HFC to purchase this item again. Go to your Purchases to view the copy you own."; + } else { + buyText.text = "You do not have enough HFC to purchase this item."; + } } else { - buyText.text = "You do not have enough HFC to purchase this item."; + if (root.alreadyOwned) { + buyText.text = "You already own this item. If you buy it again, you'll be able to use multiple copies of it at once."; + } else { + buyText.text = "This item will be added to your Purchases, which can be accessed from Marketplace."; + } } } else { - if (root.alreadyOwned) { - buyText.text = "You already own this item. If you buy it again, you'll be able to use multiple copies of it at once."; - } else { - buyText.text = "This item will be added to your Purchases, which can be accessed from Marketplace."; - } + buyText.text = ""; } } else { - buyText.text = ""; + buyText.text = "This Marketplace item isn't an entity. It will not be added to your Purchases."; } }