Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TasksController < ApplicationController
- # GET /tasks
- # GET /tasks.xml
- def index
- @userParam = params[:viewUser];
- if (!@userParam)
- @userParam = "all";
- end
- @statusParam = params[:viewStatus];
- if (!@statusParam)
- @statusParam = "active";
- end
- @doneIdx = 3
- # Status.find(:first, :conditions => { :name => "Done"}).id
- @inactIdx = 2
- # Status.find(:first, :conditions => { :name => "Inactive"}).id
- @sqlQuery = "";
- if (@userParam && @userParam != "all")
- @sqlQuery += " user_id = #{@userParam} AND "
- end
- if (@statusParam && @statusParam != "active")
- @sqlQuery += " status_id = #{@statusParam} AND "
- end
- if (@statusParam == "active")
- @sqlQuery += " status_id NOT IN (#{@doneIdx}, #{@inactIdx})"
- else
- @sqlQuery += " status_id NOT IN (#{@inactIdx})"
- end
- @tasks = Task.find(:all, :conditions => @sqlQuery)
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @tasks }
- end
- end
- # GET /tasks/1
- # GET /tasks/1.xml
- def show
- @task = Task.find(params[:id])
- respond_to do |format|
- format.html
- format.xml { render :xml => @task }
- end
- end
- # GET /tasks/new
- # GET /tasks/new.xml
- def new
- @task = Task.new
- respond_to do |format|
- format.html { render :layout => false }
- format.xml { render :xml => @task }
- end
- end
- # GET /tasks/1/edit
- def edit
- @task = Task.find(params[:id])
- @viewUser = params[:viewUser]
- @viewStatus = params[:viewStatus]
- render :layout => false
- end
- # POST /tasks
- # POST /tasks.xml
- def create
- if (params[:userId])
- cookies[:currentUserId] = params[:userId]
- cookies[:currentUserName] = params[:userName]
- redirect_to(tasks_url)
- else
- @task = Task.new(params[:task])
- @ids = params[:user_ids].split(',')
- for id in @ids
- @task.user_ids << id.to_i
- end
- respond_to do |format|
- if @task.save
- format.html { redirect_to(tasks_url) }
- else
- format.html { render :action => "new" }
- end
- end
- end
- end
- # PUT /tasks/1
- # PUT /tasks/1.xml
- def update
- @task = Task.find(params[:id])
- @task.users = User.find(params[:user_ids]) if (params[:user_ids])
- respond_to do |format|
- if @task.update_attributes(params[:task])
- if (@task.status_id == 2)
- @user = User.find(:first, :conditions => { :id => @task.assigner_id })
- Notifier.deliver_task_finished_notification(@me, @task)
- end
- if (params[:viewUser])
- format.html { redirect_to tasks_url(:viewUser => params[:viewUser], :viewStatus => params[:viewStatus]) }
- elsif (!params[:dont_redirect])
- format.html { redirect_to(@task) }
- format.xml { head :ok }
- end
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
- end
- end
- end
- # DELETE /tasks/1
- # DELETE /tasks/1.xml
- def destroy
- @task = Task.find(params[:id])
- @task.destroy
- respond_to do |format|
- format.html { redirect_to(tasks_url) }
- format.xml { head :ok }
- end
- end
- def complete
- @task = Task.find(params[:id])
- @task.status_id = 4;
- @task.save
- logger.debug "Completed called!"
- end
- end
Add Comment
Please, Sign In to add comment