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

#klass

Instance Method Details

#indexObject




24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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_to do |format|
    format.html # index.html.haml
    format.js   # index.js.rjs
    format.json { render :json => @activities }
    format.xml  { render :xml => @activities }
    format.xls  { send_data @activities.to_xls, :type => :xls }
    format.csv  { send_data @activities.to_csv, :type => :csv }
    format.rss  { render "index.rss.builder" }
    format.atom { render "index.atom.builder" }
  end
end

#optionsObject

GET /home/options AJAX




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

def options
  unless params[:cancel].true?
    @asset = @current_user.pref[:activity_asset] || "all"
    @action = @current_user.pref[:activity_action_type] || "all_actions"
    @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




55
56
57
58
59
60
61
62
63
# File 'app/controllers/home_controller.rb', line 55

def redraw
  @current_user.pref[:activity_asset] = params[:asset] if params[:asset]
  @current_user.pref[:activity_action_type] = params[:action_type] if params[:action_type]
  @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




78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/home_controller.rb', line 78

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




94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/home_controller.rb', line 94

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




67
68
69
70
71
72
73
74
# File 'app/controllers/home_controller.rb', line 67

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