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
-
#filtered_out?(view, filter = nil) ⇒ Boolean
—————————————————————————-.
-
#hide_task_and_possibly_bucket(task, bucket) ⇒ Object
—————————————————————————-.
-
#insert_content(task, bucket, view) ⇒ Object
—————————————————————————-.
-
#link_to_task_complete(pending, bucket) ⇒ Object
—————————————————————————-.
-
#link_to_task_delete(task, bucket) ⇒ Object
—————————————————————————-.
-
#link_to_task_edit(task, bucket) ⇒ Object
—————————————————————————-.
-
#link_to_task_uncomplete(task, bucket) ⇒ Object
—————————————————————————-.
-
#reassign(task) ⇒ Object
—————————————————————————-.
-
#replace_content(task, bucket = nil) ⇒ Object
—————————————————————————-.
-
#reschedule(task) ⇒ Object
—————————————————————————-.
-
#task_filter_checkbox(view, filter, count) ⇒ Object
Sidebar checkbox control for filtering tasks by due date – used for pending and assigned views only.
-
#task_summary(task) ⇒ Object
Task summary for RSS/ATOM feed.
-
#tasks_flash(message) ⇒ Object
—————————————————————————-.
Instance Method Details
#filtered_out?(view, filter = nil) ⇒ Boolean
26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/tasks_helper.rb', line 26 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
89 90 91 92 93 |
# File 'app/helpers/tasks_helper.rb', line 89 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
104 105 106 107 108 109 110 |
# File 'app/helpers/tasks_helper.rb', line 104 def insert_content(task, bucket, view) html = render(partial: view, collection: [task], locals: { bucket: bucket }) text = "$('#list_#{bucket}').show();\n" text += "$('##{h bucket.to_s}').prepend('#{j html}');\n" text += "$('##{dom_id(task)}').effect('highlight', { duration:1500 });\n" text.html_safe end |
#link_to_task_complete(pending, bucket) ⇒ Object
49 50 51 52 |
# File 'app/helpers/tasks_helper.rb', line 49 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 |
#link_to_task_delete(task, bucket) ⇒ Object
43 44 45 46 |
# File 'app/helpers/tasks_helper.rb', line 43 def link_to_task_delete(task, bucket) link_to(t(:delete) + "!", task_path(task, bucket: bucket, view: @view), method: :delete, remote: true) end |
#link_to_task_edit(task, bucket) ⇒ Object
37 38 39 40 |
# File 'app/helpers/tasks_helper.rb', line 37 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 |
#link_to_task_uncomplete(task, bucket) ⇒ Object
55 56 57 58 |
# File 'app/helpers/tasks_helper.rb', line 55 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
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/helpers/tasks_helper.rb', line 120 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 << (:index, :filters) text end |
#replace_content(task, bucket = nil) ⇒ Object
96 97 98 99 100 101 |
# File 'app/helpers/tasks_helper.rb', line 96 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 text end |
#reschedule(task) ⇒ Object
136 137 138 139 140 141 |
# File 'app/helpers/tasks_helper.rb', line 136 def reschedule(task) text = hide_task_and_possibly_bucket(task, @task_before_update.bucket) text += insert_content(task, task.bucket, @view) text += (: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.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/tasks_helper.rb', line 12 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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/tasks_helper.rb', line 62 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
113 114 115 116 117 |
# File 'app/helpers/tasks_helper.rb', line 113 def tasks_flash() text = "$('#flash').html('#{sanitize()}');\n" text += "crm.flash('notice', true)\n" text.html_safe end |