Sha256: 3d1c31961f93971e165b12e08498cdd1fe48781b067c6fc95df5d33a273b316e

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
module UsersHelper
  def language_for(user)
    _locale, language = languages.detect { |locale, _language| locale == user.preference[:locale] } if user.preference[:locale]
    language || "English"
  end

  def sort_by_language
    languages.sort.map do |locale, language|
      %[{ name: "#{language}", on_select: function() { #{redraw(:locale, [locale, language], url_for(action: :redraw, id: current_user))} } }]
    end
  end

  def all_users
    User.by_name
  end

  def user_select(asset, users, myself)
    user_options = user_options_for_select(users, myself)
    select(asset, :assigned_to, user_options,
           { include_blank: t(:unassigned) },
           style: 'width: 160px;',
           class: 'select2')
  end

  def user_options_for_select(users, myself)
    (users - [myself]).map { |u| [u.full_name, u.id] }.prepend([t(:myself), myself.id])
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fat_free_crm-0.22.0 app/helpers/users_helper.rb
fat_free_crm-0.21.0 app/helpers/users_helper.rb
fat_free_crm-0.20.1 app/helpers/users_helper.rb
fat_free_crm-0.20.0 app/helpers/users_helper.rb
fat_free_crm-0.19.2 app/helpers/users_helper.rb
fat_free_crm-0.19.0 app/helpers/users_helper.rb