Class: TasksController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- 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 BaseController
#attach, #auto_complete, #discard, #field_group, #tagged, #timeline
Methods inherited from ApplicationController
Instance Method Details
#complete ⇒ Object
PUT /tasks/1/complete
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/controllers/tasks_controller.rb', line 144 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) rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |
#create ⇒ Object
POST /tasks
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/tasks_controller.rb', line 83 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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/tasks_controller.rb', line 125 def destroy @view = params[:view] || "pending" @task = Task.tracked_by(@current_user).find(params[:id]) @task.destroy if @task # 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) rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |
#edit ⇒ Object
GET /tasks/1/edit AJAX
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/tasks_controller.rb', line 64 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($1) end respond_with(@task) rescue ActiveRecord::RecordNotFound @previous ||= $1.to_i respond_to_not_found(:js) unless @task end |
#filter ⇒ Object
Ajax request to filter out a list of tasks. AJAX
166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/controllers/tasks_controller.rb', line 166 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 |
# 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/tasks_controller.rb', line 46 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("_") instance_variable_set("@asset", model.classify.constantize.my.find(id)) end respond_with(@task) rescue ActiveRecord::RecordNotFound # Kicks in if related asset was not found. (model, :js) if model end |
#show ⇒ Object
GET /tasks/1
33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/tasks_controller.rb', line 33 def show respond_to do |format| format.html { render :index } format.json { @task = Task.tracked_by(@current_user).find(params[:id]); render :json => @task } format.xml { @task = Task.tracked_by(@current_user).find(params[:id]); render :xml => @task } end rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |
#update ⇒ Object
PUT /tasks/1
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/tasks_controller.rb', line 96 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 rescue ActiveRecord::RecordNotFound respond_to_not_found(:js, :json, :xml) end |