Skip to content

Commit

Permalink
Fixed 'expand all' and 'collapse all'. Also fixed expanding and colla…
Browse files Browse the repository at this point in the history
…psing in general, since routes weren't properly defined.
  • Loading branch information
ndbroadbent committed Feb 26, 2011
1 parent 6cfa16d commit 1d2f633
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/views/comments/_comment.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
- if collapsable
%dt{ hidden_if(comment.expanded?), :id => dom_id(comment, :truncated) }
= truncated
.textile{ hidden_if(comment.collapsed?), :id => dom_id(comment, :formatted) }
%dt.textile{ hidden_if(comment.collapsed?), :id => dom_id(comment, :formatted) }
= auto_link(formatted)
- else
.textile= auto_link(formatted)
%dt.textile= auto_link(formatted)

8 changes: 4 additions & 4 deletions app/views/comments/_new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

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

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

%div{ {:id => "#{id_prefix}_post"}.merge(hidden_if(true))}
= form_for(@comment, :remote => true, :html => {:id => "#{id_prefix}_new_comment"}) do |f|
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/create.js.rjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if @comment.valid?
page.insert_html :after, "#{id_prefix}_comment_new", :partial => "comment", :locals => { :comment => @comment }
page[dom_id(@comment)].visual_effect :highlight, :duration => 1.5
end
page[:shown_notes].value = @comment.commentable.comment_ids.join(',')
page["#{id_prefix}_shown_notes"].value = @comment.commentable.comment_ids.join(',')
page["#{id_prefix}_comment_comment"].clear
page["#{id_prefix}_comment_comment"].focus

6 changes: 5 additions & 1 deletion app/views/comments/destroy.js.rjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
page[:shown_notes].value = @comment.commentable.comment_ids.join(',')
class_name = @comment.commentable.class.name.downcase
id_prefix = "#{class_name}_#{@comment.commentable.id}"

page["#{id_prefix}_shown_notes"].value = @comment.commentable.comment_ids.join(',')
page[dom_id(@comment)].visual_effect "blind_up", :duration => 0.25

9 changes: 5 additions & 4 deletions app/views/emails/_email.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- truncated = h(truncate(email.body.to_s.gsub("\n", " "), :length => 125 - email.subject.to_s.size))
- truncated = h(truncate(email.body_without_textile.to_s.gsub("\n", " "), :length => 125 - email.subject.to_s.size))
- formatted = email.body

%li.mail{ highlightable(dom_id(email, :tools), :off => "#f2f2f2"), :id => dom_id(email) }
Expand All @@ -17,7 +17,8 @@
%p
= h(email.subject)
%tt= " - " << truncated
.textile{ hidden_if(email.collapsed?), :id => dom_id(email, :formatted) }
%p= h(email.subject)
= auto_link(formatted)
%dt.textile{ hidden_if(email.collapsed?), :id => dom_id(email, :formatted) }
.email_content
%p= h(email.subject)
= auto_link(formatted)

6 changes: 5 additions & 1 deletion app/views/emails/destroy.js.rjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
page[:shown_emails].value = @email.mediator.email_ids.join(',')
class_name = @email.mediator.class.name.downcase
id_prefix = "#{class_name}_#{@email.mediator.id}"

page["#{id_prefix}_shown_emails"].value = @email.mediator.email_ids.join(',')
page[dom_id(@email)].visual_effect "blind_up", :duration => 0.25

13 changes: 7 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

root :to => 'home#index'

match 'activities' => 'home#index'
match 'admin' => 'admin/users#index', :as => :admin
match 'login' => 'authentications#new', :as => :login
match 'logout' => 'authentications#destroy', :as => :logout
match 'options' => 'home#options'
match 'profile' => 'users#show', :as => :profile
match 'signup' => 'users#new', :as => :signup
match 'timeline' => 'home#timeline', :as => :timeline
match 'timezone' => 'home#timezone', :as => :timezone
match 'toggle' => 'home#toggle'
match 'redraw' => 'home#redraw'
match 'home/activities' => 'home#index'
match 'home/options' => 'home#options'
match 'home/timeline' => 'home#timeline', :as => :timeline
match 'home/timezone' => 'home#timezone', :as => :timezone
match 'home/toggle' => 'home#toggle'
match 'home/redraw' => 'home#redraw'

resource :authentication

Expand Down Expand Up @@ -134,3 +134,4 @@
resources :plugins
end
end

18 changes: 14 additions & 4 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,26 @@ var crm = {
},

//----------------------------------------------------------------------------
flip_notes_and_emails: function(state, more, less) {
var notes = $("shown_notes").value;
var emails = $("shown_emails").value;
flip_notes_and_emails: function(state, more, less, el_prefix) {
if(!el_prefix){
var notes_field = "shown_notes";
var emails_field = "shown_emails";
var comment_new_field = "comment_new";
} else {
var notes_field = el_prefix + "_shown_notes";
var emails_field = el_prefix + "_shown_emails";
var comment_new_field = el_prefix + "_comment_new";
};

var notes = $(notes_field).value;
var emails = $(emails_field).value;

if (notes != "" || emails != "") {
new Ajax.Request(this.base_url + "/home/timeline", {
method : "get",
parameters : { type : "", id : notes + "+" + emails, state : state },
onComplete : function() {
$("comment_new").adjacent("li").each( function(li) {
$(comment_new_field).adjacent("li").each( function(li) {
var a = li.select("tt a.toggle")[0];
var dt = li.select("dt");
if (typeof(a) != "undefined") {
Expand Down

0 comments on commit 1d2f633

Please sign in to comment.