From 1493a310af6f9ae4b599fe5ca65bb91f0e9c4f9c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 7 Aug 2017 17:02:24 -0700 Subject: [PATCH] Beginning of stack stuff --- .../resources/qml/hifi/commerce/Checkout.qml | 9 ++-- scripts/system/marketplaces/marketplaces.js | 51 ++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/Checkout.qml b/interface/resources/qml/hifi/commerce/Checkout.qml index dcf659c78c..941846a484 100644 --- a/interface/resources/qml/hifi/commerce/Checkout.qml +++ b/interface/resources/qml/hifi/commerce/Checkout.qml @@ -240,7 +240,9 @@ Rectangle { anchors.leftMargin: 20; width: parent.width/2 - anchors.leftMargin*2; text: "Cancel" - //onClicked: deleteAttachment(root.attachment); + onClicked: { + sendToScript({method: 'checkout_cancelClicked'}); + } } // "Buy" button @@ -255,7 +257,9 @@ Rectangle { anchors.rightMargin: 20; width: parent.width/2 - anchors.rightMargin*2; text: "Buy" - //onClicked: deleteAttachment(root.attachment); + onClicked: { + sendToScript({method: 'checkout_buyClicked'}); + } } } // @@ -281,7 +285,6 @@ Rectangle { function fromScript(message) { switch (message.method) { case 'updateCheckoutQML': - console.log("ZRF:", JSON.stringify(message)); itemNameText.text = message.params.itemName; itemAuthorText.text = message.params.itemAuthor; itemPriceText.text = message.params.itemPrice; diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index b3020d1d82..503eb69cc3 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -131,7 +131,8 @@ } function onScreenChanged(type, url) { - onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL + onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL; + wireEventBridge(type === "QML" && url === MARKETPLACE_CHECKOUT_QML_PATH); // for toolbar mode: change button to active when window is first openend, false otherwise. marketplaceButton.editProperties({ isActive: onMarketplaceScreen }); if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) { @@ -154,4 +155,52 @@ Entities.canWriteAssetsChanged.disconnect(onCanWriteAssetsChanged); }); + + + // Function Name: wireEventBridge() + // + // Description: + // -Used to connect/disconnect the script's response to the tablet's "fromQml" signal. Set the "on" argument to enable or + // disable to event bridge. + // + // Relevant Variables: + // -hasEventBridge: true/false depending on whether we've already connected the event bridge. + var hasEventBridge = false; + function wireEventBridge(on) { + if (!tablet) { + print("Warning in wireEventBridge(): 'tablet' undefined!"); + return; + } + if (on) { + if (!hasEventBridge) { + tablet.fromQml.connect(fromQml); + hasEventBridge = true; + } + } else { + if (hasEventBridge) { + tablet.fromQml.disconnect(fromQml); + hasEventBridge = false; + } + } + } + + // Function Name: fromQml() + // + // Description: + // -Called when a message is received from Checkout.qml. The "message" argument is what is sent from the Checkout QML + // in the format "{method, params}", like json-rpc. + function fromQml(message) { + switch (message.method) { + case 'checkout_cancelClicked': + print('fromQml: ' + JSON.stringify(message)); + tablet.popFromStack(); + break; + case 'checkout_buyClicked': + tablet.popFromStack(); + break; + default: + print('Unrecognized message from Checkout.qml: ' + JSON.stringify(message)); + } + } + }()); // END LOCAL_SCOPE