Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added reply to feature to example app
- Loading branch information
Showing
17 changed files
with
99 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= form_for @message do |f| %> | ||
<p><%= f.label :message, 'New message' %></p> | ||
<p><%= f.text_area :message, :rows => 4 %></p> | ||
<p> | ||
<%= f.hidden_field :reply_to_message_id, :value => @reply_to.id if @reply_to %> | ||
<%= f.submit "Send" %> | ||
</p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h3><%= message.message %></h3> | ||
<p>by <%= message.user.username %></p> | ||
<% if message.reply_to_message %> | ||
<p><%= link_to "In reply to", "#" + dom_id(message.reply_to_message), :class => 'in-reply-to' %></p> | ||
<% end %> | ||
<p><%= link_to 'Reply', new_message_path(:reply_to => message), :class => 'reply' %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<% Message.recent.each do |message| %> | ||
<li> | ||
<h3><%= message.message %></h3> | ||
<p>by <%= message.user.email %></p> | ||
</li> | ||
<% end %> | ||
<ul id="messages"> | ||
<% Message.recent.each do |message| %> | ||
<%= content_tag_for(:li, message) do %> | ||
<%= render message %> | ||
<% end %> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
<h1>Listing messages</h1> | ||
|
||
<%= form_for @message do |f| %> | ||
<p><%= f.label :message, 'New message' %></p> | ||
<p><%= f.text_area :message, :rows => 4 %></p> | ||
<p><%= f.submit "Send" %></p> | ||
<% end %> | ||
<p><%= link_to 'New message', new_message_path, :class => 'new' %></p> | ||
|
||
<ul id="messages"> | ||
<%= render :partial => 'messages' %> | ||
</ul> | ||
<%= render :partial => 'messages' %> | ||
<%= javascript_include_tag 'messages' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>Reply to message<h1> | ||
|
||
<%= render 'form' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,39 @@ | ||
$(function() { | ||
$('#new_message').each(function() { | ||
var form = $(this) | ||
form.submit(function() { | ||
$.ajax({ | ||
url: form.attr('action'), | ||
data: form.serialize(), | ||
type: 'POST', | ||
success: function(data) { | ||
$('#messages').html(data); | ||
} | ||
}); | ||
$('a.new').click(function() { | ||
var link = $(this); | ||
$.get(link.attr('href'), {}, function(data) { | ||
$('form.new_message').remove(); | ||
link.after(data); | ||
}, 'html'); | ||
return false; | ||
}); | ||
|
||
var Message = function() { | ||
var message = $(this); | ||
message.find('.reply').click(function() { | ||
$.get($(this).attr('href'), {}, function(data) { | ||
$('form.new_message').remove(); | ||
message.append(data); | ||
}, 'html'); | ||
return false; | ||
}); | ||
}); | ||
|
||
setInterval(function() { | ||
$.ajax({ | ||
url: '/', | ||
data: {}, | ||
success: function(data) { | ||
$('#messages').html(data); | ||
} | ||
message.find('.in-reply-to').click(function() { | ||
$($(this).attr('href')).addClass('highlighted'); | ||
}); | ||
} | ||
|
||
$('#messages li').each(Message); | ||
|
||
setInterval(function() { | ||
$.get('/', {}, function(data) { | ||
$(data).find('li').each(function() { | ||
var newMessage = $(this); | ||
if(!$('#' + newMessage.attr('id')).length) { | ||
$('#messages').prepend(newMessage); | ||
Message(newMessage); | ||
} | ||
}); | ||
}, 'html'); | ||
}, 1000); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#messages li.highlighted { | ||
background: yellow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters