refactor global event broker and user blocking from stream posts
This commit is contained in:
parent
163b76ae3d
commit
4fd9bae056
5 changed files with 28 additions and 11 deletions
|
|
@ -19,7 +19,16 @@ var app = {
|
|||
views: {},
|
||||
pages: {},
|
||||
forms: {},
|
||||
vent: _.extend({}, Backbone.Events),
|
||||
|
||||
// global event broker - use event names in the form of "object:action:data"
|
||||
// [object]: the class of the acting object
|
||||
// [action]: infinitive verb naming the performed action
|
||||
// [data]: (optional) unique name or ID of the specific instance
|
||||
// e.g. "person:ignore:123"
|
||||
// if your event has to pass more than one datum (singular) - or in case you
|
||||
// need structured data - specify them as arguments to the `#trigger` call
|
||||
// e.g. `app.events.trigger('example:event', {more: 'data'})`
|
||||
events: _.extend({}, Backbone.Events),
|
||||
|
||||
user: function(userAttrs) {
|
||||
if(userAttrs) { return this._user = new app.models.User(userAttrs) }
|
||||
|
|
|
|||
|
|
@ -27,6 +27,14 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
|
|||
return this.get("author")
|
||||
},
|
||||
|
||||
blockAuthor: function() {
|
||||
var personId = this.get("author").id;
|
||||
var block = new app.models.Block();
|
||||
|
||||
return block.save({block : {person_id : personId}})
|
||||
.done(function(){ app.events.trigger('person:block:'+personId); });
|
||||
},
|
||||
|
||||
toggleFavorite : function(options){
|
||||
this.set({favorite : !this.get("favorite")})
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
|
||||
initialize : function(){
|
||||
var personId = this.model.get('author').id;
|
||||
app.vent.on('remove:author:posts:'+personId, this.remove, this);
|
||||
app.events.on('person:block:'+personId, this.remove, this);
|
||||
|
||||
this.model.on('remove', this.remove, this);
|
||||
//subviews
|
||||
|
|
@ -75,14 +75,13 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
if(evt) { evt.preventDefault(); }
|
||||
if(!confirm(Diaspora.I18n.t('ignore_user'))) { return }
|
||||
|
||||
var personId = this.model.get("author").id;
|
||||
var block = new app.models.Block();
|
||||
|
||||
block.save({block : {person_id : personId}}, {
|
||||
success : function(){
|
||||
app.vent.trigger('remove:author:posts:'+personId);
|
||||
}
|
||||
})
|
||||
this.model.blockAuthor()
|
||||
.fail(function() {
|
||||
Diaspora.page.flashMessages.render({
|
||||
success: false,
|
||||
notice: Diaspora.I18n.t('ignore_failed')
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
remove : function() {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ en:
|
|||
created: "The report was successfully created"
|
||||
exists: "The report already exists"
|
||||
ignore_user: "Ignore this user?"
|
||||
ignore_failed: "Unable to ignore this user"
|
||||
and: "and"
|
||||
comma: ","
|
||||
edit: "Edit"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ describe("app.views.StreamPost", function(){
|
|||
it("setup remove:author:posts:#{id} to #remove", function(){
|
||||
spyOn(_PostViewClass.prototype, 'remove');
|
||||
view = new _PostViewClass({model : this.statusMessage});
|
||||
app.vent.trigger('remove:author:posts:'+authorId);
|
||||
app.events.trigger('person:block:'+authorId);
|
||||
expect(_PostViewClass.prototype.remove).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue