Created
April 6, 2016 22:20
-
-
Save VirtuosiMedia/07dd5fc1ec8da282419261dc2c359abd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Locks in a purchase bid, but checks for errors first then rerenders the table and the resource panel. | |
* @param {HTMLObject} target The lock button. | |
*/ | |
placeBid: function(target){ | |
var good = target.get('data-good'); | |
var goodCategory = target.get('data-goodCategory'); | |
var priceInput = _.$('purchasePrice-' + good); | |
var quantityInput = _.$('purchaseQuantity-' + good); | |
var price = parseFloat(priceInput.value); | |
var quantity = parseInt(quantityInput.value); | |
var orderType = _.$('orderType-' + good).value; | |
var canOrder = true; | |
if ((!price) || (price <= 0)){ | |
priceInput.addClass('error'); | |
canOrder = false; | |
} else { | |
priceInput.removeClass('error'); | |
} | |
if ((!quantity) || (quantity <= 0)){ | |
quantityInput.addClass('error'); | |
canOrder = false; | |
} else { | |
quantityInput.removeClass('error'); | |
} | |
if (canOrder){ | |
var orderPlaced = jg.calculate.trade.placeTradeOrder(jg.data.state.holding, good, goodCategory, price, quantity, orderType); | |
if (orderPlaced){ | |
var template = jg.templates.commercial.tradeCenter(); | |
template.renderPurchaseTable(); | |
jg.templates.load.interface()['update' + jg.data.state.panel + 'Panel'](); | |
} else { | |
var title = _.translate('insufficientCreditsOrderTitle'); | |
var text = _.translate('insufficientCreditsOrderDescription'); | |
jg.templates.load.interface().triggerErrorModal(title, text); | |
} | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment