Class: Fae::UtilitiesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/fae/utilities_controller.rb

Instance Method Summary collapse

Instance Method Details

#global_searchObject



35
36
37
38
39
40
41
42
# File 'app/controllers/fae/utilities_controller.rb', line 35

def global_search
  if params[:query].present? && params[:query].length > 2
    search_locals = { navigation_items: @fae_navigation.search(params[:query]), records: records_by_display_name(params[:query]) }
  else
    search_locals = { show_nav: true }
  end
  render partial: 'global_search_results', locals: search_locals
end

#language_preferenceObject



28
29
30
31
32
33
# File 'app/controllers/fae/utilities_controller.rb', line 28

def language_preference
  if params[:language].present? && (params[:language] == 'all' || Fae.languages.has_key?(params[:language].to_sym))
    current_user.update_column(:language, params[:language])
  end
  render body: nil
end

#sortObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/fae/utilities_controller.rb', line 15

def sort
  if request.xhr?
    ids = params[params[:object]]
    klass = params[:object].gsub('fae_', 'fae/').gsub('__', '/').classify.constantize
    items = klass.find(ids)
    items.each do |item|
      position = ids.index(item.id.to_s) + 1
      item.update_attribute(:position, position)
    end
  end
  render body: nil
end

#toggleObject



4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/fae/utilities_controller.rb', line 4

def toggle
  klass = params[:object].gsub('__', '/').classify
  if can_toggle(klass, params[:attr])
    klass = klass.constantize
    klass.find(params[:id]).toggle(params[:attr]).save(validate: false)
    render body: nil
  else
    render body: nil, status: :unauthorized
  end
end