Module: TasksHelper
- Defined in:
- app/helpers/tasks_helper.rb
Overview
Fat Free CRM Copyright © 2008-2011 by Michael Dvorkin
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Instance Method Summary collapse
-
#filtered_out?(view, filter = nil) ⇒ Boolean
—————————————————————————-.
-
#hide_task_and_possibly_bucket(id, 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
—————————————————————————-.
-
#links_to_task_export(view) ⇒ Object
Helper to display XLS, CSV, RSS, and ATOM links for tasks.
-
#reassign(id) ⇒ Object
—————————————————————————-.
-
#replace_content(task, bucket = nil) ⇒ Object
—————————————————————————-.
-
#reschedule(id) ⇒ Object
—————————————————————————-.
-
#task_filter_checbox(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
36 37 38 39 40 41 42 43 44 |
# File 'app/helpers/tasks_helper.rb', line 36 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(id, bucket) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/tasks_helper.rb', line 115 def hide_task_and_possibly_bucket(id, bucket) update_page do |page| page[id].replace "" if Task.bucket_empty?(bucket, @current_user, @view) page["list_#{bucket}"].visual_effect :fade, :duration => 0.5 end end end |
#insert_content(task, bucket, view) ⇒ Object
134 135 136 137 138 139 140 |
# File 'app/helpers/tasks_helper.rb', line 134 def insert_content(task, bucket, view) update_page do |page| page["list_#{bucket}"].show page.insert_html :top, bucket, :partial => view, :collection => [ task ], :locals => { :bucket => bucket } page[dom_id(task)].visual_effect :highlight, :duration => 1.5 end end |
#link_to_task_complete(pending, bucket) ⇒ Object
66 67 68 69 |
# File 'app/helpers/tasks_helper.rb', line 66 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 |
#link_to_task_delete(task, bucket) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/helpers/tasks_helper.rb', line 56 def link_to_task_delete(task, bucket) link_to(t(:delete) + "!", task_path(task), :method => :delete, :with => "{ bucket: '#{bucket}', view: '#{@view}' }", :before => visual_effect(:highlight, dom_id(task), :startcolor => "#ffe4e1"), :remote => true ) end |
#link_to_task_edit(task, bucket) ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/helpers/tasks_helper.rb', line 47 def link_to_task_edit(task, bucket) link_to(t(:edit), edit_task_path(task), :method => :get, :with => "{ bucket: '#{bucket}', view: '#{@view}', previous: crm.find_form('edit_task') }", :remote => true ) end |
#links_to_task_export(view) ⇒ Object
Helper to display XLS, CSV, RSS, and ATOM links for tasks.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/tasks_helper.rb', line 73 def links_to_task_export(view) token = @current_user.single_access_token exports = %w(xls csv).map do |format| link_to(format.upcase, "#{tasks_path}.#{format}?view=#{view}", :title => I18n.t(:"to_#{format}")) end feeds = %w(rss atom).map do |format| link_to(format.upcase, "#{tasks_path}.#{format}?view=#{view}&authentication_credentials=#{token}", :title => I18n.t(:"to_#{format}")) end (exports + feeds).join(' | ') end |
#reassign(id) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/helpers/tasks_helper.rb', line 151 def reassign(id) update_page do |page| if @view == "pending" && @task.assigned_to != @current_user.id page << hide_task_and_possibly_bucket(id, @task_before_update.bucket) page << tasks_flash("#{t(:task_assigned, @task.assignee.full_name)} (" << link_to(t(:view_assigned_tasks), url_for(:controller => :tasks, :view => :assigned)) << ").") elsif @view == "assigned" && @task.assigned_to.blank? page << hide_task_and_possibly_bucket(id, @task_before_update.bucket) page << tasks_flash("#{t(:task_pending)} (" << link_to(t(:view_pending_tasks), tasks_url) << ").") else page << replace_content(@task, @task.bucket) end page << (:index, :filters) end end |
#replace_content(task, bucket = nil) ⇒ Object
126 127 128 129 130 131 |
# File 'app/helpers/tasks_helper.rb', line 126 def replace_content(task, bucket = nil) partial = (task.assigned_to && task.assigned_to != @current_user.id) ? "assigned" : "pending" update_page do |page| page[dom_id(task)].replace_html :partial => "tasks/#{partial}", :collection => [ task ], :locals => { :bucket => bucket } end end |
#reschedule(id) ⇒ Object
167 168 169 170 171 172 173 |
# File 'app/helpers/tasks_helper.rb', line 167 def reschedule(id) update_page do |page| page << hide_task_and_possibly_bucket(id, @task_before_update.bucket) page << insert_content(@task, @task.bucket, @view) page << (:index, :filters) end end |
#task_filter_checbox(view, filter, count) ⇒ Object
Sidebar checkbox control for filtering tasks by due date – used for pending and assigned views only.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/tasks_helper.rb', line 23 def task_filter_checbox(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) end |
#task_summary(task) ⇒ Object
Task summary for RSS/ATOM feed.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/helpers/tasks_helper.rb', line 88 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
143 144 145 146 147 148 |
# File 'app/helpers/tasks_helper.rb', line 143 def tasks_flash() update_page do |page| page[:flash].replace_html page.call "crm.flash", :notice, true end end |