Skip to content

Commit

Permalink
sharing fixes: (1) make cursor a pointer in popup (2) more consistant…
Browse files Browse the repository at this point in the history
… behavior when selecting popup items (either by clicking or hitting return) (3) put display name on a second line for clarity
  • Loading branch information
elijh committed May 27, 2009
1 parent 17d9113 commit 80c6903
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
17 changes: 11 additions & 6 deletions app/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,32 @@ def link_to_entity(entity, options={})
#
# options:
# :avatar => nil | :xsmall | :small | :medium | :large | :xlarge (default: nil)
# :format => :short | :full | :both | :hover (default: full)
# :format => :short | :full | :both | :hover | :twolines (default: full)
# :block => false | true (default: false)
# :class => passed through to the tag as html class attr
# :style => passed through to the tag as html style attr
def display_entity(entity, options={})
options = {:format => :full}.merge(options)
display = nil; hover = nil
options[:class] = [options[:class], 'entity'].join(' ')
options[:block] = true if options[:format] == :twolines

if options[:avatar]
url = avatar_url(:id => (entity.avatar||0), :size => options[:avatar])
options[:class] = [options[:class], "name_icon", options[:avatar]].compact.join(' ')
options[:style] = [options[:style], "background-image:url(#{url})"].compact.join(';')
end
display, title, hover = case options[:format]
when :short then [entity.name, entity.display_name, nil]
when :full then [entity.display_name, entity.name, nil]
when :both then [entity.both_names, nil, nil]
when :hover then [entity.name, nil, entity.display_name]
when :short then [entity.name, h(entity.display_name), nil]
when :full then [h(entity.display_name), entity.name, nil]
when :both then [h(entity.both_names), nil, nil]
when :hover then [entity.name, nil, h(entity.display_name)]
when :twolines then ["<div class='name'>%s</div>%s"%[entity.name, (h(entity.display_name) if entity.name != entity.display_name)], nil, nil]
end
if hover
display += content_tag(:b,hover)
options[:style] = [options[:style], "position:relative"].compact.join(';') # to allow absolute popup with respect to the name
options[:style] = [options[:style], "position:relative"].compact.join(';')
# ^^ to allow absolute popup with respect to the name
end
element = options[:block] ? :div : :span
content_tag(element, display, :style => options[:style], :class => options[:class], :title => title)
Expand Down
2 changes: 1 addition & 1 deletion app/views/base_page/auto_complete/_recipient.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul class="side_list names">
<%- @recipients.each_with_index do |recipient, i| -%>
<li class="<%= 'selected' if i == 0 %>" >
<%= display_entity(recipient, :avatar => :xsmall, :format => :both, :block => true) %>
<%= display_entity(recipient, :avatar => :xsmall, :format => :twolines, :block => true) %>
</li>
<%- end -%>
</ul>
Expand Down
33 changes: 22 additions & 11 deletions app/views/base_page/share/_add_recipient_widget.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
<%
# if the recipient is written "Mr. Red (red)", then reformat to be just 'red'
after_update_function = "function(field,value) {
field.value = field.value.strip().replace(/.*\\((.*)\\).*/, '$1');
}"
empty_box = false if empty_box.nil?

# the remote action that is triggered when the 'add' button is pressed (or
# the popup item is selected).
add_action = {
:url => {:controller => 'base_page/share', :action => 'update', :page_id => nil, :add => true},
:loading => show_spinner('add_recipient'),
:with => %{'recipient[name]=' + $('recipient_name').value + '&recipient[access]=' + $('recipient[access]').value}
}
# submit the form when the enter key is pressed in the text box:
key_pressed_function = remote_function(add_action.merge(:condition => 'enterPressed(event)')) +
"; return !enterPressed(event);"
#if there are no recipients at all, we will never show the box
if @page
(@page.users + @page.groups - [@page.owner]).any? ? recipients_exist = true : recipient_exist = false
end

# this is called after an item in the popup has been selected.
# it makes it so selecting an item is like hitting the add button
after_update_function = "function(field,value) { #{remote_function(add_action)} }"

# this does three things:
# (1) submit the form when the enter key is pressed in the text box
# (2) don't do this, however, if the autocomplete popup is showing
# (3) also eat the event by returning false on a enter key so that the form is not submitted.
key_pressed_function = remote_function(
add_action.merge(:condition => "enterPressed(event) && !$('recipient_name_auto_complete').visible()")
) + "; return !enterPressed(event);"

#if there are no recipients at all, we will never show the box
if @page
(@page.users + @page.groups - [@page.owner]).any? ? recipients_exist = true : recipient_exist = false
end

%>
<table class='share_page_recipients'>
<tr>
Expand All @@ -36,6 +46,7 @@
:action => 'auto_complete_for_recipient_name'
},
:after_update_element => after_update_function,
:select => 'name',
:skip_style => true
}
)%>
Expand Down
9 changes: 9 additions & 0 deletions public/stylesheets/sass/core/ui_elements.sass
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ a[name]
.link_line em
color: #ccc

//
// ENTITIES
//
.entity .name
font-weight: bold
overflow: hidden

//
// SIDE LIST
//
Expand Down Expand Up @@ -431,6 +439,7 @@ div.auto_complete
li
margin: 0
padding: 8px
cursor: pointer
li.selected
background-color: #ffb
strong.highlight
Expand Down

0 comments on commit 80c6903

Please sign in to comment.