DG DH; dry-d up appending/prepending posts to the stream's collection
This commit is contained in:
parent
bc0c92ec64
commit
1804b19ccc
5 changed files with 23 additions and 23 deletions
|
|
@ -81,7 +81,7 @@
|
||||||
- for aspect in all_aspects
|
- for aspect in all_aspects
|
||||||
= aspect_dropdown_list_item(aspect, !all_aspects_selected?(selected_aspects) && selected_aspects.include?(aspect) )
|
= aspect_dropdown_list_item(aspect, !all_aspects_selected?(selected_aspects) && selected_aspects.include?(aspect) )
|
||||||
|
|
||||||
= status.submit t('.share'), :disabled => publisher_hidden_text.blank?, :disable_with => t('.posting'), :class => 'button creation', :tabindex => 2
|
= status.submit t('.share'), :disabled => publisher_hidden_text.blank?, :class => 'button creation', :tabindex => 2
|
||||||
|
|
||||||
.facebox_content
|
.facebox_content
|
||||||
#question_mark_pane
|
#question_mark_pane
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,9 @@ app.collections.Stream = Backbone.Collection.extend({
|
||||||
|
|
||||||
parse: function(resp){
|
parse: function(resp){
|
||||||
return resp.posts;
|
return resp.posts;
|
||||||
|
},
|
||||||
|
|
||||||
|
comparator : function(post) {
|
||||||
|
return -post.createdAt();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,8 @@ app.views.Feedback = app.views.StreamObject.extend({
|
||||||
if(window.confirm("Reshare " + this.model.baseAuthor().name + "'s post?")) {
|
if(window.confirm("Reshare " + this.model.baseAuthor().name + "'s post?")) {
|
||||||
var reshare = new app.models.Reshare();
|
var reshare = new app.models.Reshare();
|
||||||
reshare.save({root_guid : this.model.baseGuid()}, {
|
reshare.save({root_guid : this.model.baseGuid()}, {
|
||||||
success : function(data){
|
success : function(){
|
||||||
var newPost = new app.models.Post(data);
|
app.stream.collection.add(reshare.toJSON());
|
||||||
app.stream.collection.add(newPost, {silent : true});
|
|
||||||
app.stream.prependPost(newPost);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return reshare;
|
return reshare;
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,8 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
"aspect_ids" : serializedForm["aspect_ids[]"],
|
"aspect_ids" : serializedForm["aspect_ids[]"],
|
||||||
"photos" : serializedForm["photos[]"]
|
"photos" : serializedForm["photos[]"]
|
||||||
}, {
|
}, {
|
||||||
success : function(data) {
|
success : function() {
|
||||||
var newPost = new app.models.Post(data);
|
app.stream.collection.add(statusMessage.toJSON());
|
||||||
app.stream.collection.add(newPost, {silent : true});
|
|
||||||
app.stream.prependPost(newPost);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ app.views.Stream = Backbone.View.extend({
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.collection = this.collection || new app.collections.Stream;
|
this.collection = this.collection || new app.collections.Stream;
|
||||||
this.collection.bind("add", this.appendPost, this);
|
this.collection.bind("add", this.addPost, this);
|
||||||
|
|
||||||
this.publisher = new app.views.Publisher({collection : this.collection});
|
this.publisher = new app.views.Publisher({collection : this.collection});
|
||||||
|
|
||||||
|
|
@ -19,26 +19,30 @@ app.views.Stream = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
infScroll : function(options) {
|
infScroll : function(options) {
|
||||||
|
if(this.isLoading()) { return }
|
||||||
|
|
||||||
var $window = $(window);
|
var $window = $(window);
|
||||||
var distFromTop = $window.height() + $window.scrollTop();
|
var distFromTop = $window.height() + $window.scrollTop();
|
||||||
var distFromBottom = $(document).height() - distFromTop;
|
var distFromBottom = $(document).height() - distFromTop;
|
||||||
var bufferPx = 300;
|
var bufferPx = 300;
|
||||||
|
|
||||||
if(distFromBottom < bufferPx && !this._loading) {
|
if(distFromBottom < bufferPx) {
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
prependPost : function(post) {
|
isLoading : function(){
|
||||||
var postView = new app.views.Post({ model: post });
|
return !this._loading.isResolved();
|
||||||
$(this.el).prepend(postView.render().el);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
appendPost: function(post) {
|
addPost : function(post) {
|
||||||
var postView = new app.views.Post({ model: post });
|
var postView = new app.views.Post({ model: post });
|
||||||
$(this.el).append(postView.render().el);
|
|
||||||
|
$(this.el)[
|
||||||
|
(this.collection.at(0).id == post.id)
|
||||||
|
? "prepend"
|
||||||
|
: "append"
|
||||||
|
](postView.render().el);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -49,8 +53,6 @@ app.views.Stream = Backbone.View.extend({
|
||||||
href: this.collection.url(),
|
href: this.collection.url(),
|
||||||
id: "paginate"
|
id: "paginate"
|
||||||
}).text('Load more posts'));
|
}).text('Load more posts'));
|
||||||
|
|
||||||
this._loading = false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function(evt) {
|
render : function(evt) {
|
||||||
|
|
@ -59,9 +61,7 @@ app.views.Stream = Backbone.View.extend({
|
||||||
var self = this;
|
var self = this;
|
||||||
self.addLoader();
|
self.addLoader();
|
||||||
|
|
||||||
this._loading = true;
|
this._loading = self.collection.fetch({
|
||||||
|
|
||||||
self.collection.fetch({
|
|
||||||
add: true,
|
add: true,
|
||||||
success: $.proxy(this.collectionFetched, self)
|
success: $.proxy(this.collectionFetched, self)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue