Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 02742a4a rédigé par Steffen van Bergerem's avatar Steffen van Bergerem Validation de Dennis Schubert
Parcourir les fichiers

Use post controls view for single post moderation

parent 8faedd57
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -8,10 +8,6 @@ app.views.Feedback = app.views.Base.extend({
events: {
"click .like" : "toggleLike",
"click .reshare" : "resharePost",
"click .post_report" : "report",
"click .block_user" : "blockUser",
"click .hide_post" : "hidePost"
},
tooltipSelector : ".label",
......@@ -43,39 +39,6 @@ app.views.Feedback = app.views.Base.extend({
if(evt) { evt.preventDefault(); }
if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return }
this.model.interactions.reshare();
},
blockUser: function(evt) {
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t("ignore_user"))) { return; }
this.model.blockAuthor()
.done(function() {
// return to stream
document.location.href = "/stream";
})
.fail(function() {
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
});
},
hidePost : function(evt) {
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t("hide_post"))) { return; }
$.ajax({
url : "/share_visibilities/42",
type : "PUT",
data : {
post_id : this.model.id
}
}).done(function() {
// return to stream
document.location.href = "/stream";
})
.fail(function() {
app.flashMessages.error(Diaspora.I18n.t("ignore_post_failed"));
});
}
});
// @license-end
......@@ -34,7 +34,9 @@ app.views.PostControls = app.views.Base.extend({
if (evt) { evt.preventDefault(); }
if (!confirm(Diaspora.I18n.t("ignore_user"))) { return; }
this.model.blockAuthor().fail(function() {
this.model.blockAuthor().done(function() {
if (this.singlePost) { app._changeLocation(Routes.stream()); }
}.bind(this)).fail(function() {
app.flashMessages.error(Diaspora.I18n.t("ignore_failed"));
});
},
......@@ -43,7 +45,6 @@ app.views.PostControls = app.views.Base.extend({
if (evt) { evt.preventDefault(); }
if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; }
var self = this;
$.ajax({
url: Routes.shareVisibility(42),
type: "PUT",
......@@ -53,26 +54,28 @@ app.views.PostControls = app.views.Base.extend({
/* eslint-enable camelcase */
}
}).done(function() {
self.post.remove();
}).fail(function() {
if (this.singlePost) {
app._changeLocation(Routes.stream());
} else {
this.post.remove();
}
}.bind(this)).fail(function() {
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
});
},
createParticipation: function(evt) {
if (evt) { evt.preventDefault(); }
var that = this;
$.post(Routes.postParticipation(this.model.get("id")), {}, function() {
that.model.set({participation: true});
});
this.model.set({participation: true});
}.bind(this));
},
destroyParticipation: function(evt) {
if (evt) { evt.preventDefault(); }
var that = this;
$.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() {
that.model.set({participation: false});
});
this.model.set({participation: false});
}.bind(this));
}
});
// @license-end
app.views.SinglePostModeration = app.views.Feedback.extend({
app.views.SinglePostModeration = app.views.PostControls.extend({
templateName: "single-post-viewer/single-post-moderation",
className: "control-icons",
events: function() {
return _.defaults({
"click .remove_post": "destroyModel",
"click .create_participation": "createParticipation",
"click .destroy_participation": "destroyParticipation"
}, app.views.Feedback.prototype.events);
},
presenter: function() {
return _.extend(this.defaultPresenter(), {
authorIsCurrentUser : this.authorIsCurrentUser()
});
},
singlePost: true,
renderPluginWidgets : function() {
app.views.Base.prototype.renderPluginWidgets.apply(this);
this.$("a").tooltip({placement: "bottom"});
},
authorIsCurrentUser: function() {
return app.currentUser.authenticated() && this.model.get("author").id === app.user().id;
},
destroyModel: function(evt) {
if(evt) { evt.preventDefault(); }
var url = this.model.urlRoot + "/" + this.model.id;
......@@ -41,24 +22,4 @@ app.views.SinglePostModeration = app.views.Feedback.extend({
});
}
},
createParticipation: function (evt) {
if(evt) { evt.preventDefault(); }
var self = this;
$.post(Routes.postParticipation(this.model.get("id")), {}, function () {
self.model.set({participation: true});
self.render();
});
},
destroyParticipation: function (evt) {
if(evt) { evt.preventDefault(); }
var self = this;
$.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () {
self.model.set({participation: false});
self.render();
});
},
participation: function(){ return this.model.get("participation"); }
});
......@@ -154,6 +154,21 @@ describe("app.views.PostControls", function() {
expect(this.model.blockAuthor).toHaveBeenCalled();
});
it("doesn't redirect to the stream page on success", function() {
spyOn(app, "_changeLocation");
this.view.blockUser();
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
expect(app._changeLocation).not.toHaveBeenCalled();
});
it("redirects to the stream page on success from the single post view", function() {
spyOn(app, "_changeLocation");
this.view.singlePost = true;
this.view.blockUser();
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
expect(app._changeLocation).toHaveBeenCalledWith(Routes.stream());
});
it("shows a flash message when errors occur", function() {
spyOn(app.flashMessages, "error");
this.view.blockUser();
......@@ -185,9 +200,21 @@ describe("app.views.PostControls", function() {
it("removes the post on success", function() {
spyOn(this.view.post, "remove");
spyOn(app, "_changeLocation");
this.view.hidePost();
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
expect(this.view.post.remove).toHaveBeenCalled();
expect(app._changeLocation).not.toHaveBeenCalled();
});
it("redirects to the stream page on success from the single post view", function() {
spyOn(this.view.post, "remove");
spyOn(app, "_changeLocation");
this.view.singlePost = true;
this.view.hidePost();
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
expect(this.view.post.remove).not.toHaveBeenCalled();
expect(app._changeLocation).toHaveBeenCalledWith(Routes.stream());
});
it("shows a flash message when errors occur", function() {
......
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