Skip to content
Extraits de code Groupes Projets
Valider 1804b19c rédigé par danielgrippi's avatar danielgrippi Validation de Dennis Collinson
Parcourir les fichiers

DG DH; dry-d up appending/prepending posts to the stream's collection

parent bc0c92ec
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -81,7 +81,7 @@
- for aspect in all_aspects
= 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
#question_mark_pane
......
......@@ -13,5 +13,9 @@ app.collections.Stream = Backbone.Collection.extend({
parse: function(resp){
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?")) {
var reshare = new app.models.Reshare();
reshare.save({root_guid : this.model.baseGuid()}, {
success : function(data){
var newPost = new app.models.Post(data);
app.stream.collection.add(newPost, {silent : true});
app.stream.prependPost(newPost);
success : function(){
app.stream.collection.add(reshare.toJSON());
}
});
return reshare;
......
......@@ -27,10 +27,8 @@ app.views.Publisher = Backbone.View.extend({
"aspect_ids" : serializedForm["aspect_ids[]"],
"photos" : serializedForm["photos[]"]
}, {
success : function(data) {
var newPost = new app.models.Post(data);
app.stream.collection.add(newPost, {silent : true});
app.stream.prependPost(newPost);
success : function() {
app.stream.collection.add(statusMessage.toJSON());
}
});
......
......@@ -5,7 +5,7 @@ app.views.Stream = Backbone.View.extend({
initialize: function() {
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});
......@@ -19,26 +19,30 @@ app.views.Stream = Backbone.View.extend({
},
infScroll : function(options) {
if(this.isLoading()) { return }
var $window = $(window);
var distFromTop = $window.height() + $window.scrollTop();
var distFromBottom = $(document).height() - distFromTop;
var bufferPx = 300;
if(distFromBottom < bufferPx && !this._loading) {
if(distFromBottom < bufferPx) {
this.render();
}
},
prependPost : function(post) {
var postView = new app.views.Post({ model: post });
$(this.el).prepend(postView.render().el);
return this;
isLoading : function(){
return !this._loading.isResolved();
},
appendPost: function(post) {
addPost : function(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;
},
......@@ -49,8 +53,6 @@ app.views.Stream = Backbone.View.extend({
href: this.collection.url(),
id: "paginate"
}).text('Load more posts'));
this._loading = false;
},
render : function(evt) {
......@@ -59,9 +61,7 @@ app.views.Stream = Backbone.View.extend({
var self = this;
self.addLoader();
this._loading = true;
self.collection.fetch({
this._loading = self.collection.fetch({
add: true,
success: $.proxy(this.collectionFetched, self)
});
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter