Skip to content

Commit 1d2f633

Browse files
committed
Fixed 'expand all' and 'collapse all'. Also fixed expanding and collapsing in general, since routes weren't properly defined.
1 parent 6cfa16d commit 1d2f633

File tree

8 files changed

+43
-23
lines changed

8 files changed

+43
-23
lines changed

app/views/comments/_comment.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
- if collapsable
1919
%dt{ hidden_if(comment.expanded?), :id => dom_id(comment, :truncated) }
2020
= truncated
21-
.textile{ hidden_if(comment.collapsed?), :id => dom_id(comment, :formatted) }
21+
%dt.textile{ hidden_if(comment.collapsed?), :id => dom_id(comment, :formatted) }
2222
= auto_link(formatted)
2323
- else
24-
.textile= auto_link(formatted)
24+
%dt.textile= auto_link(formatted)
2525

app/views/comments/_new.html.haml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
-# Two hidden fields store the IDs of notes and emails shown for the asset. These IDs are used
66
-# by [Expand/Collapse All]. The contents gets updated by actions such as [Add] or [Delete].
7-
= hidden_field_tag :shown_notes, "#{commentable.comment_ids.join(',')}"
8-
= hidden_field_tag :shown_emails, "#{commentable.email_ids.join(',')}"
7+
= hidden_field_tag :shown_notes, "#{commentable.comment_ids.join(',')}", :id => "#{id_prefix}_shown_notes"
8+
= hidden_field_tag :shown_emails, "#{commentable.email_ids.join(',')}", :id => "#{id_prefix}_shown_emails"
99

1010
= link_to avatar_for(@current_user, :size => "25x25"), user_path(@current_user)
1111
.tools{ {:id => "#{id_prefix}_comment_new_tools"}.merge(invisible) }
12-
= link_to_function("Expand All", "crm.flip_notes_and_emails('Expanded', 'More...', 'Less...')") << " | "
13-
= link_to_function("Collapse All", "crm.flip_notes_and_emails('Collapsed', 'More...', 'Less...')")
12+
= link_to_function("Expand All", "crm.flip_notes_and_emails('Expanded', 'More...', 'Less...', '#{id_prefix}')") << " | "
13+
= link_to_function("Collapse All", "crm.flip_notes_and_emails('Collapsed', 'More...', 'Less...', '#{id_prefix}')")
1414

1515
%div{ {:id => "#{id_prefix}_post"}.merge(hidden_if(true))}
1616
= form_for(@comment, :remote => true, :html => {:id => "#{id_prefix}_new_comment"}) do |f|

app/views/comments/create.js.rjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if @comment.valid?
55
page.insert_html :after, "#{id_prefix}_comment_new", :partial => "comment", :locals => { :comment => @comment }
66
page[dom_id(@comment)].visual_effect :highlight, :duration => 1.5
77
end
8-
page[:shown_notes].value = @comment.commentable.comment_ids.join(',')
8+
page["#{id_prefix}_shown_notes"].value = @comment.commentable.comment_ids.join(',')
99
page["#{id_prefix}_comment_comment"].clear
1010
page["#{id_prefix}_comment_comment"].focus
1111

app/views/comments/destroy.js.rjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
page[:shown_notes].value = @comment.commentable.comment_ids.join(',')
1+
class_name = @comment.commentable.class.name.downcase
2+
id_prefix = "#{class_name}_#{@comment.commentable.id}"
3+
4+
page["#{id_prefix}_shown_notes"].value = @comment.commentable.comment_ids.join(',')
25
page[dom_id(@comment)].visual_effect "blind_up", :duration => 0.25
6+

app/views/emails/_email.html.haml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- truncated = h(truncate(email.body.to_s.gsub("\n", " "), :length => 125 - email.subject.to_s.size))
1+
- truncated = h(truncate(email.body_without_textile.to_s.gsub("\n", " "), :length => 125 - email.subject.to_s.size))
22
- formatted = email.body
33

44
%li.mail{ highlightable(dom_id(email, :tools), :off => "#f2f2f2"), :id => dom_id(email) }
@@ -17,7 +17,8 @@
1717
%p
1818
= h(email.subject)
1919
%tt= " - " << truncated
20-
.textile{ hidden_if(email.collapsed?), :id => dom_id(email, :formatted) }
21-
%p= h(email.subject)
22-
= auto_link(formatted)
20+
%dt.textile{ hidden_if(email.collapsed?), :id => dom_id(email, :formatted) }
21+
.email_content
22+
%p= h(email.subject)
23+
= auto_link(formatted)
2324

app/views/emails/destroy.js.rjs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
page[:shown_emails].value = @email.mediator.email_ids.join(',')
1+
class_name = @email.mediator.class.name.downcase
2+
id_prefix = "#{class_name}_#{@email.mediator.id}"
3+
4+
page["#{id_prefix}_shown_emails"].value = @email.mediator.email_ids.join(',')
25
page[dom_id(@email)].visual_effect "blind_up", :duration => 0.25
6+

config/routes.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
root :to => 'home#index'
44

5-
match 'activities' => 'home#index'
65
match 'admin' => 'admin/users#index', :as => :admin
76
match 'login' => 'authentications#new', :as => :login
87
match 'logout' => 'authentications#destroy', :as => :logout
9-
match 'options' => 'home#options'
108
match 'profile' => 'users#show', :as => :profile
119
match 'signup' => 'users#new', :as => :signup
12-
match 'timeline' => 'home#timeline', :as => :timeline
13-
match 'timezone' => 'home#timezone', :as => :timezone
14-
match 'toggle' => 'home#toggle'
15-
match 'redraw' => 'home#redraw'
10+
match 'home/activities' => 'home#index'
11+
match 'home/options' => 'home#options'
12+
match 'home/timeline' => 'home#timeline', :as => :timeline
13+
match 'home/timezone' => 'home#timezone', :as => :timezone
14+
match 'home/toggle' => 'home#toggle'
15+
match 'home/redraw' => 'home#redraw'
1616

1717
resource :authentication
1818

@@ -134,3 +134,4 @@
134134
resources :plugins
135135
end
136136
end
137+

public/javascripts/application.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,26 @@ var crm = {
256256
},
257257

258258
//----------------------------------------------------------------------------
259-
flip_notes_and_emails: function(state, more, less) {
260-
var notes = $("shown_notes").value;
261-
var emails = $("shown_emails").value;
259+
flip_notes_and_emails: function(state, more, less, el_prefix) {
260+
if(!el_prefix){
261+
var notes_field = "shown_notes";
262+
var emails_field = "shown_emails";
263+
var comment_new_field = "comment_new";
264+
} else {
265+
var notes_field = el_prefix + "_shown_notes";
266+
var emails_field = el_prefix + "_shown_emails";
267+
var comment_new_field = el_prefix + "_comment_new";
268+
};
269+
270+
var notes = $(notes_field).value;
271+
var emails = $(emails_field).value;
262272

263273
if (notes != "" || emails != "") {
264274
new Ajax.Request(this.base_url + "/home/timeline", {
265275
method : "get",
266276
parameters : { type : "", id : notes + "+" + emails, state : state },
267277
onComplete : function() {
268-
$("comment_new").adjacent("li").each( function(li) {
278+
$(comment_new_field).adjacent("li").each( function(li) {
269279
var a = li.select("tt a.toggle")[0];
270280
var dt = li.select("dt");
271281
if (typeof(a) != "undefined") {

0 commit comments

Comments
 (0)