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




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

def hide_task_and_possibly_bucket(task, bucket)
  text = "$('##{h dom_id(task)}').remove();\n"
  text << "$('#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




101
102
103
104
105
106
107
# File 'app/helpers/tasks_helper.rb', line 101

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



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

def link_to_task_complete(pending, bucket)
  onclick = %{$("##{dom_id(pending, :name)}").css({textDecoration: "line-through"});}
  onclick << %{$.ajax("#{complete_task_path(pending)}", {type: "PUT", data: {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



53
54
55
56
# File 'app/helpers/tasks_helper.rb', line 53

def link_to_task_uncomplete(task, bucket)
  link_to(t(:task_uncomplete), uncomplete_task_path(task, bucket: bucket, view: @view),
          method: :put, remote: true)
end

#reassign(task) ⇒ Object




117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/helpers/tasks_helper.rb', line 117

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




94
95
96
97
98
# File 'app/helpers/tasks_helper.rb', line 94

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 = "$('##{dom_id(task)}').html('#{ j html }');\n".html_safe
end

#reschedule(task) ⇒ Object




133
134
135
136
137
138
# File 'app/helpers/tasks_helper.rb', line 133

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.




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

def task_filter_checkbox(view, filter, count)
  name = "filter_by_task_#{view}"
  checked = (session[name] ? session[name].split(",").include?(filter.to_s) : count > 0)
  url = url_for(action: :filter, view: view)
  onclick = %{
    $('#loading').show();
    $.post('#{url}', {filter: this.value, checked: this.checked}, function () {
      $('#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.




60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/tasks_helper.rb', line 60

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




110
111
112
113
114
# File 'app/helpers/tasks_helper.rb', line 110

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