Sha256: baa8d2f5d0b8d09c9e926b9c098109fc544aab6521756e52f7d5942ba8ea0a64

Contents?: true

Size: 1.68 KB

Versions: 6

Compression:

Stored size: 1.68 KB

Contents

Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
  tagName: 'tr',

  initialize: function(options) {
    this.stockLocationName = options.stockLocationName;
    this.editing = false;
    this.render();
  },

  events: {
    "click .edit": "onEdit",
    "click .submit": "onSubmit",
    "submit form": "onSubmit",
    "click .cancel": "onCancel"
  },

  template: HandlebarsTemplates['stock_items/stock_location_stock_item'],

  render: function() {
    var renderAttr = {
      stockLocationName: this.stockLocationName,
      editing: this.editing
    };
    _.extend(renderAttr, this.model.attributes);
    this.$el.attr("data-variant-id", this.model.get('variant_id'));
    this.$el.html(this.template(renderAttr));
    return this;
  },

  onEdit: function(ev) {
    ev.preventDefault();
    this.editing = true;
    this.render();
  },

  onCancel: function(ev) {
    ev.preventDefault();
    this.model.set(this.model.previousAttributes());
    this.editing = false;
    this.render();
  },

  onSuccess: function() {
    this.editing = false;
    this.render();
    show_flash("success", Spree.translations.updated_successfully);
  },

  onError: function(model, response, options) {
    show_flash("error", response.responseText);
  },

  onSubmit: function(ev) {
    ev.preventDefault();
    var backorderable = this.$('[name=backorderable]').prop("checked");
    var countOnHand = parseInt(this.$("input[name='count_on_hand']").val(), 10);

    this.model.set({
      count_on_hand: countOnHand,
      backorderable: backorderable
    });
    var options = {
      success: this.onSuccess.bind(this),
      error: this.onError.bind(this)
    };
    this.model.save({ force: true }, options);
  }
});

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_backend-2.5.2 app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js
solidus_backend-2.5.1 app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js
solidus_backend-2.5.0 app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js
solidus_backend-2.5.0.rc1 app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js
solidus_backend-2.5.0.beta2 app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js
solidus_backend-2.5.0.beta1 app/assets/javascripts/spree/backend/views/stock/edit_stock_item_row.js