Skip to content

Instantly share code, notes, and snippets.

@regedarek
Created November 8, 2012 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regedarek/d7488043e654e9f313de to your computer and use it in GitHub Desktop.
Save regedarek/d7488043e654e9f313de to your computer and use it in GitHub Desktop.
Network.Views.ProviderUsedAction = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render', 'hasUsed', 'unUsed');
var self = this;
this.render();
},
events: {
'click .used' : 'used'
},
render: function() {
this.$el.html('<a class="used">I\'ve used them</a>');
return this;
},
used: function(event) {
event.preventDefault();
var self = this;
this.model = new Network.Models.Use({
service_provider_id: this.options.serviceProviderId,
category_id: this.options.categoryId,
categories: this.options.categories
});
this.$('a').text('procesing...');
this.model.save({}, { success: self.hasUsed });
},
hasUsed: function() {
this.$el.html('<span>You\'ve used them.</span> <a class="undo-used"><strong>undo</strong></a>');
this.$('.undo-used').on('click', this.unUsed);
this.useCategory = new Network.Views.UseCategory({
el: this.$el,
model: this.model,
categories: this.model.get('categories')
});
},
unUsed: function() {
this.model.destroy({ success: this.render });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment