Module: TasksHelper

Defined in:
app/helpers/tasks_helper.rb

Overview

Copyright © 2008-2013 Michael Dvorkin and contributors.

Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php


Instance Method Summary collapse

Instance Method Details

#filtered_out?(view, filter = nil) ⇒ Boolean


Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'app/helpers/tasks_helper.rb', line 24

def filtered_out?(view, filter = nil)
  name = "filter_by_task_#{view}"
  if filter
    filters = (session[name].nil? ? [] : session[name].split(","))
    !filters.include?(filter.to_s)
  else
    session[name].blank?
  end
end

#hide_task_and_possibly_bucket(task, bucket) ⇒ Object




81
82
83
84
85
# File 'app/helpers/tasks_helper.rb', line 81

def hide_task_and_possibly_bucket(task, bucket)
  text = "jQuery('##{dom_id(task)}').remove();\n"
  text << "jQuery('#list_#{h bucket.to_s}').fadeOut({ duration:500 });\n" if Task.bucket_empty?(bucket, current_user, @view)
  text.html_safe
end

#insert_content(task, bucket, view) ⇒ Object




95
96
97
98
99
100
101
# File 'app/helpers/tasks_helper.rb', line 95

def insert_content(task, bucket, view)
  text = "jQuery('#list_#{bucket}').show();\n".html_safe
  html = render(:partial => view, :collection => [ task ], :locals => { :bucket => bucket })
  text << "jQuery('##{h bucket.to_s}').prepend('#{ j html }');\n".html_safe
  text << "jQuery('##{dom_id(task)}').effect('highlight', { duration:1500 });\n".html_safe
  text
end



47
48
49
50
# File 'app/helpers/tasks_helper.rb', line 47

def link_to_task_complete(pending, bucket)
  onclick = %Q/$("#{dom_id(pending, :name)}").style.textDecoration="line-through";/
  onclick << remote_function(:url => complete_task_path(pending), :method => :put, :with => "'bucket=#{bucket}'")
end



41
42
43
44
# File 'app/helpers/tasks_helper.rb', line 41

def link_to_task_delete(task, bucket)
  link_to(t(:delete) + "!", task_path(task, :bucket => bucket, :view => @view),
    :method => :delete, :remote => true)
end



35
36
37
38
# File 'app/helpers/tasks_helper.rb', line 35

def link_to_task_edit(task, bucket)
  link_to(t(:edit), edit_task_path(task, :bucket => bucket, :view => @view, :previous => "crm.find_form('edit_task')"),
    :method => :get, :remote => true)
end

#reassign(task) ⇒ Object




111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/tasks_helper.rb', line 111

def reassign(task)
  text = "".html_safe
  if @view == "pending" && @task.assigned_to.present? && @task.assigned_to != current_user.id
    text << hide_task_and_possibly_bucket(task, @task_before_update.bucket)
    text << tasks_flash( t(:task_assigned, (h @task.assignee.try(:full_name))) + " (#{link_to(t(:view_assigned_tasks), url_for(:controller => :tasks, :view => :assigned))})" )
  elsif @view == "assigned" && @task.assigned_to.blank?
    text << hide_task_and_possibly_bucket(task, @task_before_update.bucket)
    text << tasks_flash( t(:task_pending) + " (#{link_to(t(:view_pending_tasks), tasks_url)}.")
  else
    text << replace_content(@task, @task.bucket)
  end
  text << refresh_sidebar(:index, :filters)
  text
end

#replace_content(task, bucket = nil) ⇒ Object




88
89
90
91
92
# File 'app/helpers/tasks_helper.rb', line 88

def replace_content(task, bucket = nil)
  partial = (task.assigned_to && task.assigned_to != current_user.id) ? "assigned" : "pending"
  html = render(:partial => "tasks/#{partial}", :collection => [ task ], :locals => { :bucket => bucket })
  text = "jQuery('##{dom_id(task)}').html('#{ j html }');\n".html_safe
end

#reschedule(task) ⇒ Object




127
128
129
130
131
132
# File 'app/helpers/tasks_helper.rb', line 127

def reschedule(task)
  text = hide_task_and_possibly_bucket(task, @task_before_update.bucket)
  text << insert_content(task, task.bucket, @view)
  text << refresh_sidebar(:index, :filters)
  text
end

#task_filter_checkbox(view, filter, count) ⇒ Object

Sidebar checkbox control for filtering tasks by due date – used for pending and assigned views only.




11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/tasks_helper.rb', line 11

def task_filter_checkbox(view, filter, count)
  name = "filter_by_task_#{view}"
  checked = (session[name] ? session[name].split(",").include?(filter.to_s) : count > 0)
  onclick = remote_function(
    :url      => { :action => :filter, :view => view },
    :with     => "'filter='+this.value+'&checked='+this.checked",
    :loading  => "$('loading').show()",
    :complete => "$('loading').hide()"
  )
  check_box_tag("filters[]", filter, checked, :onclick => onclick, :id => "filters_#{filter.to_s.underscore}")
end

#task_summary(task) ⇒ Object

Task summary for RSS/ATOM feed.




54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/helpers/tasks_helper.rb', line 54

def task_summary(task)
  summary = [ task.category.blank? ? t(:other) : t(task.category) ]
  if @view != "completed"
    if @view == "pending" && task.user != current_user
      summary << t(:task_from, task.user.full_name)
    elsif @view == "assigned"
      summary << t(:task_from, task.assignee.full_name)
    end
    summary << "#{t(:related)} #{task.asset.name} (#{task.asset_type.downcase})" if task.asset_id?
    summary << if task.bucket == "due_asap"
      t(:task_due_now)
    elsif task.bucket == "due_later"
      t(:task_due_later)
    else
      l(task.due_at.localtime, :format => :mmddhhss)
    end
  else # completed
    summary << "#{t(:related)} #{task.asset.name} (#{task.asset_type.downcase})" if task.asset_id?
    summary << t(:task_completed_by,
                 :time_ago => distance_of_time_in_words(task.completed_at, Time.now),
                 :date     => l(task.completed_at.localtime, :format => :mmddhhss),
                 :user     => task.completor.full_name)
  end
  summary.join(', ')
end

#tasks_flash(message) ⇒ Object




104
105
106
107
108
# File 'app/helpers/tasks_helper.rb', line 104

def tasks_flash(message)
  text = "jQuery('#flash').html('#{ message }');\n"
  text << "crm.flash('notice', true)\n"
  text.html_safe
end