added blocks js model; load app.models.Post before any other model when loading assets

This commit is contained in:
danielgrippi 2012-01-01 09:47:51 -05:00 committed by Dennis Collinson
parent 5e88ca846a
commit 31fac53969
5 changed files with 21 additions and 17 deletions

View file

@ -1,6 +1,6 @@
<div class="right controls"> <div class="right controls">
<% if(author.id != current_user.id) { %> <% 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 { %> <% } else { %>
<img src="/images/deletelabel.png" class="delete control_icon remove_post" title="Delete" /> <img src="/images/deletelabel.png" class="delete control_icon remove_post" title="Delete" />
<% } %> <% } %>
@ -8,9 +8,8 @@
</div> </div>
<div class="sm_body"> <div class="sm_body">
<a href="/people/<%= author.id %>"> <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> </a>
<div class="content"> <div class="content">

View file

@ -13,6 +13,7 @@ javascripts:
- public/javascripts/app/app.js - public/javascripts/app/app.js
- public/javascripts/app/router.js - public/javascripts/app/router.js
- public/javascripts/app/views.js - public/javascripts/app/views.js
- public/javascripts/app/models/post.js
- public/javascripts/app/models/* - public/javascripts/app/models/*
- public/javascripts/app/collections/* - public/javascripts/app/collections/*
- public/javascripts/app/views/stream_object_view.js - public/javascripts/app/views/stream_object_view.js

View file

@ -0,0 +1,3 @@
app.models.Block = Backbone.Model.extend({
urlRoot : "blocks"
});

View file

@ -27,6 +27,9 @@ app.views.Post = app.views.StreamObject.extend({
// set the guid // set the guid
$(this.el).attr("id", this.model.get("guid")); $(this.el).attr("id", this.model.get("guid"));
// remove post
this.model.bind('remove', this.remove, this);
// commentStream view // commentStream view
this.commentStreamView = new app.views.CommentStream({ model : this.model}); this.commentStreamView = new app.views.CommentStream({ model : this.model});
this.likesInfoView = new app.views.LikesInfo({ 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){ blockUser: function(evt){
if(evt) { evt.preventDefault(); } if(evt) { evt.preventDefault(); }
if(!confirm("Ignore this user?")) { return }
if(confirm('Ignore this user?')) { var personId = this.model.get("author").id;
var person_id = $(evt.target).data('person_id'); var block = new app.models.Block();
var self = this;
$.post('/blocks', {block : {"person_id" : person_id}}, function(data){ block.save({block : {person_id : personId}}, {
var models_to_remove = []; success : function(){
if(!app.stream) { return }
_.each(self.model.collection.models, function(model){ _.each(app.stream.collection.models, function(model){
if(model.get("author")["id"] == person_id) { if(model.get("author").id == personId) {
models_to_remove.push(model); app.stream.collection.remove(model);
} }
}) })
}
self.model.collection.remove(models_to_remove); })
}, "json");
}
return this;
}, },
focusCommentTextarea: function(evt){ focusCommentTextarea: function(evt){

View file

@ -37,6 +37,7 @@ src_files:
- public/javascripts/app/app.js - public/javascripts/app/app.js
- public/javascripts/app/router.js - public/javascripts/app/router.js
- public/javascripts/app/views.js - public/javascripts/app/views.js
- public/javascripts/app/models/post.js
- public/javascripts/app/models/* - public/javascripts/app/models/*
- public/javascripts/app/collections/* - public/javascripts/app/collections/*
- public/javascripts/app/views/stream_object_view.js - public/javascripts/app/views/stream_object_view.js