Class: HomeController

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

Overview

Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.


Instance Method Summary collapse

Methods inherited from ApplicationController

#auto_complete

Instance Method Details

#indexObject




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

def index
  @hello = "Hello world" # The hook below can access controller's instance variables.
  hook(:home_controller, self, :params => "it works!")

  @activities = get_activities
  respond_with(@activities)
end

#optionsObject

GET /home/options AJAX




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

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




46
47
48
49
50
51
52
53
54
# File 'app/controllers/home_controller.rb', line 46

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
  render :index
end

#timelineObject

GET /home/timeline AJAX




69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/home_controller.rb', line 69

def timeline
  unless params[:type].empty?
    model = params[:type].camelize.constantize
    item = model.find(params[:id])
    item.update_attribute(:state, params[:state])
  else
    comments, emails = params[:id].split("+")
    Comment.update_all("state = '#{params[:state]}'", "id IN (#{comments})") unless comments.blank?
    Email.update_all("state = '#{params[:state]}'", "id IN (#{emails})") unless emails.blank?
  end

  render :nothing => true
end

#timezoneObject

GET /home/timezone AJAX




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

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




58
59
60
61
62
63
64
65
# File 'app/controllers/home_controller.rb', line 58

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