Skip to content
Extraits de code Groupes Projets
Valider 80f797a5 rédigé par Dan Hansen's avatar Dan Hansen Validation de Dennis Collinson
Parcourir les fichiers

introduce comments

parent ba9ece00
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 151 ajouts et 60 suppressions
var post = App.stream.collection.get(<%= @comment.post.id %>);
console.log(post);
ContentUpdater.addCommentToPost("<%= @comment.post.guid %>", ContentUpdater.addCommentToPost("<%= @comment.post.guid %>",
"<%= @comment.guid%>", "<%= @comment.guid%>",
"<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person, :post => @comment.post}))%>"); "<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person, :post => @comment.post}))%>");
...@@ -45,9 +45,6 @@ ...@@ -45,9 +45,6 @@
current_user: #{current_user.person.as_api_response(:backbone).to_json} current_user: #{current_user.person.as_api_response(:backbone).to_json}
}); });
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
= yield(:head) = yield(:head)
-unless Rails.env == "production" -unless Rails.env == "production"
...@@ -80,6 +77,9 @@ ...@@ -80,6 +77,9 @@
%script{:id => "stream-element-template", :type => 'text/template'} %script{:id => "stream-element-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/shared/_stream_element.html.underscore") != File.read("#{Rails.root}/app/views/shared/_stream_element.html.underscore")
%script{:id => "comment-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/shared/_comment.html.underscore")
.container{:style=> "#{yield(:break_the_mold)}"} .container{:style=> "#{yield(:break_the_mold)}"}
- if @aspsect == :getting_started || @page == :logged_out - if @aspsect == :getting_started || @page == :logged_out
= yield = yield
......
<li id="<%= id %>" class="comment">
<div class="right controls">
<!-- need access to post -->
<% if(author.id === current_user.id) { %>
<!-- LINK BROKEN FOR NOW -->
<a href="/posts/<%= id %>/comments/<%= id %>" class="delete comment_delete" data-original-title="Delete">
<img alt="Deletelabel" src="/images/deletelabel.png">
</a>
<% } %>
</div>
<a href="/people/<%= author.id %>">
<img src="<%= author.avatar.small %>" class="avatar" data-person-id="<%= author.id %>"/>
</a>
<div class="content">
<span class="from">
<a href="/people/<%= author.id %>">
<%= author.name %>
</a>
</span>
<p>
<%= text %>
</p>
<div class="comment_info">
<time class="timeago" datetime="<%= created_at %>"/>
</div>
</div>
</li>
...@@ -78,43 +78,7 @@ ...@@ -78,43 +78,7 @@
</li> </li>
</ul> </ul>
<ul class="comments"> <ul class="comments"> </ul>
<% _.each(last_three_comments, function(comment) { %>
<li id="<%= comment.guid %>" class="comment">
<% if(comment.author.id == current_user.id || author.id == current_user.id) { %>
<div class="right controls">
<a href="/posts/<%= id %>/comments/<%= comment.id %>" class="delete comment_delete" data-original-title="Delete">
<img alt="Deletelabel" src="/images/deletelabel.png">
</a>
</div>
<% } %>
<a href="/people/<%= author.id %>">
<img src="<%= comment.author.avatar.small %>" class="avatar" data-person-id="<%= comment.author.id %>"/>
</a>
<div class="content">
<span class="from">
<a href="/people/<%= comment.author.id %>">
<%= comment.author.name %>
</a>
</span>
<p>
<%= comment.text %>
</p>
<div class="comment_info">
<time class="timeago" datetime="<%= comment.created_at %>"/>
</div>
</div>
</li>
<% }) %>
</ul>
<div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>"> <div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>">
<form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" data-remote="true" id="new_comment_on_<%= id %>" method="post"> <form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" data-remote="true" id="new_comment_on_<%= id %>" method="post">
......
...@@ -18,8 +18,6 @@ var App = { ...@@ -18,8 +18,6 @@ var App = {
Backbone.history.start({pushState: true}); Backbone.history.start({pushState: true});
} }
}; };
$(function() { App.initialize(); }); $(function() { App.initialize(); });
App.Collections.Comments = Backbone.Collection.extend({
model: App.Models.Comment
});
...@@ -2,7 +2,7 @@ App.Collections.Stream = Backbone.Collection.extend({ ...@@ -2,7 +2,7 @@ App.Collections.Stream = Backbone.Collection.extend({
url: function() { url: function() {
var path = document.location.pathname + ".json"; var path = document.location.pathname + ".json";
if(this.models.length) { path += "?max_time=" + _.last(this.models).intTime(); } if(this.models.length) { path += "?max_time=" + _.last(this.models).createdAt(); }
return path; return path;
}, },
......
App.Models.Comment = Backbone.Model.extend({
});
App.Models.Post = Backbone.Model.extend({ App.Models.Post = Backbone.Model.extend({
url: "/posts/:id", url: "/posts/:id",
intTime: function(){
initialize: function() {
this.comments = new App.Collections.Comments(this.get("last_three_comments"));
},
createdAt: function(){
return +new Date(this.get("created_at")) / 1000; return +new Date(this.get("created_at")) / 1000;
} }
}); });
App.Views.CommentStream = Backbone.View.extend({
initialize: function(options) {
this.collection = options.collection;
},
render: function() {
var self = this;
this.collection.each(function(comment) {
$(self.el).append(new App.Views.Comment({
model: comment
}).render());
});
return this.el;
}
});
App.Views.Comment = Backbone.View.extend({
initialize: function(options) {
this.model = options.model;
this.template = _.template($("#comment-template").html());
},
render: function() {
this.el = $(this.template($.extend(
this.model.toJSON(),
App.user()
)));
console.log(this.el);
return this.el;
}
});
App.Views.Post = Backbone.View.extend({
initialize: function(options) {
this.model = options.model;
this.template = _.template($("#stream-element-template").html());
},
render: function() {
this.el = $(this.template($.extend(
this.model.toJSON(),
App.user()
)));
this.$("ul.comments").html(new App.Views.CommentStream({
collection: this.model.comments
}).render());
this.$(".details time").timeago();
this.$("label").inFieldLabels();
return this.el;
}
});
...@@ -5,28 +5,21 @@ App.Views.Stream = Backbone.View.extend({ ...@@ -5,28 +5,21 @@ App.Views.Stream = Backbone.View.extend({
initialize: function(){ initialize: function(){
this.el = $("#main_stream"); this.el = $("#main_stream");
this.template = _.template($("#stream-element-template").html());
_.bindAll(this, "appendPost", "collectionFetched"); _.bindAll(this, "appendPost", "collectionFetched");
this.collection = new App.Collections.Stream; this.collection = new App.Collections.Stream;
this.collection.bind("add", this.appendPost); this.collection.bind("add", this.appendPost);
this.loadMore(); this.loadMore();
}, },
appendPost: function(model) { appendPost: function(post) {
var post = $(this.template($.extend( $(this.el).append(new App.Views.Post({
model.toJSON(), model: post
App.user() }).render());
)));
$(this.el).append(post);
Diaspora.BaseWidget.instantiate("StreamElement", post);
}, },
collectionFetched: function() { collectionFetched: function() {
this.$(".details time").timeago();
this.$("label").inFieldLabels();
this.$("#paginate").remove(); this.$("#paginate").remove();
$(this.el).append($("<a>", { $(this.el).append($("<a>", {
href: this.collection.url(), href: this.collection.url(),
...@@ -35,9 +28,7 @@ App.Views.Stream = Backbone.View.extend({ ...@@ -35,9 +28,7 @@ App.Views.Stream = Backbone.View.extend({
}, },
loadMore: function(evt) { loadMore: function(evt) {
if(evt) { if(evt) { evt.preventDefault(); }
evt.preventDefault();
}
this.collection.fetch({ this.collection.fetch({
add: true, add: true,
......
describe("Stream", function() {
describe("url", function() {
var stream = new BackboneStream(),
expectedPath = document.location.pathname + ".json";
it("returns the json path", function() {
expect(stream.url()).toEqual(expectedPath);
});
it("returns the json path with max_time if the collection has models", function() {
var post = new Post();
spyOn(post, "createdAt").andReturn(1234);
stream.add(post);
expect(stream.url()).toEqual(expectedPath + "?max_time=1234");
});
});
});
describe("App.Models.Post", function() {
describe("createdAt", function() {
var post = new App.Models.Post();
it("returns the post's created_at as an integer", function() {
var date = new Date;
post.set({ created_at: +date * 1000 });
expect(typeof post.createdAt()).toEqual("number");
expect(post.createdAt()).toEqual(+date);
});
});
});
...@@ -25,6 +25,8 @@ src_files: ...@@ -25,6 +25,8 @@ src_files:
- public/javascripts/vendor/timeago.js - public/javascripts/vendor/timeago.js
- public/javascripts/vendor/facebox.js - public/javascripts/vendor/facebox.js
- public/javascripts/jquery.infieldlabel-custom.js - public/javascripts/jquery.infieldlabel-custom.js
- public/javascripts/vendor/underscore.js
- public/javascripts/vendor/backbone.js
- public/javascripts/fileuploader-custom.js - public/javascripts/fileuploader-custom.js
- public/javascripts/jquery.autocomplete-custom.js - public/javascripts/jquery.autocomplete-custom.js
- public/javascripts/diaspora.js - public/javascripts/diaspora.js
...@@ -33,7 +35,12 @@ src_files: ...@@ -33,7 +35,12 @@ src_files:
- public/javascripts/pages/* - public/javascripts/pages/*
- public/javascripts/helpers/* - public/javascripts/helpers/*
- public/javascripts/widgets/* - public/javascripts/widgets/*
- public/javascripts/app.js
- public/javascripts/models/*
- public/javascripts/collections/*
- public/javascripts/views/*
- public/javascripts/mobile.js - public/javascripts/mobile.js
- public/javascripts/contact-list.js - public/javascripts/contact-list.js
- public/javascripts/web-socket-receiver.js - public/javascripts/web-socket-receiver.js
......
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