Chris@14
|
1 # redMine - project management software
|
Chris@14
|
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
|
Chris@14
|
3 #
|
Chris@14
|
4 # This program is free software; you can redistribute it and/or
|
Chris@14
|
5 # modify it under the terms of the GNU General Public License
|
Chris@14
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@14
|
7 # of the License, or (at your option) any later version.
|
Chris@14
|
8 #
|
Chris@14
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@14
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@14
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@14
|
12 # GNU General Public License for more details.
|
Chris@14
|
13 #
|
Chris@14
|
14 # You should have received a copy of the GNU General Public License
|
Chris@14
|
15 # along with this program; if not, write to the Free Software
|
Chris@14
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@14
|
17
|
Chris@14
|
18 require 'forwardable'
|
Chris@14
|
19 require 'cgi'
|
Chris@14
|
20
|
Chris@14
|
21 module ApplicationHelper
|
Chris@14
|
22 include Redmine::WikiFormatting::Macros::Definitions
|
Chris@14
|
23 include Redmine::I18n
|
Chris@14
|
24 include GravatarHelper::PublicMethods
|
Chris@14
|
25
|
Chris@14
|
26 extend Forwardable
|
Chris@14
|
27 def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
Chris@14
|
28
|
Chris@14
|
29 # Return true if user is authorized for controller/action, otherwise false
|
Chris@14
|
30 def authorize_for(controller, action)
|
Chris@14
|
31 User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
Chris@14
|
32 end
|
Chris@14
|
33
|
Chris@14
|
34 # Display a link if user is authorized
|
Chris@14
|
35 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
Chris@14
|
36 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
Chris@14
|
37 end
|
Chris@14
|
38
|
Chris@14
|
39 # Display a link to remote if user is authorized
|
Chris@14
|
40 def link_to_remote_if_authorized(name, options = {}, html_options = nil)
|
Chris@14
|
41 url = options[:url] || {}
|
Chris@14
|
42 link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
|
Chris@14
|
43 end
|
Chris@14
|
44
|
Chris@14
|
45 # Displays a link to user's account page if active
|
Chris@14
|
46 def link_to_user(user, options={})
|
Chris@14
|
47 if user.is_a?(User)
|
Chris@14
|
48 name = h(user.name(options[:format]))
|
Chris@14
|
49 if user.active?
|
Chris@14
|
50 link_to name, :controller => 'users', :action => 'show', :id => user
|
Chris@14
|
51 else
|
Chris@14
|
52 name
|
Chris@14
|
53 end
|
Chris@14
|
54 else
|
Chris@14
|
55 h(user.to_s)
|
Chris@14
|
56 end
|
Chris@14
|
57 end
|
Chris@14
|
58
|
Chris@14
|
59 # Displays a link to +issue+ with its subject.
|
Chris@14
|
60 # Examples:
|
Chris@14
|
61 #
|
Chris@14
|
62 # link_to_issue(issue) # => Defect #6: This is the subject
|
Chris@14
|
63 # link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
|
Chris@14
|
64 # link_to_issue(issue, :subject => false) # => Defect #6
|
Chris@14
|
65 # link_to_issue(issue, :project => true) # => Foo - Defect #6
|
Chris@14
|
66 #
|
Chris@14
|
67 def link_to_issue(issue, options={})
|
Chris@14
|
68 title = nil
|
Chris@14
|
69 subject = nil
|
Chris@14
|
70 if options[:subject] == false
|
Chris@14
|
71 title = truncate(issue.subject, :length => 60)
|
Chris@14
|
72 else
|
Chris@14
|
73 subject = issue.subject
|
Chris@14
|
74 if options[:truncate]
|
Chris@14
|
75 subject = truncate(subject, :length => options[:truncate])
|
Chris@14
|
76 end
|
Chris@14
|
77 end
|
Chris@14
|
78 s = link_to "#{issue.tracker} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue},
|
Chris@14
|
79 :class => issue.css_classes,
|
Chris@14
|
80 :title => title
|
Chris@14
|
81 s << ": #{h subject}" if subject
|
Chris@14
|
82 s = "#{h issue.project} - " + s if options[:project]
|
Chris@14
|
83 s
|
Chris@14
|
84 end
|
Chris@14
|
85
|
Chris@14
|
86 # Generates a link to an attachment.
|
Chris@14
|
87 # Options:
|
Chris@14
|
88 # * :text - Link text (default to attachment filename)
|
Chris@14
|
89 # * :download - Force download (default: false)
|
Chris@14
|
90 def link_to_attachment(attachment, options={})
|
Chris@14
|
91 text = options.delete(:text) || attachment.filename
|
Chris@14
|
92 action = options.delete(:download) ? 'download' : 'show'
|
Chris@14
|
93
|
Chris@14
|
94 link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
|
Chris@14
|
95 end
|
Chris@14
|
96
|
Chris@14
|
97 # Generates a link to a SCM revision
|
Chris@14
|
98 # Options:
|
Chris@14
|
99 # * :text - Link text (default to the formatted revision)
|
Chris@14
|
100 def link_to_revision(revision, project, options={})
|
Chris@14
|
101 text = options.delete(:text) || format_revision(revision)
|
Chris@14
|
102
|
Chris@14
|
103 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision))
|
Chris@14
|
104 end
|
Chris@14
|
105
|
Chris@14
|
106 def toggle_link(name, id, options={})
|
Chris@14
|
107 onclick = "Element.toggle('#{id}'); "
|
Chris@14
|
108 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
|
Chris@14
|
109 onclick << "return false;"
|
Chris@14
|
110 link_to(name, "#", :onclick => onclick)
|
Chris@14
|
111 end
|
Chris@14
|
112
|
Chris@14
|
113 def image_to_function(name, function, html_options = {})
|
Chris@14
|
114 html_options.symbolize_keys!
|
Chris@14
|
115 tag(:input, html_options.merge({
|
Chris@14
|
116 :type => "image", :src => image_path(name),
|
Chris@14
|
117 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
Chris@14
|
118 }))
|
Chris@14
|
119 end
|
Chris@14
|
120
|
Chris@14
|
121 def prompt_to_remote(name, text, param, url, html_options = {})
|
Chris@14
|
122 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
|
Chris@14
|
123 link_to name, {}, html_options
|
Chris@14
|
124 end
|
Chris@14
|
125
|
Chris@14
|
126 def format_activity_title(text)
|
Chris@14
|
127 h(truncate_single_line(text, :length => 100))
|
Chris@14
|
128 end
|
Chris@14
|
129
|
Chris@14
|
130 def format_activity_day(date)
|
Chris@14
|
131 date == Date.today ? l(:label_today).titleize : format_date(date)
|
Chris@14
|
132 end
|
Chris@14
|
133
|
Chris@14
|
134 def format_activity_description(text)
|
Chris@14
|
135 h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
|
Chris@14
|
136 end
|
Chris@14
|
137
|
Chris@14
|
138 def format_version_name(version)
|
Chris@14
|
139 if version.project == @project
|
Chris@14
|
140 h(version)
|
Chris@14
|
141 else
|
Chris@14
|
142 h("#{version.project} - #{version}")
|
Chris@14
|
143 end
|
Chris@14
|
144 end
|
Chris@14
|
145
|
Chris@14
|
146 def due_date_distance_in_words(date)
|
Chris@14
|
147 if date
|
Chris@14
|
148 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
|
Chris@14
|
149 end
|
Chris@14
|
150 end
|
Chris@14
|
151
|
Chris@14
|
152 def render_page_hierarchy(pages, node=nil)
|
Chris@14
|
153 content = ''
|
Chris@14
|
154 if pages[node]
|
Chris@14
|
155 content << "<ul class=\"pages-hierarchy\">\n"
|
Chris@14
|
156 pages[node].each do |page|
|
Chris@14
|
157 content << "<li>"
|
Chris@14
|
158 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
|
Chris@14
|
159 :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
Chris@14
|
160 content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
|
Chris@14
|
161 content << "</li>\n"
|
Chris@14
|
162 end
|
Chris@14
|
163 content << "</ul>\n"
|
Chris@14
|
164 end
|
Chris@14
|
165 content
|
Chris@14
|
166 end
|
Chris@14
|
167
|
Chris@14
|
168 # Renders flash messages
|
Chris@14
|
169 def render_flash_messages
|
Chris@14
|
170 s = ''
|
Chris@14
|
171 flash.each do |k,v|
|
Chris@14
|
172 s << content_tag('div', v, :class => "flash #{k}")
|
Chris@14
|
173 end
|
Chris@14
|
174 s
|
Chris@14
|
175 end
|
Chris@14
|
176
|
Chris@14
|
177 # Renders tabs and their content
|
Chris@14
|
178 def render_tabs(tabs)
|
Chris@14
|
179 if tabs.any?
|
Chris@14
|
180 render :partial => 'common/tabs', :locals => {:tabs => tabs}
|
Chris@14
|
181 else
|
Chris@14
|
182 content_tag 'p', l(:label_no_data), :class => "nodata"
|
Chris@14
|
183 end
|
Chris@14
|
184 end
|
Chris@14
|
185
|
Chris@14
|
186 # Renders the project quick-jump box
|
Chris@14
|
187 def render_project_jump_box
|
Chris@14
|
188 # Retrieve them now to avoid a COUNT query
|
Chris@14
|
189 projects = User.current.projects.all
|
Chris@14
|
190 if projects.any?
|
Chris@14
|
191 s = '<select onchange="if (this.value != \'\') { window.location = this.value; }">' +
|
Chris@14
|
192 "<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
|
Chris@14
|
193 '<option value="" disabled="disabled">---</option>'
|
Chris@14
|
194 s << project_tree_options_for_select(projects, :selected => @project) do |p|
|
Chris@14
|
195 { :value => url_for(:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item) }
|
Chris@14
|
196 end
|
Chris@14
|
197 s << '</select>'
|
Chris@14
|
198 s
|
Chris@14
|
199 end
|
Chris@14
|
200 end
|
Chris@14
|
201
|
Chris@14
|
202 def project_tree_options_for_select(projects, options = {})
|
Chris@14
|
203 s = ''
|
Chris@14
|
204 project_tree(projects) do |project, level|
|
Chris@14
|
205 name_prefix = (level > 0 ? (' ' * 2 * level + '» ') : '')
|
Chris@14
|
206 tag_options = {:value => project.id}
|
Chris@14
|
207 if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
|
Chris@14
|
208 tag_options[:selected] = 'selected'
|
Chris@14
|
209 else
|
Chris@14
|
210 tag_options[:selected] = nil
|
Chris@14
|
211 end
|
Chris@14
|
212 tag_options.merge!(yield(project)) if block_given?
|
Chris@14
|
213 s << content_tag('option', name_prefix + h(project), tag_options)
|
Chris@14
|
214 end
|
Chris@14
|
215 s
|
Chris@14
|
216 end
|
Chris@14
|
217
|
Chris@14
|
218 # Yields the given block for each project with its level in the tree
|
Chris@14
|
219 def project_tree(projects, &block)
|
Chris@14
|
220 ancestors = []
|
Chris@14
|
221 projects.sort_by(&:lft).each do |project|
|
Chris@14
|
222 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
Chris@14
|
223 ancestors.pop
|
Chris@14
|
224 end
|
Chris@14
|
225 yield project, ancestors.size
|
Chris@14
|
226 ancestors << project
|
Chris@14
|
227 end
|
Chris@14
|
228 end
|
Chris@14
|
229
|
Chris@14
|
230 def project_nested_ul(projects, &block)
|
Chris@14
|
231 s = ''
|
Chris@14
|
232 if projects.any?
|
Chris@14
|
233 ancestors = []
|
Chris@14
|
234 projects.sort_by(&:lft).each do |project|
|
Chris@14
|
235 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
Chris@14
|
236 s << "<ul>\n"
|
Chris@14
|
237 else
|
Chris@14
|
238 ancestors.pop
|
Chris@14
|
239 s << "</li>"
|
Chris@14
|
240 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
Chris@14
|
241 ancestors.pop
|
Chris@14
|
242 s << "</ul></li>\n"
|
Chris@14
|
243 end
|
Chris@14
|
244 end
|
Chris@14
|
245 s << "<li>"
|
Chris@14
|
246 s << yield(project).to_s
|
Chris@14
|
247 ancestors << project
|
Chris@14
|
248 end
|
Chris@14
|
249 s << ("</li></ul>\n" * ancestors.size)
|
Chris@14
|
250 end
|
Chris@14
|
251 s
|
Chris@14
|
252 end
|
Chris@14
|
253
|
Chris@14
|
254 def principals_check_box_tags(name, principals)
|
Chris@14
|
255 s = ''
|
Chris@14
|
256 principals.sort.each do |principal|
|
Chris@14
|
257 s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
|
Chris@14
|
258 end
|
Chris@14
|
259 s
|
Chris@14
|
260 end
|
Chris@14
|
261
|
Chris@14
|
262 # Truncates and returns the string as a single line
|
Chris@14
|
263 def truncate_single_line(string, *args)
|
Chris@14
|
264 truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
|
Chris@14
|
265 end
|
Chris@14
|
266
|
Chris@14
|
267 # Truncates at line break after 250 characters or options[:length]
|
Chris@14
|
268 def truncate_lines(string, options={})
|
Chris@14
|
269 length = options[:length] || 250
|
Chris@14
|
270 if string.to_s =~ /\A(.{#{length}}.*?)$/m
|
Chris@14
|
271 "#{$1}..."
|
Chris@14
|
272 else
|
Chris@14
|
273 string
|
Chris@14
|
274 end
|
Chris@14
|
275 end
|
Chris@14
|
276
|
Chris@14
|
277 def html_hours(text)
|
Chris@14
|
278 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
|
Chris@14
|
279 end
|
Chris@14
|
280
|
Chris@14
|
281 def authoring(created, author, options={})
|
Chris@14
|
282 l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created))
|
Chris@14
|
283 end
|
Chris@14
|
284
|
Chris@14
|
285 def time_tag(time)
|
Chris@14
|
286 text = distance_of_time_in_words(Time.now, time)
|
Chris@14
|
287 if @project
|
Chris@14
|
288 link_to(text, {:controller => 'projects', :action => 'activity', :id => @project, :from => time.to_date}, :title => format_time(time))
|
Chris@14
|
289 else
|
Chris@14
|
290 content_tag('acronym', text, :title => format_time(time))
|
Chris@14
|
291 end
|
Chris@14
|
292 end
|
Chris@14
|
293
|
Chris@14
|
294 def syntax_highlight(name, content)
|
Chris@14
|
295 Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
|
Chris@14
|
296 end
|
Chris@14
|
297
|
Chris@14
|
298 def to_path_param(path)
|
Chris@14
|
299 path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
|
Chris@14
|
300 end
|
Chris@14
|
301
|
Chris@14
|
302 def pagination_links_full(paginator, count=nil, options={})
|
Chris@14
|
303 page_param = options.delete(:page_param) || :page
|
Chris@14
|
304 per_page_links = options.delete(:per_page_links)
|
Chris@14
|
305 url_param = params.dup
|
Chris@14
|
306 # don't reuse query params if filters are present
|
Chris@14
|
307 url_param.merge!(:fields => nil, :values => nil, :operators => nil) if url_param.delete(:set_filter)
|
Chris@14
|
308
|
Chris@14
|
309 html = ''
|
Chris@14
|
310 if paginator.current.previous
|
Chris@14
|
311 html << link_to_remote_content_update('« ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
|
Chris@14
|
312 end
|
Chris@14
|
313
|
Chris@14
|
314 html << (pagination_links_each(paginator, options) do |n|
|
Chris@14
|
315 link_to_remote_content_update(n.to_s, url_param.merge(page_param => n))
|
Chris@14
|
316 end || '')
|
Chris@14
|
317
|
Chris@14
|
318 if paginator.current.next
|
Chris@14
|
319 html << ' ' + link_to_remote_content_update((l(:label_next) + ' »'), url_param.merge(page_param => paginator.current.next))
|
Chris@14
|
320 end
|
Chris@14
|
321
|
Chris@14
|
322 unless count.nil?
|
Chris@14
|
323 html << " (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})"
|
Chris@14
|
324 if per_page_links != false && links = per_page_links(paginator.items_per_page)
|
Chris@14
|
325 html << " | #{links}"
|
Chris@14
|
326 end
|
Chris@14
|
327 end
|
Chris@14
|
328
|
Chris@14
|
329 html
|
Chris@14
|
330 end
|
Chris@14
|
331
|
Chris@14
|
332 def per_page_links(selected=nil)
|
Chris@14
|
333 url_param = params.dup
|
Chris@14
|
334 url_param.clear if url_param.has_key?(:set_filter)
|
Chris@14
|
335
|
Chris@14
|
336 links = Setting.per_page_options_array.collect do |n|
|
Chris@14
|
337 n == selected ? n : link_to_remote(n, {:update => "content",
|
Chris@14
|
338 :url => params.dup.merge(:per_page => n),
|
Chris@14
|
339 :method => :get},
|
Chris@14
|
340 {:href => url_for(url_param.merge(:per_page => n))})
|
Chris@14
|
341 end
|
Chris@14
|
342 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
|
Chris@14
|
343 end
|
Chris@14
|
344
|
Chris@14
|
345 def reorder_links(name, url)
|
Chris@14
|
346 link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :title => l(:label_sort_highest)) +
|
Chris@14
|
347 link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), :method => :post, :title => l(:label_sort_higher)) +
|
Chris@14
|
348 link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), :method => :post, :title => l(:label_sort_lower)) +
|
Chris@14
|
349 link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), url.merge({"#{name}[move_to]" => 'lowest'}), :method => :post, :title => l(:label_sort_lowest))
|
Chris@14
|
350 end
|
Chris@14
|
351
|
Chris@14
|
352 def breadcrumb(*args)
|
Chris@14
|
353 elements = args.flatten
|
Chris@14
|
354 elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil
|
Chris@14
|
355 end
|
Chris@14
|
356
|
Chris@14
|
357 def other_formats_links(&block)
|
Chris@14
|
358 concat('<p class="other-formats">' + l(:label_export_to))
|
Chris@14
|
359 yield Redmine::Views::OtherFormatsBuilder.new(self)
|
Chris@14
|
360 concat('</p>')
|
Chris@14
|
361 end
|
Chris@14
|
362
|
Chris@14
|
363 def page_header_title
|
Chris@14
|
364 if @project.nil? || @project.new_record?
|
Chris@14
|
365 h(Setting.app_title)
|
Chris@14
|
366 else
|
Chris@14
|
367 b = []
|
Chris@14
|
368 ancestors = (@project.root? ? [] : @project.ancestors.visible)
|
Chris@14
|
369 if ancestors.any?
|
Chris@14
|
370 root = ancestors.shift
|
Chris@14
|
371 b << link_to(h(root), {:controller => 'projects', :action => 'show', :id => root, :jump => current_menu_item}, :class => 'root')
|
Chris@14
|
372 if ancestors.size > 2
|
Chris@14
|
373 b << '…'
|
Chris@14
|
374 ancestors = ancestors[-2, 2]
|
Chris@14
|
375 end
|
Chris@14
|
376 b += ancestors.collect {|p| link_to(h(p), {:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item}, :class => 'ancestor') }
|
Chris@14
|
377 end
|
Chris@14
|
378 b << h(@project)
|
Chris@14
|
379 b.join(' » ')
|
Chris@14
|
380 end
|
Chris@14
|
381 end
|
Chris@14
|
382
|
Chris@14
|
383 def html_title(*args)
|
Chris@14
|
384 if args.empty?
|
Chris@14
|
385 title = []
|
Chris@14
|
386 title << @project.name if @project
|
Chris@14
|
387 title += @html_title if @html_title
|
Chris@14
|
388 title << Setting.app_title
|
Chris@14
|
389 title.select {|t| !t.blank? }.join(' - ')
|
Chris@14
|
390 else
|
Chris@14
|
391 @html_title ||= []
|
Chris@14
|
392 @html_title += args
|
Chris@14
|
393 end
|
Chris@14
|
394 end
|
Chris@14
|
395
|
Chris@14
|
396 def accesskey(s)
|
Chris@14
|
397 Redmine::AccessKeys.key_for s
|
Chris@14
|
398 end
|
Chris@14
|
399
|
Chris@14
|
400 # Formats text according to system settings.
|
Chris@14
|
401 # 2 ways to call this method:
|
Chris@14
|
402 # * with a String: textilizable(text, options)
|
Chris@14
|
403 # * with an object and one of its attribute: textilizable(issue, :description, options)
|
Chris@14
|
404 def textilizable(*args)
|
Chris@14
|
405 options = args.last.is_a?(Hash) ? args.pop : {}
|
Chris@14
|
406 case args.size
|
Chris@14
|
407 when 1
|
Chris@14
|
408 obj = options[:object]
|
Chris@14
|
409 text = args.shift
|
Chris@14
|
410 when 2
|
Chris@14
|
411 obj = args.shift
|
Chris@14
|
412 attr = args.shift
|
Chris@14
|
413 text = obj.send(attr).to_s
|
Chris@14
|
414 else
|
Chris@14
|
415 raise ArgumentError, 'invalid arguments to textilizable'
|
Chris@14
|
416 end
|
Chris@14
|
417 return '' if text.blank?
|
Chris@14
|
418 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
Chris@14
|
419 only_path = options.delete(:only_path) == false ? false : true
|
Chris@14
|
420
|
Chris@14
|
421 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
Chris@14
|
422
|
Chris@14
|
423 parse_non_pre_blocks(text) do |text|
|
Chris@14
|
424 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
|
Chris@14
|
425 send method_name, text, project, obj, attr, only_path, options
|
Chris@14
|
426 end
|
Chris@14
|
427 end
|
Chris@14
|
428 end
|
Chris@14
|
429
|
Chris@14
|
430 def parse_non_pre_blocks(text)
|
Chris@14
|
431 s = StringScanner.new(text)
|
Chris@14
|
432 tags = []
|
Chris@14
|
433 parsed = ''
|
Chris@14
|
434 while !s.eos?
|
Chris@14
|
435 s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
|
Chris@14
|
436 text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
|
Chris@14
|
437 if tags.empty?
|
Chris@14
|
438 yield text
|
Chris@14
|
439 end
|
Chris@14
|
440 parsed << text
|
Chris@14
|
441 if tag
|
Chris@14
|
442 if closing
|
Chris@14
|
443 if tags.last == tag.downcase
|
Chris@14
|
444 tags.pop
|
Chris@14
|
445 end
|
Chris@14
|
446 else
|
Chris@14
|
447 tags << tag.downcase
|
Chris@14
|
448 end
|
Chris@14
|
449 parsed << full_tag
|
Chris@14
|
450 end
|
Chris@14
|
451 end
|
Chris@14
|
452 # Close any non closing tags
|
Chris@14
|
453 while tag = tags.pop
|
Chris@14
|
454 parsed << "</#{tag}>"
|
Chris@14
|
455 end
|
Chris@14
|
456 parsed
|
Chris@14
|
457 end
|
Chris@14
|
458
|
Chris@14
|
459 def parse_inline_attachments(text, project, obj, attr, only_path, options)
|
Chris@14
|
460 # when using an image link, try to use an attachment, if possible
|
Chris@14
|
461 if options[:attachments] || (obj && obj.respond_to?(:attachments))
|
Chris@14
|
462 attachments = nil
|
Chris@14
|
463 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
Chris@14
|
464 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
Chris@14
|
465 attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
|
Chris@14
|
466 # search for the picture in attachments
|
Chris@14
|
467 if found = attachments.detect { |att| att.filename.downcase == filename }
|
Chris@14
|
468 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
|
Chris@14
|
469 desc = found.description.to_s.gsub('"', '')
|
Chris@14
|
470 if !desc.blank? && alttext.blank?
|
Chris@14
|
471 alt = " title=\"#{desc}\" alt=\"#{desc}\""
|
Chris@14
|
472 end
|
Chris@14
|
473 "src=\"#{image_url}\"#{alt}"
|
Chris@14
|
474 else
|
Chris@14
|
475 m
|
Chris@14
|
476 end
|
Chris@14
|
477 end
|
Chris@14
|
478 end
|
Chris@14
|
479 end
|
Chris@14
|
480
|
Chris@14
|
481 # Wiki links
|
Chris@14
|
482 #
|
Chris@14
|
483 # Examples:
|
Chris@14
|
484 # [[mypage]]
|
Chris@14
|
485 # [[mypage|mytext]]
|
Chris@14
|
486 # wiki links can refer other project wikis, using project name or identifier:
|
Chris@14
|
487 # [[project:]] -> wiki starting page
|
Chris@14
|
488 # [[project:|mytext]]
|
Chris@14
|
489 # [[project:mypage]]
|
Chris@14
|
490 # [[project:mypage|mytext]]
|
Chris@14
|
491 def parse_wiki_links(text, project, obj, attr, only_path, options)
|
Chris@14
|
492 text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
|
Chris@14
|
493 link_project = project
|
Chris@14
|
494 esc, all, page, title = $1, $2, $3, $5
|
Chris@14
|
495 if esc.nil?
|
Chris@14
|
496 if page =~ /^([^\:]+)\:(.*)$/
|
Chris@14
|
497 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
|
Chris@14
|
498 page = $2
|
Chris@14
|
499 title ||= $1 if page.blank?
|
Chris@14
|
500 end
|
Chris@14
|
501
|
Chris@14
|
502 if link_project && link_project.wiki
|
Chris@14
|
503 # extract anchor
|
Chris@14
|
504 anchor = nil
|
Chris@14
|
505 if page =~ /^(.+?)\#(.+)$/
|
Chris@14
|
506 page, anchor = $1, $2
|
Chris@14
|
507 end
|
Chris@14
|
508 # check if page exists
|
Chris@14
|
509 wiki_page = link_project.wiki.find_page(page)
|
Chris@14
|
510 url = case options[:wiki_links]
|
Chris@14
|
511 when :local; "#{title}.html"
|
Chris@14
|
512 when :anchor; "##{title}" # used for single-file wiki export
|
Chris@14
|
513 else
|
Chris@14
|
514 url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
|
Chris@14
|
515 end
|
Chris@14
|
516 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
Chris@14
|
517 else
|
Chris@14
|
518 # project or wiki doesn't exist
|
Chris@14
|
519 all
|
Chris@14
|
520 end
|
Chris@14
|
521 else
|
Chris@14
|
522 all
|
Chris@14
|
523 end
|
Chris@14
|
524 end
|
Chris@14
|
525 end
|
Chris@14
|
526
|
Chris@14
|
527 # Redmine links
|
Chris@14
|
528 #
|
Chris@14
|
529 # Examples:
|
Chris@14
|
530 # Issues:
|
Chris@14
|
531 # #52 -> Link to issue #52
|
Chris@14
|
532 # Changesets:
|
Chris@14
|
533 # r52 -> Link to revision 52
|
Chris@14
|
534 # commit:a85130f -> Link to scmid starting with a85130f
|
Chris@14
|
535 # Documents:
|
Chris@14
|
536 # document#17 -> Link to document with id 17
|
Chris@14
|
537 # document:Greetings -> Link to the document with title "Greetings"
|
Chris@14
|
538 # document:"Some document" -> Link to the document with title "Some document"
|
Chris@14
|
539 # Versions:
|
Chris@14
|
540 # version#3 -> Link to version with id 3
|
Chris@14
|
541 # version:1.0.0 -> Link to version named "1.0.0"
|
Chris@14
|
542 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
|
Chris@14
|
543 # Attachments:
|
Chris@14
|
544 # attachment:file.zip -> Link to the attachment of the current object named file.zip
|
Chris@14
|
545 # Source files:
|
Chris@14
|
546 # source:some/file -> Link to the file located at /some/file in the project's repository
|
Chris@14
|
547 # source:some/file@52 -> Link to the file's revision 52
|
Chris@14
|
548 # source:some/file#L120 -> Link to line 120 of the file
|
Chris@14
|
549 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
Chris@14
|
550 # export:some/file -> Force the download of the file
|
Chris@14
|
551 # Forum messages:
|
Chris@14
|
552 # message#1218 -> Link to message with id 1218
|
Chris@14
|
553 def parse_redmine_links(text, project, obj, attr, only_path, options)
|
Chris@14
|
554 text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m|
|
Chris@14
|
555 leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $7, $6 || $8
|
Chris@14
|
556 link = nil
|
Chris@14
|
557 if esc.nil?
|
Chris@14
|
558 if prefix.nil? && sep == 'r'
|
Chris@14
|
559 if project && (changeset = project.changesets.find_by_revision(identifier))
|
Chris@14
|
560 link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
Chris@14
|
561 :class => 'changeset',
|
Chris@14
|
562 :title => truncate_single_line(changeset.comments, :length => 100))
|
Chris@14
|
563 end
|
Chris@14
|
564 elsif sep == '#'
|
Chris@14
|
565 oid = identifier.to_i
|
Chris@14
|
566 case prefix
|
Chris@14
|
567 when nil
|
Chris@14
|
568 if issue = Issue.visible.find_by_id(oid, :include => :status)
|
Chris@14
|
569 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
Chris@14
|
570 :class => issue.css_classes,
|
Chris@14
|
571 :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
Chris@14
|
572 end
|
Chris@14
|
573 when 'document'
|
Chris@14
|
574 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
Chris@14
|
575 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
Chris@14
|
576 :class => 'document'
|
Chris@14
|
577 end
|
Chris@14
|
578 when 'version'
|
Chris@14
|
579 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
|
Chris@14
|
580 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
Chris@14
|
581 :class => 'version'
|
Chris@14
|
582 end
|
Chris@14
|
583 when 'message'
|
Chris@14
|
584 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
|
Chris@14
|
585 link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
|
Chris@14
|
586 :controller => 'messages',
|
Chris@14
|
587 :action => 'show',
|
Chris@14
|
588 :board_id => message.board,
|
Chris@14
|
589 :id => message.root,
|
Chris@14
|
590 :anchor => (message.parent ? "message-#{message.id}" : nil)},
|
Chris@14
|
591 :class => 'message'
|
Chris@14
|
592 end
|
Chris@14
|
593 when 'project'
|
Chris@14
|
594 if p = Project.visible.find_by_id(oid)
|
Chris@14
|
595 link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p},
|
Chris@14
|
596 :class => 'project'
|
Chris@14
|
597 end
|
Chris@14
|
598 end
|
Chris@14
|
599 elsif sep == ':'
|
Chris@14
|
600 # removes the double quotes if any
|
Chris@14
|
601 name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
Chris@14
|
602 case prefix
|
Chris@14
|
603 when 'document'
|
Chris@14
|
604 if project && document = project.documents.find_by_title(name)
|
Chris@14
|
605 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
Chris@14
|
606 :class => 'document'
|
Chris@14
|
607 end
|
Chris@14
|
608 when 'version'
|
Chris@14
|
609 if project && version = project.versions.find_by_name(name)
|
Chris@14
|
610 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
Chris@14
|
611 :class => 'version'
|
Chris@14
|
612 end
|
Chris@14
|
613 when 'commit'
|
Chris@14
|
614 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
Chris@14
|
615 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
Chris@14
|
616 :class => 'changeset',
|
Chris@14
|
617 :title => truncate_single_line(changeset.comments, :length => 100)
|
Chris@14
|
618 end
|
Chris@14
|
619 when 'source', 'export'
|
Chris@14
|
620 if project && project.repository
|
Chris@14
|
621 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
|
Chris@14
|
622 path, rev, anchor = $1, $3, $5
|
Chris@14
|
623 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
|
Chris@14
|
624 :path => to_path_param(path),
|
Chris@14
|
625 :rev => rev,
|
Chris@14
|
626 :anchor => anchor,
|
Chris@14
|
627 :format => (prefix == 'export' ? 'raw' : nil)},
|
Chris@14
|
628 :class => (prefix == 'export' ? 'source download' : 'source')
|
Chris@14
|
629 end
|
Chris@14
|
630 when 'attachment'
|
Chris@14
|
631 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
Chris@14
|
632 if attachments && attachment = attachments.detect {|a| a.filename == name }
|
Chris@14
|
633 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
|
Chris@14
|
634 :class => 'attachment'
|
Chris@14
|
635 end
|
Chris@14
|
636 when 'project'
|
Chris@14
|
637 if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
|
Chris@14
|
638 link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p},
|
Chris@14
|
639 :class => 'project'
|
Chris@14
|
640 end
|
Chris@14
|
641 end
|
Chris@14
|
642 end
|
Chris@14
|
643 end
|
Chris@14
|
644 leading + (link || "#{prefix}#{sep}#{identifier}")
|
Chris@14
|
645 end
|
Chris@14
|
646 end
|
Chris@14
|
647
|
Chris@14
|
648 # Same as Rails' simple_format helper without using paragraphs
|
Chris@14
|
649 def simple_format_without_paragraph(text)
|
Chris@14
|
650 text.to_s.
|
Chris@14
|
651 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
|
Chris@14
|
652 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
|
Chris@14
|
653 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
Chris@14
|
654 end
|
Chris@14
|
655
|
Chris@14
|
656 def lang_options_for_select(blank=true)
|
Chris@14
|
657 (blank ? [["(auto)", ""]] : []) +
|
Chris@14
|
658 valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
|
Chris@14
|
659 end
|
Chris@14
|
660
|
Chris@14
|
661 def label_tag_for(name, option_tags = nil, options = {})
|
Chris@14
|
662 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
Chris@14
|
663 content_tag("label", label_text)
|
Chris@14
|
664 end
|
Chris@14
|
665
|
Chris@14
|
666 def labelled_tabular_form_for(name, object, options, &proc)
|
Chris@14
|
667 options[:html] ||= {}
|
Chris@14
|
668 options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
|
Chris@14
|
669 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
|
Chris@14
|
670 end
|
Chris@14
|
671
|
Chris@14
|
672 def back_url_hidden_field_tag
|
Chris@14
|
673 back_url = params[:back_url] || request.env['HTTP_REFERER']
|
Chris@14
|
674 back_url = CGI.unescape(back_url.to_s)
|
Chris@14
|
675 hidden_field_tag('back_url', CGI.escape(back_url)) unless back_url.blank?
|
Chris@14
|
676 end
|
Chris@14
|
677
|
Chris@14
|
678 def check_all_links(form_name)
|
Chris@14
|
679 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
|
Chris@14
|
680 " | " +
|
Chris@14
|
681 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
|
Chris@14
|
682 end
|
Chris@14
|
683
|
Chris@14
|
684 def progress_bar(pcts, options={})
|
Chris@14
|
685 pcts = [pcts, pcts] unless pcts.is_a?(Array)
|
Chris@14
|
686 pcts = pcts.collect(&:round)
|
Chris@14
|
687 pcts[1] = pcts[1] - pcts[0]
|
Chris@14
|
688 pcts << (100 - pcts[1] - pcts[0])
|
Chris@14
|
689 width = options[:width] || '100px;'
|
Chris@14
|
690 legend = options[:legend] || ''
|
Chris@14
|
691 content_tag('table',
|
Chris@14
|
692 content_tag('tr',
|
Chris@14
|
693 (pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : '') +
|
Chris@14
|
694 (pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : '') +
|
Chris@14
|
695 (pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : '')
|
Chris@14
|
696 ), :class => 'progress', :style => "width: #{width};") +
|
Chris@14
|
697 content_tag('p', legend, :class => 'pourcent')
|
Chris@14
|
698 end
|
Chris@14
|
699
|
Chris@14
|
700 def checked_image(checked=true)
|
Chris@14
|
701 if checked
|
Chris@14
|
702 image_tag 'toggle_check.png'
|
Chris@14
|
703 end
|
Chris@14
|
704 end
|
Chris@14
|
705
|
Chris@14
|
706 def context_menu(url)
|
Chris@14
|
707 unless @context_menu_included
|
Chris@14
|
708 content_for :header_tags do
|
Chris@14
|
709 javascript_include_tag('context_menu') +
|
Chris@14
|
710 stylesheet_link_tag('context_menu')
|
Chris@14
|
711 end
|
Chris@14
|
712 @context_menu_included = true
|
Chris@14
|
713 end
|
Chris@14
|
714 javascript_tag "new ContextMenu('#{ url_for(url) }')"
|
Chris@14
|
715 end
|
Chris@14
|
716
|
Chris@14
|
717 def context_menu_link(name, url, options={})
|
Chris@14
|
718 options[:class] ||= ''
|
Chris@14
|
719 if options.delete(:selected)
|
Chris@14
|
720 options[:class] << ' icon-checked disabled'
|
Chris@14
|
721 options[:disabled] = true
|
Chris@14
|
722 end
|
Chris@14
|
723 if options.delete(:disabled)
|
Chris@14
|
724 options.delete(:method)
|
Chris@14
|
725 options.delete(:confirm)
|
Chris@14
|
726 options.delete(:onclick)
|
Chris@14
|
727 options[:class] << ' disabled'
|
Chris@14
|
728 url = '#'
|
Chris@14
|
729 end
|
Chris@14
|
730 link_to name, url, options
|
Chris@14
|
731 end
|
Chris@14
|
732
|
Chris@14
|
733 def calendar_for(field_id)
|
Chris@14
|
734 include_calendar_headers_tags
|
Chris@14
|
735 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
|
Chris@14
|
736 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
|
Chris@14
|
737 end
|
Chris@14
|
738
|
Chris@14
|
739 def include_calendar_headers_tags
|
Chris@14
|
740 unless @calendar_headers_tags_included
|
Chris@14
|
741 @calendar_headers_tags_included = true
|
Chris@14
|
742 content_for :header_tags do
|
Chris@14
|
743 start_of_week = case Setting.start_of_week.to_i
|
Chris@14
|
744 when 1
|
Chris@14
|
745 'Calendar._FD = 1;' # Monday
|
Chris@14
|
746 when 7
|
Chris@14
|
747 'Calendar._FD = 0;' # Sunday
|
Chris@14
|
748 else
|
Chris@14
|
749 '' # use language
|
Chris@14
|
750 end
|
Chris@14
|
751
|
Chris@14
|
752 javascript_include_tag('calendar/calendar') +
|
Chris@14
|
753 javascript_include_tag("calendar/lang/calendar-#{current_language.to_s.downcase}.js") +
|
Chris@14
|
754 javascript_tag(start_of_week) +
|
Chris@14
|
755 javascript_include_tag('calendar/calendar-setup') +
|
Chris@14
|
756 stylesheet_link_tag('calendar')
|
Chris@14
|
757 end
|
Chris@14
|
758 end
|
Chris@14
|
759 end
|
Chris@14
|
760
|
Chris@14
|
761 def content_for(name, content = nil, &block)
|
Chris@14
|
762 @has_content ||= {}
|
Chris@14
|
763 @has_content[name] = true
|
Chris@14
|
764 super(name, content, &block)
|
Chris@14
|
765 end
|
Chris@14
|
766
|
Chris@14
|
767 def has_content?(name)
|
Chris@14
|
768 (@has_content && @has_content[name]) || false
|
Chris@14
|
769 end
|
Chris@14
|
770
|
Chris@14
|
771 # Returns the avatar image tag for the given +user+ if avatars are enabled
|
Chris@14
|
772 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
|
Chris@14
|
773 def avatar(user, options = { })
|
Chris@14
|
774 if Setting.gravatar_enabled?
|
Chris@14
|
775 options.merge!({:ssl => Setting.protocol == 'https', :default => Setting.gravatar_default})
|
Chris@14
|
776 email = nil
|
Chris@14
|
777 if user.respond_to?(:mail)
|
Chris@14
|
778 email = user.mail
|
Chris@14
|
779 elsif user.to_s =~ %r{<(.+?)>}
|
Chris@14
|
780 email = $1
|
Chris@14
|
781 end
|
Chris@14
|
782 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
|
Chris@14
|
783 end
|
Chris@14
|
784 end
|
Chris@14
|
785
|
Chris@14
|
786 private
|
Chris@14
|
787
|
Chris@14
|
788 def wiki_helper
|
Chris@14
|
789 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
Chris@14
|
790 extend helper
|
Chris@14
|
791 return self
|
Chris@14
|
792 end
|
Chris@14
|
793
|
Chris@14
|
794 def link_to_remote_content_update(text, url_params)
|
Chris@14
|
795 link_to_remote(text,
|
Chris@14
|
796 {:url => url_params, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'},
|
Chris@14
|
797 {:href => url_for(:params => url_params)}
|
Chris@14
|
798 )
|
Chris@14
|
799 end
|
Chris@14
|
800
|
Chris@14
|
801 end
|