Class: TasksController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TasksController
- Defined in:
- app/controllers/tasks_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
-
#complete ⇒ Object
PUT /tasks/1/complete —————————————————————————-.
-
#create ⇒ Object
POST /tasks —————————————————————————-.
-
#destroy ⇒ Object
DELETE /tasks/1 —————————————————————————-.
-
#edit ⇒ Object
GET /tasks/1/edit AJAX —————————————————————————-.
-
#filter ⇒ Object
Ajax request to filter out a list of tasks.
-
#index ⇒ Object
GET /tasks —————————————————————————-.
-
#new ⇒ Object
GET /tasks/new —————————————————————————-.
-
#show ⇒ Object
GET /tasks/1 —————————————————————————-.
-
#update ⇒ Object
PUT /tasks/1 —————————————————————————-.
Methods inherited from ApplicationController
Instance Method Details
#complete ⇒ Object
PUT /tasks/1/complete
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/controllers/tasks_controller.rb', line 135 def complete @task = Task.tracked_by(@current_user).find(params[:id]) @task.update_attributes(:completed_at => Time.now, :completed_by => @current_user.id) if @task # Make sure bucket's div gets hidden if it's the last completed task in the bucket. if Task.bucket_empty?(params[:bucket], @current_user) @empty_bucket = params[:bucket] end unless params[:bucket].blank? respond_with(@task) end |
#create ⇒ Object
POST /tasks
80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/tasks_controller.rb', line 80 def create @view = params[:view] || "pending" @task = Task.new(params[:task]) # NOTE: we don't display validation messages for tasks. respond_with(@task) do |format| if @task.save if called_from_index_page? end end end |
#destroy ⇒ Object
DELETE /tasks/1
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/controllers/tasks_controller.rb', line 119 def destroy @view = params[:view] || "pending" @task = Task.tracked_by(@current_user).find(params[:id]) @task.destroy # Make sure bucket's div gets hidden if we're deleting last task in the bucket. if Task.bucket_empty?(params[:bucket], @current_user, @view) @empty_bucket = params[:bucket] end if called_from_index_page? respond_with(@task) end |
#edit ⇒ Object
GET /tasks/1/edit AJAX
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/tasks_controller.rb', line 63 def edit @view = params[:view] || "pending" @task = Task.tracked_by(@current_user).find(params[:id]) @users = User.except(@current_user).by_name @bucket = Setting.unroll(:task_bucket)[1..-1] << [ t(:due_specific_date, :default => 'On Specific Date...'), :specific_time ] @category = Setting.unroll(:task_category) @asset = @task.asset if @task.asset_id? if params[:previous].to_s =~ /(\d+)\z/ @previous = Task.tracked_by(@current_user).find_by_id($1) || $1.to_i end respond_with(@task) end |
#filter ⇒ Object
Ajax request to filter out a list of tasks. AJAX
154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/controllers/tasks_controller.rb', line 154 def filter @view = params[:view] || "pending" update_session do |filters| if params[:checked].true? filters << params[:filter] else filters.delete(params[:filter]) end end end |
#index ⇒ Object
GET /tasks
25 26 27 28 29 30 |
# File 'app/controllers/tasks_controller.rb', line 25 def index @view = params[:view] || "pending" @tasks = Task.find_all_grouped(@current_user, @view) respond_with(@tasks) end |
#new ⇒ Object
GET /tasks/new
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/tasks_controller.rb', line 42 def new @view = params[:view] || "pending" @task = Task.new @users = User.except(@current_user).by_name @bucket = Setting.unroll(:task_bucket)[1..-1] << [ t(:due_specific_date, :default => 'On Specific Date...'), :specific_time ] @category = Setting.unroll(:task_category) if params[:related] model, id = params[:related].split('_') if = model.classify.constantize.my.find_by_id(id) instance_variable_set("@asset", ) else (model) and return end end respond_with(@task) end |
#show ⇒ Object
GET /tasks/1
34 35 36 37 38 |
# File 'app/controllers/tasks_controller.rb', line 34 def show @task = Task.tracked_by(@current_user).find(params[:id]) respond_with(@task) end |
#update ⇒ Object
PUT /tasks/1
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/tasks_controller.rb', line 93 def update @view = params[:view] || "pending" @task = Task.tracked_by(@current_user).find(params[:id]) @task_before_update = @task.clone if @task.due_at && (@task.due_at < Date.today.to_time) @task_before_update.bucket = "overdue" else @task_before_update.bucket = @task.computed_bucket end respond_with(@task) do |format| if @task.update_attributes(params[:task]) @task.bucket = @task.computed_bucket if called_from_index_page? if Task.bucket_empty?(@task_before_update.bucket, @current_user, @view) @empty_bucket = @task_before_update.bucket end end end end end |