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