Class: HomeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/home_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

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#indexObject




13
14
15
16
17
18
19
# File 'app/controllers/home_controller.rb', line 13

def index
  @activities = get_activities
  @my_tasks = Task.visible_on_dashboard(current_user).includes(:user, :asset).by_due_at
  @my_opportunities = Opportunity.visible_on_dashboard(current_user).includes(:account, :user, :tags).by_closes_on.by_amount
  @my_accounts = Account.visible_on_dashboard(current_user).includes(:user, :tags).by_name
  respond_with(@activities)
end

#optionsObject

GET /home/options AJAX




23
24
25
26
27
28
29
30
31
# File 'app/controllers/home_controller.rb', line 23

def options
  unless params[:cancel].true?
    @asset = current_user.pref[:activity_asset] || "all"
    @action = current_user.pref[:activity_event] || "all_events"
    @user = current_user.pref[:activity_user] || "all_users"
    @duration = current_user.pref[:activity_duration] || "two_days"
    @all_users = User.order("first_name, last_name")
  end
end

#redrawObject

GET /home/redraw AJAX




35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/home_controller.rb', line 35

def redraw
  current_user.pref[:activity_asset] = params[:asset] if params[:asset]
  current_user.pref[:activity_event] = params[:event] if params[:event]
  current_user.pref[:activity_user] = params[:user] if params[:user]
  current_user.pref[:activity_duration] = params[:duration] if params[:duration]
  @activities = get_activities

  respond_with(@activities) do |format|
    format.js { render :index }
  end
end

#timelineObject

GET /home/timeline AJAX




63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/home_controller.rb', line 63

def timeline
  state = params[:state].to_s
  if %w[Collapsed Expanded].include?(state)
    if (model_type = params[:type].to_s).present?
      if %w[comment email].include?(model_type)
        model = model_type.camelize.constantize
        item = model.find(params[:id])
        item.update_attribute(:state, state)
      end
    else
      comments, emails = params[:id].split("+")
      Comment.where(id: comments.split(',')).update_all(state: state) unless comments.blank?
      Email.where(id: emails.split(',')).update_all(state: state) unless emails.blank?
    end
  end

  head :ok
end

#timezoneObject

GET /home/timezone AJAX




84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/home_controller.rb', line 84

def timezone
  #
  # (new Date()).getTimezoneOffset() in JavaScript returns (UTC - localtime) in
  # minutes, while ActiveSupport::TimeZone expects (localtime - UTC) in seconds.
  #
  if params[:offset]
    session[:timezone_offset] = params[:offset].to_i * -60
    ActiveSupport::TimeZone[session[:timezone_offset]]
  end
  head :ok
end

#toggleObject

GET /home/toggle AJAX




49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/home_controller.rb', line 49

def toggle
  if (toggle_param = params[:id]&.to_sym)
    session[:toggle_states] ||= {}
    if session[:toggle_states][toggle_param]
      session[:toggle_states].delete(toggle_param)
    else
      session[:toggle_states][toggle_param] = true
    end
  end
  head :ok
end