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




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

def index
  @activities = get_activities
  @my_tasks = Task.visible_on_dashboard(current_user).by_due_at
  @my_opportunities = Opportunity.visible_on_dashboard(current_user).by_closes_on.by_amount
  @my_accounts = Account.visible_on_dashboard(current_user).by_name
  respond_with(@activities)
end

#optionsObject

GET /home/options AJAX




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

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

POST /home/redraw AJAX




33
34
35
36
37
38
39
40
# File 'app/controllers/home_controller.rb', line 33

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]

  render :index
end

#timelineObject

GET /home/timeline AJAX




55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/home_controller.rb', line 55

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

  render :nothing => true
end

#timezoneObject

GET /home/timezone AJAX




76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/home_controller.rb', line 76

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
  render :nothing => true
end

#toggleObject

GET /home/toggle AJAX




44
45
46
47
48
49
50
51
# File 'app/controllers/home_controller.rb', line 44

def toggle
  if session[params[:id].to_sym]
    session.delete(params[:id].to_sym)
  else
    session[params[:id].to_sym] = true
  end
  render :nothing => true
end