added blocks js model; load app.models.Post before any other model when loading assets
This commit is contained in:
parent
5e88ca846a
commit
31fac53969
5 changed files with 21 additions and 17 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<div class="right controls">
|
||||
<% if(author.id != current_user.id) { %>
|
||||
<img src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "Ignore" data-person_id="<%= author.id %>" />
|
||||
<img src="/images/icons/ignoreuser.png" alt="Ignoreuser" class="block_user control_icon" title= "Ignore" />
|
||||
<% } else { %>
|
||||
<img src="/images/deletelabel.png" class="delete control_icon remove_post" title="Delete" />
|
||||
<% } %>
|
||||
|
|
@ -8,9 +8,8 @@
|
|||
</div>
|
||||
|
||||
<div class="sm_body">
|
||||
|
||||
<a href="/people/<%= author.id %>">
|
||||
<img src="<%= author.avatar.small %>" class="avatar" data-person_id="<%= author.id %>"/>
|
||||
<img src="<%= author.avatar.small %>" class="avatar" />
|
||||
</a>
|
||||
|
||||
<div class="content">
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ javascripts:
|
|||
- public/javascripts/app/app.js
|
||||
- public/javascripts/app/router.js
|
||||
- public/javascripts/app/views.js
|
||||
- public/javascripts/app/models/post.js
|
||||
- public/javascripts/app/models/*
|
||||
- public/javascripts/app/collections/*
|
||||
- public/javascripts/app/views/stream_object_view.js
|
||||
|
|
|
|||
3
public/javascripts/app/models/block.js
Normal file
3
public/javascripts/app/models/block.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
app.models.Block = Backbone.Model.extend({
|
||||
urlRoot : "blocks"
|
||||
});
|
||||
|
|
@ -27,6 +27,9 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
// set the guid
|
||||
$(this.el).attr("id", this.model.get("guid"));
|
||||
|
||||
// remove post
|
||||
this.model.bind('remove', this.remove, this);
|
||||
|
||||
// commentStream view
|
||||
this.commentStreamView = new app.views.CommentStream({ model : this.model});
|
||||
this.likesInfoView = new app.views.LikesInfo({ model : this.model});
|
||||
|
|
@ -70,25 +73,22 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
|
||||
blockUser: function(evt){
|
||||
if(evt) { evt.preventDefault(); }
|
||||
if(!confirm("Ignore this user?")) { return }
|
||||
|
||||
if(confirm('Ignore this user?')) {
|
||||
var person_id = $(evt.target).data('person_id');
|
||||
var self = this;
|
||||
var personId = this.model.get("author").id;
|
||||
var block = new app.models.Block();
|
||||
|
||||
$.post('/blocks', {block : {"person_id" : person_id}}, function(data){
|
||||
var models_to_remove = [];
|
||||
block.save({block : {person_id : personId}}, {
|
||||
success : function(){
|
||||
if(!app.stream) { return }
|
||||
|
||||
_.each(self.model.collection.models, function(model){
|
||||
if(model.get("author")["id"] == person_id) {
|
||||
models_to_remove.push(model);
|
||||
_.each(app.stream.collection.models, function(model){
|
||||
if(model.get("author").id == personId) {
|
||||
app.stream.collection.remove(model);
|
||||
}
|
||||
})
|
||||
|
||||
self.model.collection.remove(models_to_remove);
|
||||
}, "json");
|
||||
}
|
||||
|
||||
return this;
|
||||
})
|
||||
},
|
||||
|
||||
focusCommentTextarea: function(evt){
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ src_files:
|
|||
- public/javascripts/app/app.js
|
||||
- public/javascripts/app/router.js
|
||||
- public/javascripts/app/views.js
|
||||
- public/javascripts/app/models/post.js
|
||||
- public/javascripts/app/models/*
|
||||
- public/javascripts/app/collections/*
|
||||
- public/javascripts/app/views/stream_object_view.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue