diff --git a/tracks/app/controllers/mobile_controller.rb b/tracks/app/controllers/mobile_controller.rb index 55f80ace..2d257e40 100644 --- a/tracks/app/controllers/mobile_controller.rb +++ b/tracks/app/controllers/mobile_controller.rb @@ -8,12 +8,12 @@ class MobileController < ApplicationController layout 'mobile' prepend_before_filter :login_required + before_filter :init, :except => :update # Plain list of all next actions, paginated 6 per page # Sorted by due date, then creation date # - def list - self.init + def index @page_title = @desc = "All actions" @todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC', :conditions => ['user_id = ? and state = ?', @user.id, "active"], @@ -22,14 +22,19 @@ class MobileController < ApplicationController end def detail - self.init @item = check_user_return_item @place = @item.context.id end - def update_action + def update if params[:id] - @item = check_user_return_item + @item = check_user_return_item + @item.update_attributes params[:item] + if params[:item][:state] == "1" + @item.state = "completed" + else + @item.state = "active" + end else if params[:item][:"show_from(1i)"] == "" @item = Todo.create(params[:item]) if params[:item] @@ -42,7 +47,7 @@ class MobileController < ApplicationController @item.user_id = @user.id if @item.save - redirect_to :action => 'list' + redirect_to :action => 'index' else self.init if params[:id] @@ -54,24 +59,23 @@ class MobileController < ApplicationController end def show_add_form - self.init + # Just render the view end def filter - self.init @type = params[:type] case params[:type] when 'context' @context = Context.find( params[:context][:id] ) @page_title = @desc = "#{@context.name}" - @todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC', - :conditions => ['user_id = ? and state = ? and context_id = ?', @user.id, "active", @context.id], :per_page => 6 ) + @todos = Todo.find( :all, :order => 'due IS NULL, due ASC, created_at ASC', + :conditions => ['user_id = ? and state = ? and context_id = ?', @user.id, "active", @context.id] ) @count = @all_todos.reject { |x| x.completed? || x.context_id != @context.id }.size when 'project' @project = Project.find( params[:project][:id] ) @page_title = @desc = "#{@project.name}" - @todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC', - :conditions => ['user_id = ? and state = ? and project_id = ?', @user.id, "active", @project.id], :per_page => 6 ) + @todos = Todo.find( :all, :order => 'due IS NULL, due ASC, created_at ASC', + :conditions => ['user_id = ? and state = ? and project_id = ?', @user.id, "active", @project.id] ) @count = @all_todos.reject { |x| x.completed? || x.project_id != @project.id }.size end end @@ -91,7 +95,7 @@ class MobileController < ApplicationController def init @contexts = @user.contexts.find(:all, :order => 'position ASC') @projects = @user.projects.find_in_state(:all, :active, :order => 'position ASC') - @all_todos = @user.todos.find(:all, :conditions => ['state = ? or state =?', "active", "completed"]) + @all_todos = @user.todos.find(:all, :conditions => ['state = ? or state = ?', "active", "completed"]) end end diff --git a/tracks/app/views/mobile/_mobile_actions.rhtml b/tracks/app/views/mobile/_mobile_actions.rhtml index feaa71c4..b1f45731 100644 --- a/tracks/app/views/mobile/_mobile_actions.rhtml +++ b/tracks/app/views/mobile/_mobile_actions.rhtml @@ -13,10 +13,12 @@ <% end -%>