##// END OF EJS Templates
Moved login and logout links to ApplicationHelper methods for easier customization....
Jean-Philippe Lang -
r1017:97f0da0b1a6f
parent child
Show More
@@ -1,386 +1,394
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 module ApplicationHelper
19 19 include Redmine::WikiFormatting::Macros::Definitions
20 20
21 21 def current_role
22 22 @current_role ||= User.current.role_for_project(@project)
23 23 end
24 24
25 25 # Return true if user is authorized for controller/action, otherwise false
26 26 def authorize_for(controller, action)
27 27 User.current.allowed_to?({:controller => controller, :action => action}, @project)
28 28 end
29 29
30 30 # Display a link if user is authorized
31 31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
32 32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
33 33 end
34 34
35 def link_to_signin
36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
37 end
38
39 def link_to_signout
40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
41 end
42
35 43 # Display a link to user's account page
36 44 def link_to_user(user)
37 45 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
38 46 end
39 47
40 48 def link_to_issue(issue)
41 49 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
42 50 end
43 51
44 52 def toggle_link(name, id, options={})
45 53 onclick = "Element.toggle('#{id}'); "
46 54 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
47 55 onclick << "return false;"
48 56 link_to(name, "#", :onclick => onclick)
49 57 end
50 58
51 59 def show_and_goto_link(name, id, options={})
52 60 onclick = "Element.show('#{id}'); "
53 61 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
54 62 onclick << "location.href='##{id}-anchor'; "
55 63 onclick << "return false;"
56 64 link_to(name, "#", options.merge(:onclick => onclick))
57 65 end
58 66
59 67 def image_to_function(name, function, html_options = {})
60 68 html_options.symbolize_keys!
61 69 tag(:input, html_options.merge({
62 70 :type => "image", :src => image_path(name),
63 71 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
64 72 }))
65 73 end
66 74
67 75 def prompt_to_remote(name, text, param, url, html_options = {})
68 76 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
69 77 link_to name, {}, html_options
70 78 end
71 79
72 80 def format_date(date)
73 81 return nil unless date
74 82 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
75 83 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
76 84 date.strftime(@date_format)
77 85 end
78 86
79 87 def format_time(time, include_date = true)
80 88 return nil unless time
81 89 time = time.to_time if time.is_a?(String)
82 90 zone = User.current.time_zone
83 91 if time.utc?
84 92 local = zone ? zone.adjust(time) : time.getlocal
85 93 else
86 94 local = zone ? zone.adjust(time.getutc) : time
87 95 end
88 96 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
89 97 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
90 98 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
91 99 end
92 100
93 101 def authoring(created, author)
94 102 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
95 103 l(:label_added_time_by, author || 'Anonymous', time_tag)
96 104 end
97 105
98 106 def day_name(day)
99 107 l(:general_day_names).split(',')[day-1]
100 108 end
101 109
102 110 def month_name(month)
103 111 l(:actionview_datehelper_select_month_names).split(',')[month-1]
104 112 end
105 113
106 114 def pagination_links_full(paginator, count=nil, options={})
107 115 page_param = options.delete(:page_param) || :page
108 116 url_param = params.dup
109 117
110 118 html = ''
111 119 html << link_to_remote(('&#171; ' + l(:label_previous)),
112 120 {:update => "content", :url => url_param.merge(page_param => paginator.current.previous)},
113 121 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
114 122
115 123 html << (pagination_links_each(paginator, options) do |n|
116 124 link_to_remote(n.to_s,
117 125 {:url => {:params => url_param.merge(page_param => n)}, :update => 'content'},
118 126 {:href => url_for(:params => url_param.merge(page_param => n))})
119 127 end || '')
120 128
121 129 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
122 130 {:update => "content", :url => url_param.merge(page_param => paginator.current.next)},
123 131 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
124 132
125 133 unless count.nil?
126 134 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
127 135 end
128 136
129 137 html
130 138 end
131 139
132 140 def per_page_links(selected=nil)
133 141 links = Setting.per_page_options_array.collect do |n|
134 142 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
135 143 {:href => url_for(params.dup.merge(:per_page => n))})
136 144 end
137 145 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
138 146 end
139 147
140 148 def set_html_title(text)
141 149 @html_header_title = text
142 150 end
143 151
144 152 def html_title
145 153 title = []
146 154 title << @project.name if @project
147 155 title << @html_header_title
148 156 title << Setting.app_title
149 157 title.compact.join(' - ')
150 158 end
151 159
152 160 ACCESSKEYS = {:edit => 'e',
153 161 :preview => 'r',
154 162 :quick_search => 'f',
155 163 :search => '4',
156 164 }.freeze unless const_defined?(:ACCESSKEYS)
157 165
158 166 def accesskey(s)
159 167 ACCESSKEYS[s]
160 168 end
161 169
162 170 # Formats text according to system settings.
163 171 # 2 ways to call this method:
164 172 # * with a String: textilizable(text, options)
165 173 # * with an object and one of its attribute: textilizable(issue, :description, options)
166 174 def textilizable(*args)
167 175 options = args.last.is_a?(Hash) ? args.pop : {}
168 176 case args.size
169 177 when 1
170 178 obj = nil
171 179 text = args.shift || ''
172 180 when 2
173 181 obj = args.shift
174 182 text = obj.send(args.shift)
175 183 else
176 184 raise ArgumentError, 'invalid arguments to textilizable'
177 185 end
178 186
179 187 # when using an image link, try to use an attachment, if possible
180 188 attachments = options[:attachments]
181 189 if attachments
182 190 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
183 191 style = $1
184 192 filename = $6
185 193 rf = Regexp.new(filename, Regexp::IGNORECASE)
186 194 # search for the picture in attachments
187 195 if found = attachments.detect { |att| att.filename =~ rf }
188 196 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
189 197 "!#{style}#{image_url}!"
190 198 else
191 199 "!#{style}#{filename}!"
192 200 end
193 201 end
194 202 end
195 203
196 204 text = (Setting.text_formatting == 'textile') ?
197 205 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
198 206 simple_format(auto_link(h(text)))
199 207
200 208 # different methods for formatting wiki links
201 209 case options[:wiki_links]
202 210 when :local
203 211 # used for local links to html files
204 212 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
205 213 when :anchor
206 214 # used for single-file wiki export
207 215 format_wiki_link = Proc.new {|project, title| "##{title}" }
208 216 else
209 217 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
210 218 end
211 219
212 220 project = options[:project] || @project
213 221
214 222 # turn wiki links into html links
215 223 # example:
216 224 # [[mypage]]
217 225 # [[mypage|mytext]]
218 226 # wiki links can refer other project wikis, using project name or identifier:
219 227 # [[project:]] -> wiki starting page
220 228 # [[project:|mytext]]
221 229 # [[project:mypage]]
222 230 # [[project:mypage|mytext]]
223 231 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) do |m|
224 232 link_project = project
225 233 page = $1
226 234 title = $3
227 235 if page =~ /^([^\:]+)\:(.*)$/
228 236 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
229 237 page = title || $2
230 238 title = $1 if page.blank?
231 239 end
232 240
233 241 if link_project && link_project.wiki
234 242 # check if page exists
235 243 wiki_page = link_project.wiki.find_page(page)
236 244 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
237 245 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
238 246 else
239 247 # project or wiki doesn't exist
240 248 title || page
241 249 end
242 250 end
243 251
244 252 # turn issue and revision ids into links
245 253 # example:
246 254 # #52 -> <a href="/issues/show/52">#52</a>
247 255 # r52 -> <a href="/repositories/revision/6?rev=52">r52</a> (project.id is 6)
248 256 text = text.gsub(%r{([\s\(,-^])(#|r)(\d+)(?=[[:punct:]]|\s|<|$)}) do |m|
249 257 leading, otype, oid = $1, $2, $3
250 258 link = nil
251 259 if otype == 'r'
252 260 if project && (changeset = project.changesets.find_by_revision(oid))
253 261 link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
254 262 :title => truncate(changeset.comments, 100))
255 263 end
256 264 else
257 265 if issue = Issue.find_by_id(oid.to_i, :include => [:project, :status], :conditions => Project.visible_by(User.current))
258 266 link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
259 267 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
260 268 link = content_tag('del', link) if issue.closed?
261 269 end
262 270 end
263 271 leading + (link || "#{otype}#{oid}")
264 272 end
265 273
266 274 text
267 275 end
268 276
269 277 # Same as Rails' simple_format helper without using paragraphs
270 278 def simple_format_without_paragraph(text)
271 279 text.to_s.
272 280 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
273 281 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
274 282 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
275 283 end
276 284
277 285 def error_messages_for(object_name, options = {})
278 286 options = options.symbolize_keys
279 287 object = instance_variable_get("@#{object_name}")
280 288 if object && !object.errors.empty?
281 289 # build full_messages here with controller current language
282 290 full_messages = []
283 291 object.errors.each do |attr, msg|
284 292 next if msg.nil?
285 293 msg = msg.first if msg.is_a? Array
286 294 if attr == "base"
287 295 full_messages << l(msg)
288 296 else
289 297 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
290 298 end
291 299 end
292 300 # retrieve custom values error messages
293 301 if object.errors[:custom_values]
294 302 object.custom_values.each do |v|
295 303 v.errors.each do |attr, msg|
296 304 next if msg.nil?
297 305 msg = msg.first if msg.is_a? Array
298 306 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
299 307 end
300 308 end
301 309 end
302 310 content_tag("div",
303 311 content_tag(
304 312 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
305 313 ) +
306 314 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
307 315 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
308 316 )
309 317 else
310 318 ""
311 319 end
312 320 end
313 321
314 322 def lang_options_for_select(blank=true)
315 323 (blank ? [["(auto)", ""]] : []) +
316 324 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
317 325 end
318 326
319 327 def label_tag_for(name, option_tags = nil, options = {})
320 328 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
321 329 content_tag("label", label_text)
322 330 end
323 331
324 332 def labelled_tabular_form_for(name, object, options, &proc)
325 333 options[:html] ||= {}
326 334 options[:html].store :class, "tabular"
327 335 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
328 336 end
329 337
330 338 def check_all_links(form_name)
331 339 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
332 340 " | " +
333 341 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
334 342 end
335 343
336 344 def progress_bar(pcts, options={})
337 345 pcts = [pcts, pcts] unless pcts.is_a?(Array)
338 346 pcts[1] = pcts[1] - pcts[0]
339 347 pcts << (100 - pcts[1] - pcts[0])
340 348 width = options[:width] || '100px;'
341 349 legend = options[:legend] || ''
342 350 content_tag('table',
343 351 content_tag('tr',
344 352 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
345 353 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
346 354 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
347 355 ), :class => 'progress', :style => "width: #{width};") +
348 356 content_tag('p', legend, :class => 'pourcent')
349 357 end
350 358
351 359 def context_menu_link(name, url, options={})
352 360 options[:class] ||= ''
353 361 if options.delete(:selected)
354 362 options[:class] << ' icon-checked disabled'
355 363 options[:disabled] = true
356 364 end
357 365 if options.delete(:disabled)
358 366 options.delete(:method)
359 367 options.delete(:confirm)
360 368 options.delete(:onclick)
361 369 options[:class] << ' disabled'
362 370 url = '#'
363 371 end
364 372 link_to name, url, options
365 373 end
366 374
367 375 def calendar_for(field_id)
368 376 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
369 377 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
370 378 end
371 379
372 380 def wikitoolbar_for(field_id)
373 381 return '' unless Setting.text_formatting == 'textile'
374 382 javascript_include_tag('jstoolbar') + javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
375 383 end
376 384
377 385 def content_for(name, content = nil, &block)
378 386 @has_content ||= {}
379 387 @has_content[name] = true
380 388 super(name, content, &block)
381 389 end
382 390
383 391 def has_content?(name)
384 392 (@has_content && @has_content[name]) || false
385 393 end
386 394 end
@@ -1,79 +1,79
1 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3 3 <head>
4 4 <title><%=h html_title %></title>
5 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6 6 <meta name="description" content="<%= Redmine::Info.app_name %>" />
7 7 <meta name="keywords" content="issue,bug,tracker" />
8 8 <%= stylesheet_link_tag 'application', :media => 'all' %>
9 9 <%= javascript_include_tag :defaults %>
10 10 <%= stylesheet_link_tag 'jstoolbar' %>
11 11 <!--[if IE]>
12 12 <style type="text/css">
13 13 * html body{ width: expression( document.documentElement.clientWidth < 900 ? '900px' : '100%' ); }
14 14 body {behavior: url(<%= stylesheet_path "csshover.htc" %>);}
15 15 </style>
16 16 <![endif]-->
17 17
18 18 <!-- page specific tags --><%= yield :header_tags %>
19 19 </head>
20 20 <body>
21 21 <div id="top-menu">
22 22 <div id="account">
23 23 <% if User.current.logged? %>
24 24 <%=l(:label_logged_as)%> <%= User.current.login %> -
25 25 <%= link_to l(:label_my_account), { :controller => 'my', :action => 'account' }, :class => 'myaccount' %>
26 <%= link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout' %>
26 <%= link_to_signout %>
27 27 <% else %>
28 <%= link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin' %>
28 <%= link_to_signin %>
29 29 <%= link_to(l(:label_register), { :controller => 'account',:action => 'register' }, :class => 'register') if Setting.self_registration? %>
30 30 <% end %>
31 31 </div>
32 32 <%= link_to l(:label_home), home_url, :class => 'home' %>
33 33 <%= link_to l(:label_my_page), { :controller => 'my', :action => 'page'}, :class => 'mypage' if User.current.logged? %>
34 34 <%= link_to l(:label_project_plural), { :controller => 'projects' }, :class => 'projects' %>
35 35 <%= link_to l(:label_administration), { :controller => 'admin' }, :class => 'admin' if User.current.admin? %>
36 36 <%= link_to l(:label_help), Redmine::Info.help_url, :class => 'help' %>
37 37 </div>
38 38
39 39 <div id="header">
40 40 <div id="quick-search">
41 41 <% form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
42 42 <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
43 43 <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
44 44 <% end %>
45 45 <%= render :partial => 'layouts/project_selector' if User.current.memberships.any? %>
46 46 </div>
47 47
48 48 <h1><%= h(@project ? @project.name : Setting.app_title) %></h1>
49 49
50 50 <div id="main-menu">
51 51 <ul>
52 52 <% Redmine::MenuManager.allowed_items(:project_menu, User.current, @project).each do |item| %>
53 53 <% unless item.condition && !item.condition.call(@project) %>
54 54 <li><%= link_to l(item.name), {item.param => @project}.merge(item.url) %></li>
55 55 <% end %>
56 56 <% end if @project && !@project.new_record? %>
57 57 </ul>
58 58 </div>
59 59 </div>
60 60
61 61 <%= tag('div', {:id => 'main', :class => (has_content?(:sidebar) ? '' : 'nosidebar')}, true) %>
62 62 <div id="sidebar">
63 63 <%= yield :sidebar %>
64 64 </div>
65 65
66 66 <div id="content">
67 67 <%= content_tag('div', flash[:error], :class => 'flash error') if flash[:error] %>
68 68 <%= content_tag('div', flash[:notice], :class => 'flash notice') if flash[:notice] %>
69 69 <%= yield %>
70 70 </div>
71 71 </div>
72 72
73 73 <div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
74 74
75 75 <div id="footer">
76 76 Powered by <%= link_to Redmine::Info.app_name, Redmine::Info.url %> <%= Redmine::VERSION %> &copy; 2006-2007 Jean-Philippe Lang
77 77 </div>
78 78 </body>
79 79 </html>
General Comments 0
You need to be logged in to leave comments. Login now