From 80c6903e6aaab0e36641e8c3dc937582dbe934c5 Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Wed, 27 May 2009 13:34:10 -0700 Subject: [PATCH] sharing fixes: (1) make cursor a pointer in popup (2) more consistant behavior when selecting popup items (either by clicking or hitting return) (3) put display name on a second line for clarity --- app/helpers/url_helper.rb | 17 ++++++---- .../auto_complete/_recipient.html.erb | 2 +- .../share/_add_recipient_widget.html.erb | 33 ++++++++++++------- public/stylesheets/sass/core/ui_elements.sass | 9 +++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb index f1483d4de..30cbaa9ab 100644 --- a/app/helpers/url_helper.rb +++ b/app/helpers/url_helper.rb @@ -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 ["
%s
%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) diff --git a/app/views/base_page/auto_complete/_recipient.html.erb b/app/views/base_page/auto_complete/_recipient.html.erb index db37b2adc..a24b80ff6 100644 --- a/app/views/base_page/auto_complete/_recipient.html.erb +++ b/app/views/base_page/auto_complete/_recipient.html.erb @@ -1,7 +1,7 @@ diff --git a/app/views/base_page/share/_add_recipient_widget.html.erb b/app/views/base_page/share/_add_recipient_widget.html.erb index c5f15b17e..a0589d777 100644 --- a/app/views/base_page/share/_add_recipient_widget.html.erb +++ b/app/views/base_page/share/_add_recipient_widget.html.erb @@ -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 + %> @@ -36,6 +46,7 @@ :action => 'auto_complete_for_recipient_name' }, :after_update_element => after_update_function, + :select => 'name', :skip_style => true } )%> diff --git a/public/stylesheets/sass/core/ui_elements.sass b/public/stylesheets/sass/core/ui_elements.sass index 60d40434e..6fb4c09ab 100644 --- a/public/stylesheets/sass/core/ui_elements.sass +++ b/public/stylesheets/sass/core/ui_elements.sass @@ -77,6 +77,14 @@ a[name] .link_line em color: #ccc +// +// ENTITIES +// + +.entity .name + font-weight: bold + overflow: hidden + // // SIDE LIST // @@ -431,6 +439,7 @@ div.auto_complete li margin: 0 padding: 8px + cursor: pointer li.selected background-color: #ffb strong.highlight