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

Version Path
solidus_backend-2.10.5 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.10.3 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.10.2 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.6 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.8.6 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.10.1 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.5 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.10.0 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.4 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.6.6 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.7.4 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.8.5 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.3 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.2 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.10.0.beta1 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.7.3 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.6.5 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.5.2 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.1 app/assets/javascripts/spree/backend/views/order/details_adjustments.js
solidus_backend-2.9.0 app/assets/javascripts/spree/backend/views/order/details_adjustments.js