fixing event passing

This commit is contained in:
Dennis Collinson 2012-05-22 15:08:31 -07:00
parent abc4843273
commit 1c342282b0
7 changed files with 46 additions and 23 deletions

View file

@ -22,7 +22,7 @@ app.pages.Stream = app.views.Base.extend({
this.streamView = new app.views.NewStream({ model : this.stream })
var interactions = this.interactionsView = new app.views.StreamInteractions()
this.on("frame:interacted", function(post){
this.stream.on("frame:interacted", function(post){
interactions.setInteractions(post)
})
}

View file

@ -122,7 +122,7 @@ app.views.InfScroll = app.views.Base.extend({
},
createPostView : function(post){
var postView = new this.postClass({ model: post });
var postView = new this.postClass({ model: post, stream: this.stream });
this.postViews.push(postView)
return postView
},

View file

@ -13,6 +13,11 @@ app.views.Post.SmallFrame = app.views.Post.extend({
'.embed-frame' : "oEmbedView"
},
initialize : function(options) {
this.stream = options.stream;
this.addStylingClasses()
},
oEmbedView : function(){
return new app.views.OEmbed({model : this.model})
},
@ -28,10 +33,6 @@ app.views.Post.SmallFrame = app.views.Post.extend({
})
},
initialize : function() {
this.addStylingClasses()
},
postRenderTemplate : function() {
this.addStylingClasses()
},

View file

@ -1,5 +1,4 @@
app.views.Post.StreamFrame = app.views.Base.extend({
className : "stream-frame",
templateName : "stream-frame",
@ -8,18 +7,19 @@ app.views.Post.StreamFrame = app.views.Base.extend({
".small-frame" : "smallFrameView"
},
initialize : function() {
this.smallFrameView = new app.views.Post.SmallFrame({model : this.model})
initialize : function(options) {
this.stream = options.stream
this.smallFrameView = new app.views.Post.SmallFrame({model : this.model, stream: this.stream})
},
events : _.extend({
'click .content' : 'triggerInteracted'
}, app.views.Post.SmallFrame.prototype.events),
triggerInteracted : function() {
app.page.trigger("frame:interacted", this.model)
this.stream.trigger("frame:interacted", this.model)
},
// this is some gross shit.
goToPost : $.noop
});

View file

@ -1,5 +1,4 @@
app.views.StreamInteractions = app.views.Base.extend({
id : "post-info",
subviews:{
@ -19,9 +18,5 @@ app.views.StreamInteractions = app.views.Base.extend({
this.feedback = new app.views.FeedbackActions({ model: model })
this.comments = new app.views.PostViewerReactions({ model: model.interactions })
this.newCommentView = new app.views.PostViewerNewComment({ model : model })
},
postRenderTemplate : function(){
console.log(this.$el)
}
});

View file

@ -0,0 +1,22 @@
describe("app.Pages.Stream", function(){
beforeEach(function(){
app.setPreload("stream", [factory.post().attributes])
this.page = new app.pages.Stream()
this.post = this.page.model.items.models[0]
expect(this.post).toBeTruthy()
})
describe("rendering", function(){
beforeEach(function(){
this.page.render()
})
context("clicking the content", function(){
it("triggers frame interacted", function(){
spyOn(this.post.interactions, "fetch").andReturn(new $.Deferred)
this.page.$('.canvas-frame:first .content').click()
expect(this.post.interactions.fetch).toHaveBeenCalled()
})
})
})
});

View file

@ -1,18 +1,23 @@
describe("app.views.Post.StreamFrame", function(){
beforeEach(function(){
this.post = factory.post()
this.view = new app.views.Post.StreamFrame({model : this.post})
app.page = new app.pages.Stream({model : new app.models.Stream()})
this.stream = new Backbone.Model
this.view = new app.views.Post.StreamFrame({model : this.post, stream: this.stream })
})
describe("rendering", function(){
beforeEach(function(){
this.view.render()
})
context("clicking the content", function(){
it("fetches the interaction pane", function(){
spyOn(this.post.interactions, "fetch").andReturn(new $.Deferred)
this.view.render()
it("triggers frame interacted", function(){
var spy = jasmine.createSpy()
this.stream.on("frame:interacted", spy)
this.view.$('.content').click()
expect(this.post.interactions.fetch).toHaveBeenCalled()
expect(spy).toHaveBeenCalledWith(this.post)
})
})
})
});