Use post controls view for single post moderation
This commit is contained in:
parent
8faedd574d
commit
02742a4a8f
4 changed files with 42 additions and 88 deletions
|
|
@ -8,10 +8,6 @@ app.views.Feedback = app.views.Base.extend({
|
||||||
events: {
|
events: {
|
||||||
"click .like" : "toggleLike",
|
"click .like" : "toggleLike",
|
||||||
"click .reshare" : "resharePost",
|
"click .reshare" : "resharePost",
|
||||||
|
|
||||||
"click .post_report" : "report",
|
|
||||||
"click .block_user" : "blockUser",
|
|
||||||
"click .hide_post" : "hidePost"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
tooltipSelector : ".label",
|
tooltipSelector : ".label",
|
||||||
|
|
@ -43,39 +39,6 @@ app.views.Feedback = app.views.Base.extend({
|
||||||
if(evt) { evt.preventDefault(); }
|
if(evt) { evt.preventDefault(); }
|
||||||
if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return }
|
if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return }
|
||||||
this.model.interactions.reshare();
|
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
|
// @license-end
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ app.views.PostControls = app.views.Base.extend({
|
||||||
if (evt) { evt.preventDefault(); }
|
if (evt) { evt.preventDefault(); }
|
||||||
if (!confirm(Diaspora.I18n.t("ignore_user"))) { return; }
|
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"));
|
app.flashMessages.error(Diaspora.I18n.t("ignore_failed"));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -43,7 +45,6 @@ app.views.PostControls = app.views.Base.extend({
|
||||||
if (evt) { evt.preventDefault(); }
|
if (evt) { evt.preventDefault(); }
|
||||||
if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; }
|
if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; }
|
||||||
|
|
||||||
var self = this;
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: Routes.shareVisibility(42),
|
url: Routes.shareVisibility(42),
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
|
|
@ -53,26 +54,28 @@ app.views.PostControls = app.views.Base.extend({
|
||||||
/* eslint-enable camelcase */
|
/* eslint-enable camelcase */
|
||||||
}
|
}
|
||||||
}).done(function() {
|
}).done(function() {
|
||||||
self.post.remove();
|
if (this.singlePost) {
|
||||||
}).fail(function() {
|
app._changeLocation(Routes.stream());
|
||||||
|
} else {
|
||||||
|
this.post.remove();
|
||||||
|
}
|
||||||
|
}.bind(this)).fail(function() {
|
||||||
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
|
app.flashMessages.error(Diaspora.I18n.t("hide_post_failed"));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
createParticipation: function(evt) {
|
createParticipation: function(evt) {
|
||||||
if (evt) { evt.preventDefault(); }
|
if (evt) { evt.preventDefault(); }
|
||||||
var that = this;
|
|
||||||
$.post(Routes.postParticipation(this.model.get("id")), {}, function() {
|
$.post(Routes.postParticipation(this.model.get("id")), {}, function() {
|
||||||
that.model.set({participation: true});
|
this.model.set({participation: true});
|
||||||
});
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
destroyParticipation: function(evt) {
|
destroyParticipation: function(evt) {
|
||||||
if (evt) { evt.preventDefault(); }
|
if (evt) { evt.preventDefault(); }
|
||||||
var that = this;
|
|
||||||
$.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() {
|
$.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() {
|
||||||
that.model.set({participation: false});
|
this.model.set({participation: false});
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,12 @@
|
||||||
app.views.SinglePostModeration = app.views.Feedback.extend({
|
app.views.SinglePostModeration = app.views.PostControls.extend({
|
||||||
templateName: "single-post-viewer/single-post-moderation",
|
templateName: "single-post-viewer/single-post-moderation",
|
||||||
|
singlePost: true,
|
||||||
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()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
renderPluginWidgets : function() {
|
renderPluginWidgets : function() {
|
||||||
app.views.Base.prototype.renderPluginWidgets.apply(this);
|
app.views.Base.prototype.renderPluginWidgets.apply(this);
|
||||||
this.$("a").tooltip({placement: "bottom"});
|
this.$("a").tooltip({placement: "bottom"});
|
||||||
},
|
},
|
||||||
|
|
||||||
authorIsCurrentUser: function() {
|
|
||||||
return app.currentUser.authenticated() && this.model.get("author").id === app.user().id;
|
|
||||||
},
|
|
||||||
|
|
||||||
destroyModel: function(evt) {
|
destroyModel: function(evt) {
|
||||||
if(evt) { evt.preventDefault(); }
|
if(evt) { evt.preventDefault(); }
|
||||||
var url = this.model.urlRoot + "/" + this.model.id;
|
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();
|
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() {
|
it("shows a flash message when errors occur", function() {
|
||||||
spyOn(app.flashMessages, "error");
|
spyOn(app.flashMessages, "error");
|
||||||
this.view.blockUser();
|
this.view.blockUser();
|
||||||
|
|
@ -185,9 +200,21 @@ describe("app.views.PostControls", function() {
|
||||||
|
|
||||||
it("removes the post on success", function() {
|
it("removes the post on success", function() {
|
||||||
spyOn(this.view.post, "remove");
|
spyOn(this.view.post, "remove");
|
||||||
|
spyOn(app, "_changeLocation");
|
||||||
this.view.hidePost();
|
this.view.hidePost();
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
|
jasmine.Ajax.requests.mostRecent().respondWith({status: 204});
|
||||||
expect(this.view.post.remove).toHaveBeenCalled();
|
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() {
|
it("shows a flash message when errors occur", function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue