Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#container_toggle(id) ⇒ Object


18
19
20
21
22
23
# File 'app/helpers/application_helper.rb', line 18

def container_toggle(id)
  link_to(
    image_tag("blank.png", :alt => t('common.collapse_expand')),
    "#",
    {:class => "container_toggle", :id => id} )
end

#count_undone_todos_and_notes_phrase(project) ⇒ Object


55
56
57
58
59
# File 'app/helpers/application_helper.rb', line 55

def count_undone_todos_and_notes_phrase(project)
  s = count_undone_todos_phrase(project)
  s += ", #{t('common.note', :count => project.note_count)}" unless project.note_count == 0
  s.html_safe
end

#count_undone_todos_phrase(todos_parent) ⇒ Object

Returns a count of next actions in the given context or project. The result is count and a string descriptor, correctly pluralised if there are no actions or multiple actions


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

def count_undone_todos_phrase(todos_parent)
  controller.count_undone_todos_phrase(todos_parent).html_safe
end

#count_undone_todos_phrase_text(todos_parent) ⇒ Object


51
52
53
# File 'app/helpers/application_helper.rb', line 51

def count_undone_todos_phrase_text(todos_parent)
  count_undone_todos_phrase(todos_parent).gsub(" "," ").html_safe
end

#date_format_for_date_pickerObject


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

def date_format_for_date_picker()
  [
    ['%m', 'mm'],
    ['%b', 'M'],
    ['%B', 'MM'],
    ['%d', 'dd'],
    ['%a', 'D'],
    ['%A', 'DD'],
    ['%y', 'y'],
    ['%Y', 'yy']
  ].inject(current_user.prefs.date_format) { |str, translation| str.gsub(*translation) }
end

#determine_all_done_pathObject


199
200
201
# File 'app/helpers/application_helper.rb', line 199

def determine_all_done_path
  done_path(controller.controller_name, :all_done)
end

#determine_done_pathObject


195
196
197
# File 'app/helpers/application_helper.rb', line 195

def determine_done_path
  done_path(controller.controller_name, :done)
end

#done_path(controller_name, type) ⇒ Object


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'app/helpers/application_helper.rb', line 178

def done_path(controller_name, type)
  case controller_name
  when "contexts"
    send("#{type}_todos_context_path",@context)
  when "projects"
    send("#{type}_todos_project_path", @project)
  when "todos"
    if @tag_name
      send("#{type}_tag_path",@tag_name)
    else
      send("#{type}_todos_path")
    end
  else
    send("#{type}_todos_path")
  end
end

#due_date(due) ⇒ Object

Check due date in comparison to today’s date Flag up date appropriately with a ‘traffic light’ colour code


32
33
34
# File 'app/helpers/application_helper.rb', line 32

def due_date(due)
  return DateLabelHelper::DueDateView.new(due, prefs).due_date_html
end

#due_date_mobile(due) ⇒ Object

Check due date in comparison to today’s date Flag up date appropriately with a ‘traffic light’ colour code Modified method for mobile screen


39
40
41
# File 'app/helpers/application_helper.rb', line 39

def due_date_mobile(due)
  return DateLabelHelper::DueDateView.new(due, prefs).due_date_mobile_html
end

#generate_i18n_stringsObject


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'app/helpers/application_helper.rb', line 149

def generate_i18n_strings
  js = "i18n_locale='#{I18n.locale}';\n"
  js << "i18n = new Array();\n"
  %w{
  shared.toggle_multi       shared.toggle_multi_title
  shared.hide_form          shared.hide_action_form_title
  shared.toggle_single      shared.toggle_single_title
  projects.hide_form        projects.hide_form_title
  projects.show_form        projects.show_form_title
  contexts.hide_form        contexts.hide_form_title
  contexts.show_form        contexts.show_form_title
  contexts.new_context_pre  contexts.new_context_post
  common.cancel             common.ok
  common.update             common.create
  common.ajaxError          todos.unresolved_dependency
  }.each do |s|
    js << "i18n['#{s}'] = '#{ t(s).gsub(/'/, "\\\\'") }';\n"
  end
  return js.html_safe
end

#get_list_of_error_messages_for(model) ⇒ Object


203
204
205
206
207
208
209
210
211
# File 'app/helpers/application_helper.rb', line 203

def get_list_of_error_messages_for(model)
  if model.errors.any?
    (:div, {:id=>"errorExplanation"}) do
      (:ul) do
        model.errors.full_messages.collect { |msg| concat((:li, msg)) }
      end
    end
  end
end

#group_view_by_menu_entryObject


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/application_helper.rb', line 3

def group_view_by_menu_entry
  # not set, no menu entry
  return "" if @group_view_by.nil?

  # if view == context, the menu shows Order By Project
  menu_name = @group_view_by == 'context' ? 'project' : 'context'

  (:li) do
    link_to(
      t("layouts.navigation.group_view_by_#{menu_name}"),
      '#',
      {:id => "group_view_by_link", :accesskey => "g", :title => t('layouts.navigation.group_view_by_title'), :x_current_group_by => @group_view_by} )
  end
end

78
79
80
# File 'app/helpers/application_helper.rb', line 78

def item_link_to_context(item)
  link_to_context( item.context, prefs.verbose_action_descriptors ? "[#{item.context.name}]" : "[C]" )
end

82
83
84
# File 'app/helpers/application_helper.rb', line 82

def item_link_to_project(item)
  link_to_project( item.project, prefs.verbose_action_descriptors ? "[#{item.project.name}]" : "[P]" )
end

#javascript_tag_for_i18n_datepickerObject


170
171
172
173
174
175
176
# File 'app/helpers/application_helper.rb', line 170

def javascript_tag_for_i18n_datepicker
  locale = I18n.locale
  # do not include en as locale since this the available by default
  if locale && locale != :en
    javascript_include_tag("i18n/jquery.ui.datepicker-#{locale}.js")
  end
end

#js_error_messages_for(object) ⇒ Object


253
254
255
# File 'app/helpers/application_helper.rb', line 253

def js_error_messages_for(object)
  escape_javascript(get_list_of_error_messages_for(object))
end

#js_render(partial, locals = {}, object = nil) ⇒ Object


245
246
247
248
249
250
251
# File 'app/helpers/application_helper.rb', line 245

def js_render(partial, locals = {}, object=nil)
  if object
    escape_javascript(render(partial: partial, locals: locals, object: object))
  else
    escape_javascript(render(partial: partial, locals: locals))
  end
end

61
62
63
# File 'app/helpers/application_helper.rb', line 61

def link_to_context(context, descriptor = sanitize(context.name))
  link_to( descriptor, context, :title => "View context: #{context.name}" )
end

213
214
215
216
217
218
219
220
221
222
223
224
# File 'app/helpers/application_helper.rb', line 213

def link_to_delete(type, object, descriptor = sanitize(object.name))
  link_to(
    descriptor,
    self.send("#{type}_path", object, :format => 'js'),
    {
      :id => "delete_#{type}_#{object.id}",
      :class => "delete_#{type}_button icon",
      :x_confirm_message => t("#{type}s.delete_#{type}_confirmation", :name => object.name),
      :title => t("#{type}s.delete_#{type}_title")
    }
  )
end

226
227
228
229
230
231
232
# File 'app/helpers/application_helper.rb', line 226

def link_to_edit(type, object, descriptor)
  link_to(descriptor, self.send("edit_#{type}_path", object),
    {
      :id => "link_edit_#{dom_id(object)}",
      :class => "#{type}_edit_settings icon"
    })
end

69
70
71
72
# File 'app/helpers/application_helper.rb', line 69

def link_to_edit_note (note, descriptor = sanitize(note.id.to_s))
  link_to(descriptor, edit_note_path(note),
    {:id => "link_edit_#{dom_id(note)}", :class => "note_edit_settings"})
end

65
66
67
# File 'app/helpers/application_helper.rb', line 65

def link_to_project(project, descriptor = sanitize(project.name))
  link_to( descriptor, project, :title => "View project: #{project.name}" )
end

74
75
76
# File 'app/helpers/application_helper.rb', line 74

def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name))
  link_to( descriptor, project_path(project, :format => 'm'), {:title => "View project: #{project.name}", :accesskey => accesskey} )
end

136
137
138
# File 'app/helpers/application_helper.rb', line 136

def link_to_sidebar_item(item)
  item.is_a?(Project) ? link_to_project( item ) : link_to_context( item )
end

25
26
27
# File 'app/helpers/application_helper.rb', line 25

def navigation_link(name, options = {}, html_options = nil, *parameters_for_method_reference)
  link_to name, options, html_options
end

#recurrence_pattern_as_text(recurring_todo) ⇒ Object


109
110
111
112
113
114
115
116
117
# File 'app/helpers/application_helper.rb', line 109

def recurrence_pattern_as_text(recurring_todo)
  rt = recurring_todo.recurring_target_as_text
  rp = recurring_todo.recurrence_pattern
  rp = " " + rp unless rp.nil?
  rts = recurrence_time_span(recurring_todo)
  # only add space if recurrence_time_span has content
  rts = " " + rts unless rts == ""
  return rt+rp+rts
end

#recurrence_time_span(rt) ⇒ Object


94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/application_helper.rb', line 94

def recurrence_time_span(rt)
  case rt.ends_on
  when "no_end_date"
    return time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from"))
  when "ends_on_number_of_times"
    return I18n.t("todos.recurrence.pattern.times", :number => rt.number_of_occurences)
  when "ends_on_end_date"
    starts = time_span_text(rt.start_from, I18n.t("todos.recurrence.pattern.from"))
    ends = time_span_text(rt.end_date, I18n.t("todos.recurrence.pattern.until"))
    return starts+ends
  else
    raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})"
  end
end

#render_flashObject


86
87
88
# File 'app/helpers/application_helper.rb', line 86

def render_flash
  render :partial => 'shared/flash', :object => flash
end

140
141
142
# File 'app/helpers/application_helper.rb', line 140

def sidebar_html_for_item(item)
  (:li, link_to_sidebar_item(item) + " (" + count_undone_todos_phrase(item)+")")
end

144
145
146
147
# File 'app/helpers/application_helper.rb', line 144

def sidebar_html_for_list(list)
  return (:li, t('sidebar.list_empty')).html_safe if list.empty?
  return list.inject("") { |html, item| html << sidebar_html_for_item(item) }.html_safe
end

132
133
134
# File 'app/helpers/application_helper.rb', line 132

def sidebar_html_for_titled_list (list, title)
  return (:h3, title+" (#{list.size})")  + (:ul, sidebar_html_for_list(list))
end

#source_view_keyObject


234
235
236
237
# File 'app/helpers/application_helper.rb', line 234

def source_view_key
  # uses @project.id or @context.id depending on source_view
  source_view_is_one_of(:project, :context) ? "#{@source_view}-#{eval("@#{@source_view}.id")}" : @source_view
end

#time_span_text(date, i18n_text) ⇒ Object


90
91
92
# File 'app/helpers/application_helper.rb', line 90

def time_span_text(date, i18n_text)
  return (date ? "#{i18n_text} #{format_date(date)}" : "").html_safe
end

#unique_object_name_for(name) ⇒ Object

create a unique object name which can be used in ajax calls returning js to prevent concurrent calls with same functions to overwrite each other functions


241
242
243
# File 'app/helpers/application_helper.rb', line 241

def unique_object_name_for(name)
  "#{name}_#{SecureRandom.hex(5)}"
end