diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 167a558d..36510e22 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -139,13 +139,6 @@ module ApplicationHelper :target => "_blank" end - # offers a link for writing message to user - # checks for nil (useful for relations) - def link_to_user_message_if_valid(user) - user.nil? ? '??' : link_to(user.nick, new_message_path('message[mail_to]' => user.id), - :title => I18n.t('helpers.application.write_message')) - end - def bootstrap_flash flash_messages = [] flash.each do |type, message| @@ -167,4 +160,31 @@ module ApplicationHelper render :partial => 'shared/base_errors', :locals => {:error_messages => messages} end + # show a user, depending on settings + def show_user(user=@current_user, options = {})#full: false, markup: false, unique: false) + if user.nil? + "?" + elsif FoodsoftConfig[:use_nick] + if options[:full] and options[:markup] + raw "#{h user.nick} (#{h user.first_name} #{h user.last_name})" + elsif options[:full] + "#{user.nick} (#{user.first_name} #{user.last_name})" + else + user.nick + end + else + "#{user.first_name} #{user.last_name}" + (options[:unique] ? " (\##{user.id})" : '') + end + end + + # render user presentation linking to default action (write message) + def show_user_link(user=@current_user) + if user.nil? + show_user user + else + link_to show_user(user), new_message_path('message[mail_to]' => user.id), + :title => I18n.t('helpers.application.write_message') + end + end + end diff --git a/app/views/admin/base/index.html.haml b/app/views/admin/base/index.html.haml index fbe63c09..01cc5aaa 100644 --- a/app/views/admin/base/index.html.haml +++ b/app/views/admin/base/index.html.haml @@ -9,13 +9,15 @@ %table.table.table-striped %thead %tr - %th= t '.username' + - if FoodsoftConfig[:use_nick] + %th= t '.username' %th= t '.name' %th= t '.created_at' - for user in @users %tr{:class => cycle('even','odd', :name => 'users')} - %td= link_to user.nick, [:admin, user] - %td=h user.name + %td= link_to show_user(user, full: true), [:admin, user] + - if FoodsoftConfig[:use_nick] + %td= link_to user.name %td= format_date(user.created_on) = link_to t('.all_users'), admin_users_path | diff --git a/app/views/admin/users/_users.html.haml b/app/views/admin/users/_users.html.haml index 3f8b1df6..2f085f7b 100644 --- a/app/views/admin/users/_users.html.haml +++ b/app/views/admin/users/_users.html.haml @@ -4,7 +4,8 @@ %table.table.table-striped %thead %tr - %th= t '.login' + - if FoodsoftConfig[:use_nick] + %th= t '.login' %th= t '.name' %th= t '.email' %th= t 'admin.access_to' @@ -13,8 +14,9 @@ %tbody - for user in @users %tr - %td= link_to user.nick, [:admin, user] - %td= user.name + %td= link_to show_user(user, full: true), [:admin, user] + - if FoodsoftConfig[:use_nick] + %td= user.name %td= user.email %td= format_roles(user) %td= format_time(user.last_login) diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 4d0cd1ab..2321ccdb 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -1,4 +1,4 @@ -- title @user.nick +- title show_user(@user) .row-fluid .span3 @@ -6,8 +6,9 @@ %h4= t '.person' %p= t '.member_since', time: distance_of_time_in_words(Time.now, @user.created_on) %dl - %dt= t '.nick' - %dd= @user.nick + - if FoodsoftConfig[:use_nick] + %dt= t '.nick' + %dd= @user.nick %dt= t '.name' %dd= h @user.name %dt= t '.email' diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index 0fa52428..6973aa32 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -16,7 +16,7 @@ %td= link_to truncate(order.name), new_finance_order_path(order_id: order.id) %td=h format_time(order.ends) unless order.ends.nil? %td= order.closed? ? t('.cleared', amount: number_to_currency(order.foodcoop_result)) : t('.ended') - %td= order.updated_by.nil? ? '??' : order.updated_by.nick + %td= show_user(order.updated_by) %td - unless order.closed? = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-mini btn-primary' diff --git a/app/views/finance/financial_transactions/_transactions.html.haml b/app/views/finance/financial_transactions/_transactions.html.haml index ecfd1c9e..64b1c938 100644 --- a/app/views/finance/financial_transactions/_transactions.html.haml +++ b/app/views/finance/financial_transactions/_transactions.html.haml @@ -12,6 +12,6 @@ - @financial_transactions.each do |t| %tr %td= format_time(t.created_on) - %td= h t.user.nil? ? '??' : t.user.nick + %td= h show_user(t.user) %td= h t.note %td.currency{:style => "color:#{t.amount < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(t.amount) diff --git a/app/views/foodcoop/ordergroups/_ordergroups.html.haml b/app/views/foodcoop/ordergroups/_ordergroups.html.haml index 7c7780ee..20fbd0c9 100644 --- a/app/views/foodcoop/ordergroups/_ordergroups.html.haml +++ b/app/views/foodcoop/ordergroups/_ordergroups.html.haml @@ -13,7 +13,7 @@ - for ordergroup in @ordergroups %tr %td= ordergroup.name - %td=h ordergroup.users.collect { |u| u.nick }.join(", ") + %td=h ordergroup.users.collect { |u| show_user(u) }.join(", ") %td= format_date ordergroup.orders.order('orders.starts DESC').first.try(:starts) %td= link_to_new_message(message_params: {group_id: ordergroup.id}) diff --git a/app/views/foodcoop/users/_users.html.haml b/app/views/foodcoop/users/_users.html.haml index 90b1de3a..cbac9dc8 100644 --- a/app/views/foodcoop/users/_users.html.haml +++ b/app/views/foodcoop/users/_users.html.haml @@ -4,7 +4,8 @@ %table.table.table-striped %thead %tr - %th= t 'simple_form.labels.user.nick' + - if FoodsoftConfig[:use_nick] + %th= t 'simple_form.labels.user.nick' %th= t 'simple_form.labels.user.name' %th= t 'simple_form.labels.user.email' %th= t 'simple_form.labels.user.phone' @@ -13,7 +14,8 @@ %tbody - for user in @users %tr - %td= user.nick + - if FoodsoftConfig[:use_nick] + %td= user.nick %td= user.name if @current_user.role_admin? || user.settings.profile["name_is_public"] %td= user.email if @current_user.role_admin? || user.settings.profile["email_is_public"] %td= user.phone if @current_user.role_admin? || user.settings.profile["phone_is_public"] diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 2bd2f30b..7cd97150 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -19,7 +19,7 @@ %dt= t '.note' %dd= @order.note %dt= t '.created_by' - %dd= link_to_user_message_if_valid(@order.created_by) + %dd= show_user_link(@order.created_by) %dt= t '.ending' %dd= format_time(@order.ends) - unless @order.stockit? or @order.supplier.min_order_quantity.blank? @@ -29,7 +29,7 @@ %dd= number_to_currency @order.sum %dt= t '.last_update' %dd - = @group_order.updated_by.nick if @group_order.updated_by + = show_user(@group_order.updated_by) if @group_order.updated_by (#{format_time(@group_order.updated_on)}) %dt= t '.funds' %dd= number_to_currency(@ordering_data[:available_funds]) diff --git a/app/views/group_orders/show.html.haml b/app/views/group_orders/show.html.haml index ed3079ca..27a88eff 100644 --- a/app/views/group_orders/show.html.haml +++ b/app/views/group_orders/show.html.haml @@ -22,7 +22,7 @@ - else = t '.not_ordered' - if @order.closed? - %p= t '.closed_by', user: @order.updated_by.nick + %p= t '.closed_by', user: show_user(@order.updated_by) = link_to t('.comment'), "#comments" // Article box diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 3e70be75..236d5c5c 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -57,7 +57,7 @@ - for ft in current_user.ordergroup.financial_transactions.limit(5).order('created_on DESC') %tr %td= format_time(ft.created_on) - %td= h(ft.user.nil? ? '?' : ft.user.nick) + %td= h(show_user(ft.user)) %td= h(ft.note) - color = ft.amount < 0 ? 'red' : 'black' %td{:style => "color:#{color}; width:5em", :class => "currency"}= number_to_currency(ft.amount) diff --git a/app/views/home/ordergroup.html.haml b/app/views/home/ordergroup.html.haml index d28921a4..1fe79cbf 100644 --- a/app/views/home/ordergroup.html.haml +++ b/app/views/home/ordergroup.html.haml @@ -13,7 +13,7 @@ %h2= t '.people' %ul - for membership in @ordergroup.memberships - %li= membership.user.nick + %li= show_user membership.user = link_to t('.invite'), new_invite_path(:id => @ordergroup), :remote => true, class: 'btn btn-primary' .span8 %h2= t('.account_summary') diff --git a/app/views/home/profile.html.haml b/app/views/home/profile.html.haml index d462995a..3b0a8abb 100644 --- a/app/views/home/profile.html.haml +++ b/app/views/home/profile.html.haml @@ -3,7 +3,7 @@ .row-fluid .span7 %h3 - = h(t('.user.title', user: @current_user.nick)) + = h(t('.user.title', user: show_user)) %small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on) = simple_form_for(@current_user, :url => { :action => 'update_profile'}) do |f| = render :partial => 'shared/user_form_fields', :locals => {:f => f} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 2feb4fa3..f926e500 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -4,7 +4,7 @@ %ul.nav.nav-pills.pull-right %li.dropdown %a.dropdown-toggle(data-toggle="dropdown" href="#") - = current_user.nick + = show_user current_user %b.caret %ul.dropdown-menu %li= link_to t('.profile'), my_profile_path diff --git a/app/views/login/accept_invitation.html.haml b/app/views/login/accept_invitation.html.haml index 07489ebc..4ee300c5 100644 --- a/app/views/login/accept_invitation.html.haml +++ b/app/views/login/accept_invitation.html.haml @@ -1,6 +1,6 @@ - content_for :javascript do :javascript - $('user_nick').focus(); + $(#{FoodsoftConfig[:use_nick ? 'user_nick' : 'user_first_name'}).focus(); - title t('.title', name: FoodsoftConfig[:name]) = t('.body', group: h(@invite.group.name), foodcoop: h(FoodsoftConfig[:name])).html_safe diff --git a/app/views/login/new_password.html.haml b/app/views/login/new_password.html.haml index d3f2c58c..f3fe19e5 100644 --- a/app/views/login/new_password.html.haml +++ b/app/views/login/new_password.html.haml @@ -1,5 +1,5 @@ - title t('.title') -= t('.body', user: h(@user.nick)).html_safe += raw t('.body', user: h(show_user(@user))) = simple_form_for @user, :url => {:action => 'update_password', :id => @user.id, :token => @user.reset_password_token} do |form| = form.input :password = form.input :password_confirmation diff --git a/app/views/mailer/feedback.text.haml b/app/views/mailer/feedback.text.haml index 7708e297..a63e2fdc 100644 --- a/app/views/mailer/feedback.text.haml +++ b/app/views/mailer/feedback.text.haml @@ -1,3 +1,3 @@ -= t '.header', user: @user.nick, date: I18n.l(Time.now, :format => :short) += t '.header', user: show_user(@user), date: I18n.l(Time.now, :format => :short) \ = @feedback diff --git a/app/views/mailer/negative_balance.text.haml b/app/views/mailer/negative_balance.text.haml index 51d4f6e7..94734be5 100644 --- a/app/views/mailer/negative_balance.text.haml +++ b/app/views/mailer/negative_balance.text.haml @@ -1 +1 @@ -= t '.text', group: @group.name, when: @transaction.created_on.strftime('%d.%m.%Y um %H:%M'), balance: @group.account_balance, amount:@transaction.amount, note: @transaction.note, user: @transaction.user.nick, foodcoop: FoodsoftConfig[:name] += t '.text', group: @group.name, when: @transaction.created_on.strftime('%d.%m.%Y um %H:%M'), balance: @group.account_balance, amount:@transaction.amount, note: @transaction.note, user: show_user(@transaction.user), foodcoop: FoodsoftConfig[:name] diff --git a/app/views/mailer/order_result.text.haml b/app/views/mailer/order_result.text.haml index 8d64fbd2..cfe6cf78 100644 --- a/app/views/mailer/order_result.text.haml +++ b/app/views/mailer/order_result.text.haml @@ -1,4 +1,4 @@ -= raw t '.text0', ordergroup: @group_order.ordergroup.name, order: @order.name, when: I18n.l(@order.ends), user: @order.updated_by.nick += raw t '.text0', ordergroup: @group_order.ordergroup.name, order: @order.name, when: I18n.l(@order.ends), user: show_user(@order.updated_by) - for group_order_article in @group_order.group_order_articles.ordered.all(:include => :order_article) - article = group_order_article.order_article.article \- #{article.name}: #{group_order_article.result} x #{article.unit} = #{group_order_article.result * article.fc_price} diff --git a/app/views/mailer/reset_password.text.haml b/app/views/mailer/reset_password.text.haml index fd836232..2582d317 100644 --- a/app/views/mailer/reset_password.text.haml +++ b/app/views/mailer/reset_password.text.haml @@ -1 +1 @@ -= raw t '.text', user: @user.nick, link: @link, expires: I18n.l(@user.reset_password_expires) += raw t '.text', user: show_user(@user), link: @link, expires: I18n.l(@user.reset_password_expires) diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index 0e9a3926..2a34807d 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -13,7 +13,7 @@ %dt= t '.note' %dd= @order.note %dt= t '.created_by' - %dd= link_to_user_message_if_valid(@order.created_by) + %dd= show_user_link(@order.created_by) %dt= t '.begin' %dd= format_time(@order.starts) %dt= t '.ending' diff --git a/app/views/pages/_page_list_item.html.haml b/app/views/pages/_page_list_item.html.haml index 496e0720..cfd03a59 100644 --- a/app/views/pages/_page_list_item.html.haml +++ b/app/views/pages/_page_list_item.html.haml @@ -2,7 +2,7 @@ %tr %td{:style => "padding-left: #{ident}px"} = link_to page.title, wiki_page_path(page.permalink) - %td #{page.user.try(:nick)} (#{format_datetime_timespec(page.updated_at, t('.date_format'))}) + %td #{show_user page.user} (#{format_datetime_timespec(page.updated_at, t('.date_format'))}) -if siteMap == 1 -for child in page.children.all = render :partial => 'page_list_item', :locals => {:page => child, :level => level+1, :siteMap => 1} diff --git a/app/views/pages/show.html.haml b/app/views/pages/show.html.haml index 2c1d0bb1..91b7a9fc 100644 --- a/app/views/pages/show.html.haml +++ b/app/views/pages/show.html.haml @@ -17,7 +17,7 @@ - @page.versions.reverse.each do |version| %li = link_to I18n.l(version.updated_at, :format => t('.date_format')), version_page_path(@page, :version => version.lock_version) - = "(#{User.find_by_id(version.updated_by).try(:nick)})" + = "(#{show_user(User.find_by_id(version.updated_by))})" - unless @page.children.empty? #subpages.well.well-small{:style => "display:none"} @@ -48,4 +48,4 @@ %i.icon-edit= t '.edit' = link_to t('.delete'), @page, class: 'btn btn-danger', :method => :delete, :confirm => t('.delete_confirm') - != '| ' + t('.last_updated', user: h(@page.user.try(:nick)), when: format_datetime(@page.updated_at)) + != '| ' + t('.last_updated', user: show_user(@page.user), when: format_datetime(@page.updated_at)) diff --git a/app/views/pages/version.html.haml b/app/views/pages/version.html.haml index 222b465d..864c4f28 100644 --- a/app/views/pages/version.html.haml +++ b/app/views/pages/version.html.haml @@ -4,7 +4,7 @@ %h3= t '.title_version' %b= "#{format_datetime_timespec(@version.updated_at, t('.date_format'))}" %ul - %li= t '.author', user: User.find(@version.updated_by).nick + %li= t '.author', user: show_user(User.find(@version.updated_by)) %li= link_to t('.view_current'), wiki_page_path(:permalink => @page.permalink) %li= link_to t('.revert'), revert_page_path(@page, :version => @version.lock_version) diff --git a/app/views/shared/_comments.haml b/app/views/shared/_comments.haml index 27da9138..03d2c0b3 100644 --- a/app/views/shared/_comments.haml +++ b/app/views/shared/_comments.haml @@ -1,5 +1,5 @@ - comments.each do |comment| .comment[comment] %strong= comment.user.try(:ordergroup_name) - %small (#{comment.user.try(:nick)} am #{format_time(comment.created_at)}): + %small (#{show_user comment.user} am #{format_time(comment.created_at)}): = simple_format(comment.text) diff --git a/app/views/shared/_group.html.haml b/app/views/shared/_group.html.haml index b9b914ce..ebd34405 100644 --- a/app/views/shared/_group.html.haml +++ b/app/views/shared/_group.html.haml @@ -12,7 +12,7 @@ %dd - members = group.users = "(#{members.size})" - = members.collect(&:nick).join(", ") + = members.collect{|u| show_user(u)}.join(", ") - unless group.is_a?(Workgroup) %dt= t '.apple_limit' %dd= group.ignore_apple_restriction ? t('.deactivated') : t('.activated') diff --git a/app/views/shared/_open_orders.html.haml b/app/views/shared/_open_orders.html.haml index ebda2730..62e86fa6 100644 --- a/app/views/shared/_open_orders.html.haml +++ b/app/views/shared/_open_orders.html.haml @@ -19,7 +19,7 @@ %td= format_time(order.ends) unless order.ends.nil? - if group_order = order.group_order(ordergroup) - total += group_order.price - %td= "#{group_order.updated_by.nick} (#{format_time(group_order.updated_on)})" + %td= "#{show_user group_order.updated_by} (#{format_time(group_order.updated_on)})" %td.numeric= number_to_currency(group_order.price) - else %td{:colspan => 2} diff --git a/app/views/shared/_user_form_fields.html.haml b/app/views/shared/_user_form_fields.html.haml index bfd27f49..e9924a63 100644 --- a/app/views/shared/_user_form_fields.html.haml +++ b/app/views/shared/_user_form_fields.html.haml @@ -1,4 +1,5 @@ -= f.input :nick +- unless FoodsoftConfig[:use_nick] == false + = f.input :nick = f.input :first_name = f.input :last_name = f.input :email @@ -19,7 +20,8 @@ = t 'simple_form.labels.settings.settings_group.privacy' = profile.input 'phone_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['phone_is_public'] } = profile.input 'email_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['email_is_public'] } - = profile.input 'name_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['name_is_public'] } + - if FoodsoftConfig[:use_nick] + = profile.input 'name_is_public', as: :boolean, label: false, input_html: { checked: f.object.settings.profile['name_is_public'] } .settings-group %div{class: 'control-group'} diff --git a/app/views/shared/memberships/_current_members.rhtml b/app/views/shared/memberships/_current_members.rhtml index 81aab3a0..18939041 100644 --- a/app/views/shared/memberships/_current_members.rhtml +++ b/app/views/shared/memberships/_current_members.rhtml @@ -8,7 +8,7 @@