-
-
Save regedarek/d7488043e654e9f313de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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