Sha256: 531358662f5173c9de3eef05f2949961e0603bc003075d0ab127ec91ddbd363e

Contents?: true

Size: 1.46 KB

Versions: 137

Compression:

Stored size: 1.46 KB

Contents

Spree.Views.Calculators.Tiered = Backbone.View.extend({
  initialize: function() {
    this.calculatorName = this.$('.js-tiers').data('calculator');
    this.tierFieldsTemplate = HandlebarsTemplates["promotions/calculators/fields/" + this.calculatorName];
    this.originalTiers = this.$('.js-tiers').data('original-tiers');
    this.formPrefix = this.$('.js-tiers').data('form-prefix');

    for (var base in this.originalTiers) {
      var value = this.originalTiers[base];
      this.$('.js-tiers').append(
        this.tierFieldsTemplate({
          baseField: {
            value: base
          },
          valueField: {
            name: this.tierInputName(base),
            value: value
          }
        })
      );
    }
  },

  events: {
    'click .js-add-tier': 'onAdd',
    'click .js-remove-tier': 'onRemove',
    'change .js-base-input': 'onChange'
  },

  tierInputName: function(base) {
    return this.formPrefix + "[calculator_attributes][preferred_tiers][" + base + "]";
  },

  onAdd: function(event) {
    event.preventDefault();
    this.$('.js-tiers').append(
      this.tierFieldsTemplate({
        valueField: {
          name: null
        }
      })
    );
  },

  onRemove: function(event) {
    event.preventDefault();
    $(event.target).parents('.tier').remove();
  },

  onChange: function(event) {
    var valueInput = $(event.target).parents('.tier').find('.js-value-input');
    valueInput.attr('name', this.tierInputName($(event.target).val()));
  }
});

Version data entries

137 entries across 137 versions & 3 rubygems

Version Path
solidus_legacy_promotions-4.4.1 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_legacy_promotions-4.4.0 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.1.5 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.1.4 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.1.3 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.0.4 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-3.4.6 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.0.3 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.1.2 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-3.4.5 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.2.1 app/assets/javascripts/spree/backend/views/calculators/tiered.js
solidus_backend-4.2.0 app/assets/javascripts/spree/backend/views/calculators/tiered.js