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