From 140268365cf2dae0b854cd71865ff5454da9ab78 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 16 Aug 2011 12:43:08 -0700 Subject: [PATCH] Simplify aspect dropdown views --- app/helpers/aspect_global_helper.rb | 16 +++++++--------- app/views/aspects/_aspect_stream.haml | 2 +- app/views/aspects/index.mobile.haml | 2 +- app/views/shared/_aspect_dropdown.html.haml | 7 ++----- app/views/shared/_publisher.html.haml | 2 +- app/views/status_messages/bookmarklet.html.haml | 6 +++--- app/views/status_messages/new.haml | 4 ++-- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/helpers/aspect_global_helper.rb b/app/helpers/aspect_global_helper.rb index 77428b8fb..9bf1ad7d7 100644 --- a/app/helpers/aspect_global_helper.rb +++ b/app/helpers/aspect_global_helper.rb @@ -66,20 +66,14 @@ module AspectGlobalHelper end def aspect_membership_dropdown(contact, person, hang, aspect=nil) - @selected_aspects = [] - if contact.persisted? - @selected_aspects = all_aspects.find_all{|aspect| contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id}} - end - @selected_aspects = [@selected_aspects] if @selected_aspects.kind_of? Aspect + selected_aspects = all_aspects.select{|aspect| contact.aspect_memberships.detect{ |am| am.aspect_id == aspect.id } } render "shared/aspect_dropdown", :contact => @contact, - :selected_aspects => @selected_aspects, + :selected_aspects => selected_aspects, :person => person, :hang => hang, - :dropdown_class => "aspect_membership", - :button_class => ("in_aspects" if @selected_aspects.size > 0), - :may_create_new_aspect => ( @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification) + :dropdown_class => "aspect_membership" end def aspect_dropdown_list_item(aspect, checked) @@ -94,4 +88,8 @@ module AspectGlobalHelper LISTITEM str.html_safe end + + def dropdown_may_create_new_aspect + @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification + end end diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index c727f32fc..b086f3127 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -16,7 +16,7 @@ - else = @aspects.to_sentence -= render 'shared/publisher', :aspect => aspect, :aspect_ids => aspect_ids += render 'shared/publisher', :selected_aspects => @aspects, :aspect_ids => aspect_ids, :aspect => @aspect - if posts.length == 0 = render 'aspects/no_posts_message' diff --git a/app/views/aspects/index.mobile.haml b/app/views/aspects/index.mobile.haml index caea84c34..e7e22f20a 100644 --- a/app/views/aspects/index.mobile.haml +++ b/app/views/aspects/index.mobile.haml @@ -17,4 +17,4 @@ %a.more-link.paginate{:href => next_page_path} %h2= t("more") - content_for :subpages do - = render 'shared/publisher', :aspect_ids => @aspect_ids + = render 'shared/publisher', :aspect_ids => @aspect_ids, :selected_aspects => @aspects, :aspect => @aspect diff --git a/app/views/shared/_aspect_dropdown.html.haml b/app/views/shared/_aspect_dropdown.html.haml index 13ddfa5c8..6018db69f 100644 --- a/app/views/shared/_aspect_dropdown.html.haml +++ b/app/views/shared/_aspect_dropdown.html.haml @@ -3,10 +3,7 @@ -# the COPYRIGHT file. .dropdown{:class => ["hang_#{hang}", defined?(dropdown_class) && dropdown_class]} - - selected_aspects = [selected_aspects] if selected_aspects.kind_of? Aspect - - if !selected_aspects.kind_of? Array - - selected_aspects = all_aspects - .button.toggle{:class => (button_class if defined?(button_class))} + .button.toggle{:class => ("in_aspects" if selected_aspects.size > 0)} - if selected_aspects.size == 1 = selected_aspects.first.name - else @@ -18,7 +15,7 @@ - for aspect in all_aspects = aspect_dropdown_list_item(aspect, selected_aspects.include?(aspect) ) - - if (defined?may_create_new_aspect && may_create_new_aspect) && (defined?person && person) + - if (dropdown_may_create_new_aspect && defined?(person) && person) %li.newItem .add_aspect = link_to t('contacts.index.add_a_new_aspect'), new_aspect_path(:person_id => person.id), :rel => 'facebox' diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index 0261c4ef0..3b534281a 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -39,7 +39,7 @@ - for service in current_user.services = image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider.titleize, :class => "service_icon dim", :id =>"#{service.provider}", :maxchar => "#{service.class::MAX_CHARACTERS}" = link_to (image_tag "icons/monotone_wrench_settings.png"), "#question_mark_pane", :class => 'question_mark', :rel => 'facebox', :title => t('shared.public_explain.manage') - = render "shared/aspect_dropdown", :selected_aspects => Aspect.find(aspect_ids), :hang => 'left' + = render "shared/aspect_dropdown", :selected_aspects => selected_aspects, :hang => 'left' = status.submit t('.share'), :disable_with => t('.posting'), :class => 'button creation', :tabindex => 2 .facebox_content diff --git a/app/views/status_messages/bookmarklet.html.haml b/app/views/status_messages/bookmarklet.html.haml index 134d01303..3854a9255 100644 --- a/app/views/status_messages/bookmarklet.html.haml +++ b/app/views/status_messages/bookmarklet.html.haml @@ -10,7 +10,7 @@ :javascript Diaspora.widgets.i18n.loadLocale(#{get_javascript_strings_for(current_user.language).to_json}, "#{current_user.language}"); - $(document).ready(function() + $(document).ready(function() { Publisher.open(); $("#publisher").bind('ajax:success', function(){ @@ -24,7 +24,7 @@ if ("#{params[:notes]}".length > 0){ contents = contents + " - #{params[:notes]}"; } - + $("#publisher #status_message_fake_text").val(contents); $("#publisher #status_message_text").val(contents); $('input.button')[0].removeAttribute('disabled'); @@ -34,5 +34,5 @@ .span-15.last %h4 =t('bookmarklet.post_something') - = render :partial => 'shared/publisher', :locals => { :aspect => :profile, :aspects_with_person => @aspects, :aspect_ids => @aspect_ids} + = render :partial => 'shared/publisher', :locals => { :aspect => :profile, :selected_aspects => @aspects, :aspect_ids => @aspect_ids } diff --git a/app/views/status_messages/new.haml b/app/views/status_messages/new.haml index acc8b1677..003073df1 100644 --- a/app/views/status_messages/new.haml +++ b/app/views/status_messages/new.haml @@ -6,7 +6,7 @@ = javascript_include_tag "publisher.js" :javascript - $(document).ready(function() + $(document).ready(function() { var person = {name: '#{@person.name}', handle: '#{@person.diaspora_handle}' }; Publisher.autocompletion.onSelect($("#status_message_fake_text"),person,'#{@person.name}'); @@ -21,5 +21,5 @@ %h3 = t('.mentioning', :person => @person.name) - = render :partial => 'shared/publisher', :locals => { :aspect => @aspect, :aspect_ids => @aspect_ids, :aspects_with_person => @aspects_with_person, :person => @person} + = render :partial => 'shared/publisher', :locals => { :aspect => @aspect, :aspect_ids => @aspect_ids, :selected_aspects => @aspects_with_person, :person => @person}