Class: Admin::SettingsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/settings_controller.rb

Overview

Copyright © 2008-2013 Michael Dvorkin and contributors.

Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php


Instance Method Summary collapse

Instance Method Details

#indexObject

GET /admin/settings GET /admin/settings.xml




14
15
# File 'app/controllers/admin/settings_controller.rb', line 14

def index
end

#updateObject

PUT /admin/settings




19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/settings_controller.rb', line 19

def update
  settings = settings_params.to_h.with_indifferent_access

  # All settings are strings from the form.
  # We need to convert them to their correct types before saving.

  # Booleans
  %w[per_user_locale compound_address task_calendar_with_time require_first_names require_last_names require_unique_account_names comments_visible_on_dashboard enforce_international_phone_format].each do |key|
    settings[key] = (settings[key] == '1') if settings.key?(key)
  end

  # Nested booleans
  settings[:email_dropbox][:ssl] = (settings[:email_dropbox][:ssl] == '1') if settings.key?(:email_dropbox) && settings[:email_dropbox].key?(:ssl)
  settings[:email_comment_replies][:ssl] = (settings[:email_comment_replies][:ssl] == '1') if settings.key?(:email_comment_replies) && settings[:email_comment_replies].key?(:ssl)

  # Arrays from textareas
  %w[account_category campaign_status lead_status lead_source opportunity_stage task_category task_bucket task_completed priority_countries].each do |key|
    settings[key] = settings[key].split(/\r?\n/).map(&:strip).compact_blank if settings[key].is_a?(String)
  end

  # Symbols
  settings[:user_signup] = settings[:user_signup].to_sym if settings[:user_signup].is_a?(String)

  # Save all settings
  settings.each do |key, value|
    Setting[key] = value
  end

  redirect_to admin_settings_path, notice: t('fat_free_crm.settings_updated')
end