Created
April 6, 2016 20:29
-
-
Save VirtuosiMedia/2b881ef7e5fd7d1e4bc4ac56332ddd61 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
| /** | |
| * Renders the purchase table in the trade center. | |
| */ | |
| renderPurchaseTable: function(){ | |
| var self = jg.templates.commercial.tradeCenter(); | |
| var goods = self.getPurchaseGoods(); | |
| var template = _.f(); | |
| var table = jg.ui.table({id: 'purchaseTable'}); | |
| table.setHeaders({ | |
| 'name': 'name', | |
| 'average': 'averagePrice', | |
| 'price': 'price', | |
| 'quantity': 'quantity', | |
| 'type': 'bidType', | |
| 'action': 'action' | |
| }, jg.data.state.commercial.trade.purchaseTableSort, jg.data.state.commercial.trade.purchaseTableSortDirection, 'templates.commercial.tradeCenter.setPurchaseSort'); | |
| //Render each table row | |
| goods.each(function(good){ | |
| if (good.category === 'component'){ | |
| var name = _.e('button#' + good.id + 'Info', {text: good.name, 'data-modal': 'item', 'data-id': good.id}); | |
| } else { | |
| var name = _.e('button#' + good.id + 'Info', {text: good.name, 'data-modal': 'resource', 'data-id': good.id}); | |
| } | |
| if (good.price){ // This indicates a purchase bid exists for this good | |
| var price = _.e('span.numericAlign', {text: _.text.formatNumber(good.price, 2)}); | |
| var quantity = _.e('span.numericAlign', {text: _.text.formatNumber(good.quantity)}); | |
| var orderType = _.e('span', {text: _.translate(good.orderType)}); | |
| } else { | |
| var price = _.e('input.priceInput', { | |
| 'id': 'purchasePrice-' + good.id, | |
| 'type': 'text', | |
| 'data-good': good.id | |
| }); | |
| var quantity = _.e('input.quantityInput', { | |
| 'id': 'purchaseQuantity-' + good.id, | |
| 'type': 'text', | |
| 'data-good': good.id | |
| }); | |
| var orderTypes = { | |
| 'order': _.translate('order'), | |
| 'trade': _.translate('trade') | |
| }; | |
| var orderType = jg.ui.forms.select(orderTypes, 'order', { | |
| 'id': 'orderType-' + good.id, | |
| 'class': 'orderType', | |
| 'data-good': good.id | |
| }); | |
| } | |
| if (good.action === 'bid'){ | |
| var action = _.e('button.lockedButton.button.primary', { | |
| text: _.translate(good.action), | |
| 'data-good': good.id, | |
| 'data-goodCategory': good.category, | |
| 'data-action': 'purchase', | |
| 'data-click': 'templates.commercial.tradeCenter.placeBid' | |
| }); | |
| } else { | |
| var action = _.e('button.unlockedButton.button.secondary', { | |
| text: _.translate(good.action), | |
| 'data-good': good.id, | |
| 'data-action': 'purchase', | |
| 'data-click': 'templates.commercial.tradeCenter.cancelBid' | |
| }); | |
| } | |
| table.addRow([ | |
| name, | |
| _.e('span.numericAlign', {text: _.text.formatNumber(good.average)}), | |
| price, | |
| quantity, | |
| orderType, | |
| action | |
| ]); | |
| }); | |
| table.render().inject(template); | |
| _.$('tradeCenterPurchaseTable').empty().adopt(template); | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment