Only remove post from stream after successful response

Pass destroyModel from post control view to post view
and don't listen to the remove event in the post view
anymore. The `remove` function will be called from the
base view.

Fixes #5445
This commit is contained in:
Steffen van Bergerem 2017-03-23 00:58:56 +01:00 committed by Benjamin Neff
parent aa55a7a023
commit 3ce4bba383
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
4 changed files with 11 additions and 4 deletions

View file

@ -76,6 +76,10 @@ app.views.PostControls = app.views.Base.extend({
$.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() {
this.model.set({participation: false});
}.bind(this));
},
destroyModel: function() {
this.post.destroyModel();
}
});
// @license-end

View file

@ -33,7 +33,6 @@ app.views.StreamPost = app.views.Post.extend({
var personId = this.model.get("author").id;
app.events.on("person:block:" + personId, this.remove, this);
}
this.model.on("remove", this.remove, this);
//subviews
this.commentStreamView = new app.views.CommentStream({model : this.model});
this.oEmbedView = new app.views.OEmbed({model : this.model});

View file

@ -4,7 +4,8 @@
margin: 0px;
}
&.deleting {
> .media { opacity: 0.3; }
opacity: .3;
.control-icons { display: none !important; }
}
}

View file

@ -74,12 +74,15 @@ describe("app.views.PostControls", function() {
});
it("calls destroyModel when removing a post", function() {
spyOn(app.views.PostControls.prototype, "destroyModel");
spyOn(app.views.PostControls.prototype, "destroyModel").and.callThrough();
spyOn(app.views.Post.prototype, "destroyModel");
app.currentUser = new app.models.User(this.model.attributes.author);
this.view = new app.views.PostControls({model: this.model});
this.postView = new app.views.Post({model: this.model});
this.view = new app.views.PostControls({model: this.model, post: this.postView});
this.view.render();
this.view.$(".remove_post.delete").click();
expect(app.views.PostControls.prototype.destroyModel).toHaveBeenCalled();
expect(app.views.Post.prototype.destroyModel).toHaveBeenCalled();
});
it("calls hidePost when hiding a post", function() {