See all markets button working again

This commit is contained in:
Elisa Lupin-Jimenez 2017-08-09 17:28:05 -07:00
parent 69a13052ab
commit d3c76c99c2
3 changed files with 61 additions and 39 deletions

View file

@ -25,6 +25,7 @@ Rectangle {
id: checkoutRoot; id: checkoutRoot;
property string itemId; property string itemId;
property string itemHref;
// Style // Style
color: hifi.colors.baseGray; color: hifi.colors.baseGray;
Hifi.QmlCommerce { Hifi.QmlCommerce {
@ -234,6 +235,7 @@ Rectangle {
// "Cancel" button // "Cancel" button
HifiControlsUit.Button { HifiControlsUit.Button {
id: cancelButton;
color: hifi.buttons.black; color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark; colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top; anchors.top: parent.top;
@ -251,6 +253,8 @@ Rectangle {
// "Buy" button // "Buy" button
HifiControlsUit.Button { HifiControlsUit.Button {
property bool buyFailed: false;
id: buyButton;
color: hifi.buttons.black; color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark; colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top; anchors.top: parent.top;
@ -262,7 +266,11 @@ Rectangle {
width: parent.width/2 - anchors.rightMargin*2; width: parent.width/2 - anchors.rightMargin*2;
text: "Buy" text: "Buy"
onClicked: { onClicked: {
sendToScript({method: 'checkout_buyClicked', params: {success: commerce.buy(itemId, parseInt(itemPriceText.text))}}); if (buyFailed) {
sendToScript({method: 'checkout_cancelClicked', params: itemId});
} else {
sendToScript({method: 'checkout_buyClicked', success: commerce.buy(itemId, parseInt(itemPriceText.text)), itemId: itemId, itemHref: itemHref});
}
} }
} }
} }
@ -293,6 +301,13 @@ Rectangle {
itemNameText.text = message.params.itemName; itemNameText.text = message.params.itemName;
itemAuthorText.text = message.params.itemAuthor; itemAuthorText.text = message.params.itemAuthor;
itemPriceText.text = message.params.itemPrice; itemPriceText.text = message.params.itemPrice;
itemHref = message.params.itemHref;
buyButton.text = "Buy";
buyButton.buyFailed = false;
break;
case 'buyFailed':
buyButton.text = "Buy Failed";
buyButton.buyFailed = true;
break; break;
default: default:
console.log('Unrecognized message from marketplaces.js:', JSON.stringify(message)); console.log('Unrecognized message from marketplaces.js:', JSON.stringify(message));

View file

@ -93,24 +93,29 @@
}); });
} }
function buyButtonClicked(id, name, author, price) { function buyButtonClicked(id, name, author, price, href) {
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "CHECKOUT", type: "CHECKOUT",
itemId: id, itemId: id,
itemName: name, itemName: name,
itemAuthor: author, itemAuthor: author,
itemPrice: price itemPrice: price,
itemHref: href
})); }));
} }
function injectBuyButtonOnMainPage() { function injectBuyButtonOnMainPage() {
$('.grid-item').find('#price-or-edit').find('a').attr('href', '#'); $('.grid-item').find('#price-or-edit').find('a').each(function() {
$(this).attr('data-href', $(this).attr('href'));
$(this).attr('href', '#');
});
$('.grid-item').find('#price-or-edit').find('.price').text("BUY"); $('.grid-item').find('#price-or-edit').find('.price').text("BUY");
$('.grid-item').find('#price-or-edit').find('a').on('click', function () { $('.grid-item').find('#price-or-edit').find('a').on('click', function () {
buyButtonClicked($(this).closest('.grid-item').attr('data-item-id'), buyButtonClicked($(this).closest('.grid-item').attr('data-item-id'),
$(this).closest('.grid-item').find('.item-title').text(), $(this).closest('.grid-item').find('.item-title').text(),
$(this).closest('.grid-item').find('.creator').find('.value').text(), $(this).closest('.grid-item').find('.creator').find('.value').text(),
10); 10,
$(this).attr('data-href'));
}); });
} }
@ -137,13 +142,15 @@
function injectHiFiItemPageCode() { function injectHiFiItemPageCode() {
if (confirmAllPurchases) { if (confirmAllPurchases) {
var href = $('#side-info').find('.btn').attr('href');
$('#side-info').find('.btn').attr('href', '#'); $('#side-info').find('.btn').attr('href', '#');
$('#side-info').find('.btn').html('<span class="glyphicon glyphicon-download"></span>Buy Item '); $('#side-info').find('.btn').html('<span class="glyphicon glyphicon-download"></span>Buy Item ');
$('#side-info').find('.btn').on('click', function () { $('#side-info').find('.btn').on('click', function () {
buyButtonClicked(window.location.pathname.split("/")[3], buyButtonClicked(window.location.pathname.split("/")[3],
$('#top-center').find('h1').text(), $('#top-center').find('h1').text(),
$('#creator').find('.value').text(), $('#creator').find('.value').text(),
10); 10,
href);
}); });
} }
} }
@ -415,16 +422,18 @@
function onLoad() { function onLoad() {
EventBridge.scriptEventReceived.connect(function (message) { EventBridge.scriptEventReceived.connect(function (message) {
var parsedJsonMessage = JSON.parse(message);
if (message.slice(0, CAN_WRITE_ASSETS.length) === CAN_WRITE_ASSETS) { if (message.slice(0, CAN_WRITE_ASSETS.length) === CAN_WRITE_ASSETS) {
canWriteAssets = message.slice(-4) === "true"; canWriteAssets = message.slice(-4) === "true";
} else if (message.slice(0, CLARA_IO_CANCEL_DOWNLOAD.length) === CLARA_IO_CANCEL_DOWNLOAD) { } else if (message.slice(0, CLARA_IO_CANCEL_DOWNLOAD.length) === CLARA_IO_CANCEL_DOWNLOAD) {
cancelClaraDownload(); cancelClaraDownload();
} else if (parsedJsonMessage.type === "marketplaces") { } else {
if (parsedJsonMessage.action === "inspectionModeSetting") { var parsedJsonMessage = JSON.parse(message);
confirmAllPurchases = !!parsedJsonMessage.data;
injectCode(); if (parsedJsonMessage.type === "marketplaces") {
if (parsedJsonMessage.action === "inspectionModeSetting") {
confirmAllPurchases = !!parsedJsonMessage.data;
injectCode();
}
} }
} }
}); });

View file

@ -101,31 +101,14 @@
Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged); Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged);
function onMessage(message) { function onMessage(message) {
var parsedJsonMessage = JSON.parse(message);
if (parsedJsonMessage.type === "CHECKOUT") {
tablet.sendToQml({ method: 'updateCheckoutQML', params: parsedJsonMessage });
tablet.pushOntoStack(MARKETPLACE_CHECKOUT_QML_PATH);
} else if (parsedJsonMessage.type === "REQUEST_SETTING") {
tablet.emitScriptEvent(JSON.stringify({
type: "marketplaces",
action: "inspectionModeSetting",
data: Settings.getValue("inspectionMode", false)
}));
}
if (message === GOTO_DIRECTORY) { if (message === GOTO_DIRECTORY) {
tablet.gotoWebScreen(MARKETPLACES_URL, MARKETPLACES_INJECT_SCRIPT_URL); tablet.gotoWebScreen(MARKETPLACES_URL, MARKETPLACES_INJECT_SCRIPT_URL);
} } else if (message === QUERY_CAN_WRITE_ASSETS) {
if (message === QUERY_CAN_WRITE_ASSETS) {
tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets()); tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets());
} } else if (message === WARN_USER_NO_PERMISSIONS) {
if (message === WARN_USER_NO_PERMISSIONS) {
Window.alert(NO_PERMISSIONS_ERROR_MESSAGE); Window.alert(NO_PERMISSIONS_ERROR_MESSAGE);
} } else if (message.slice(0, CLARA_IO_STATUS.length) === CLARA_IO_STATUS) {
if (message.slice(0, CLARA_IO_STATUS.length) === CLARA_IO_STATUS) {
if (isDownloadBeingCancelled) { if (isDownloadBeingCancelled) {
return; return;
} }
@ -137,18 +120,26 @@
Window.updateMessageBox(messageBox, CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON); Window.updateMessageBox(messageBox, CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
} }
return; return;
} } else if (message.slice(0, CLARA_IO_DOWNLOAD.length) === CLARA_IO_DOWNLOAD) {
if (message.slice(0, CLARA_IO_DOWNLOAD.length) === CLARA_IO_DOWNLOAD) {
if (messageBox !== null) { if (messageBox !== null) {
Window.closeMessageBox(messageBox); Window.closeMessageBox(messageBox);
messageBox = null; messageBox = null;
} }
return; return;
} } else if (message === CLARA_IO_CANCELLED_DOWNLOAD) {
if (message === CLARA_IO_CANCELLED_DOWNLOAD) {
isDownloadBeingCancelled = false; isDownloadBeingCancelled = false;
} else {
var parsedJsonMessage = JSON.parse(message);
if (parsedJsonMessage.type === "CHECKOUT") {
tablet.sendToQml({ method: 'updateCheckoutQML', params: parsedJsonMessage });
tablet.pushOntoStack(MARKETPLACE_CHECKOUT_QML_PATH);
} else if (parsedJsonMessage.type === "REQUEST_SETTING") {
tablet.emitScriptEvent(JSON.stringify({
type: "marketplaces",
action: "inspectionModeSetting",
data: Settings.getValue("inspectionMode", false)
}));
}
} }
} }
@ -207,7 +198,14 @@
//tablet.popFromStack(); //tablet.popFromStack();
break; break;
case 'checkout_buyClicked': case 'checkout_buyClicked':
print("fromQml: " + JSON.stringify(message)); if (message.success === true) {
tablet.gotoWebScreen(message.itemHref);
Script.setTimeout(function () {
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL);
}, 100);
} else {
tablet.sendToQml({ method: 'buyFailed' });
}
//tablet.popFromStack(); //tablet.popFromStack();
break; break;
default: default: