Skip to content

Instantly share code, notes, and snippets.

@BDQ
Created April 2, 2012 15:54
Show Gist options
  • Save BDQ/2284585 to your computer and use it in GitHub Desktop.
Save BDQ/2284585 to your computer and use it in GitHub Desktop.
Spree.Admin.Views.Products.Edit = Backbone.View.extend({
events: {
'submit form': 'save',
'click input[value="Cancel"]': 'cancel',
'click a#delete_variant': 'delete_variant',
'change :input': 'changed'
},
render: function() {
this.$el.html(JST['admin/templates/products/edit']({ product: this.model }));
_.each(product.variants.models, function(variant){
if(!variant.get('is_master')){
variant_edit = new Spree.Admin.Views.Variants.Edit({model: variant});
this.$el.find('#variants').append(variant_edit.render().el);
}
},this);
return this;
},
save: function(event) {
if(event!=undefined){
event.preventDefault();
}
attrs = this.$el.find('form').serializeObject();
this.model.save(attrs, {
success: function(model, resp) {
window.location.href = '#products/' + model.get('permalink');
}
});
},
cancel: function(event) {
if(this.model.id==undefined){
Spree.Admin.products.remove(this.model);
}
window.location.href="#products";
},
delete_variant: function(event){
if(event!=undefined){ event.preventDefault(); }
var variant = this.model.variants.getByCid($(event.currentTarget).attr('data-variant-cid'));
this.$el.find('tr#' + variant.cid).hide();
this.model.variants.remove(variant);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment