module TasksHelper
def remove_active_task(page)
page.visual_effect :blind_up, "task_#{@task.id}"
if @last_active_in_backlog
page["task_#{@task.id}"].ancestors.first.ancestors.first.remove
else
page.remove "task_#{@task.id}"
end
if @last_active
page.visual_effect :blind_up, "active_tasks"
page.visual_effect :appear, "no_tasks_message"
end
end
def remove_finished_task(page)
page.visual_effect :fade, "task_#{@task.id}"
page.remove "task_#{@task.id}"
if @last_finished
page.select('#completed_tasks tr').first.remove
end
end
def add_active_task(page)
if @task.lower_item.nil? || @task.lower_item.backlog != @task.backlog
page.insert_html :top, :active_tasks, '
'
elsif @task.lower_item
page.select('#active_tasks table tr').first.remove
page.select('#active_tasks table tr').first.remove
end
insert(page, render(:partial => "/tasks/task", :locals => { :task => @task, :i => 1, :active => true, :highlight_task => false, :update => :spotlight, :hidden => true }), '#active_tasks table')
fields_header = render(:partial => '/tasks/fields_header', :locals => { :backlog => @task.backlog, :active => true } )
insert(page, fields_header, '#active_tasks table')
insert(page, render(:partial => "/tasks/backlog_header", :locals => {:backlog => @task.backlog}), '#active_tasks table')
page[:no_tasks_message].hide
if @task.lower_item.nil?
page.visual_effect :appear, "active_tasks"
end
page.visual_effect :appear, "task_#{@task.id}"
end
def add_finished_task(page)
unless @first_finished
page.select('#completed_tasks tr').first.remove
end
page.insert_html :top, :completed_tasks, :partial => '/tasks/task', :locals => {:active => false, :hidden => true, :highlight_task => false}
page.visual_effect :appear, "task_#{@task.id}"
page.insert_html :top, :completed_tasks, :partial => '/tasks/fields_header', :locals => {:backlog => @task.backlog, :active => false}
end
def update_burn_down_chart(page)
page['burn_down_chart'].src = url_for(:controller => 'periods', :action => :burn_down_chart_thumbnail, :id => @task.period.id, :rnd => rand)
end
def record(page, script)
page.call("#{script};//")
end
def insert(page, content, selector, position = :top)
escaped_content = content.gsub("\n", '').gsub("'", "\\\\'")
record(page, "new Insertion.#{position.to_s.capitalize}($$('#{selector}').first(), '#{escaped_content}')")
end
end
class Time
def self.next_quarter
now = Time.now
now -= now.sec
next_quarter = now + (15 - now.min % 15).minutes
end
def self.previous_quarter
now = Time.now
now -= now.sec
previous_quarter = now - (now.min % 15).minutes
end
end