Sha256: 9102834ee4b49aba68c2e64cb618b5a64feaeb10a53db9990c1c259bc0b1b1b7
Contents?: true
Size: 1.16 KB
Versions: 69
Compression:
Stored size: 1.16 KB
Contents
Spree.Views.Order.DetailsAdjustments = Backbone.View.extend({ initialize: function() { this.listenTo(this.model, "change", this.render); this.render() }, adjustmentTotals: function() { var totals = {}; var collection = this.collection ? this.collection.chain() : _.chain([this.model]); collection .map(function(item){ return item.get("adjustments") || [] }) .flatten(true) .each(function(adjustment){ var label = adjustment.label; /* Fixme: because this is done in JS, we only have floating point math */ totals[label] = (totals[label] || 0); totals[label] += Number(adjustment.amount); }); return totals; }, render: function() { var model = this.model; var tbody = this.$('tbody'); var adjustmentTotals = this.adjustmentTotals() tbody.empty(); _.each(adjustmentTotals, function(amount, label) { var html = HandlebarsTemplates["orders/details_adjustment_row"]({ label: label, amount: Spree.formatMoney(amount, model.get("currency")) }); tbody.append(html); }); this.$el.toggleClass("hidden", _.isEmpty(adjustmentTotals)); } })
Version data entries
69 entries across 69 versions & 2 rubygems