@@ -1,450 +1,450 | |||
|
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 | 35 | def link_to_signin |
|
36 | 36 | link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def link_to_signout |
|
40 | 40 | link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout' |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | # Display a link to user's account page |
|
44 | 44 | def link_to_user(user) |
|
45 | 45 | user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous' |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def link_to_issue(issue) |
|
49 | 49 | link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def toggle_link(name, id, options={}) |
|
53 | 53 | onclick = "Element.toggle('#{id}'); " |
|
54 | 54 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
55 | 55 | onclick << "return false;" |
|
56 | 56 | link_to(name, "#", :onclick => onclick) |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def show_and_goto_link(name, id, options={}) |
|
60 | 60 | onclick = "Element.show('#{id}'); " |
|
61 | 61 | onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
|
62 |
onclick << " |
|
|
62 | onclick << "Element.scrollTo('#{id}'); " | |
|
63 | 63 | onclick << "return false;" |
|
64 | 64 | link_to(name, "#", options.merge(:onclick => onclick)) |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def image_to_function(name, function, html_options = {}) |
|
68 | 68 | html_options.symbolize_keys! |
|
69 | 69 | tag(:input, html_options.merge({ |
|
70 | 70 | :type => "image", :src => image_path(name), |
|
71 | 71 | :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" |
|
72 | 72 | })) |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def prompt_to_remote(name, text, param, url, html_options = {}) |
|
76 | 76 | html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;" |
|
77 | 77 | link_to name, {}, html_options |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def format_date(date) |
|
81 | 81 | return nil unless date |
|
82 | 82 | # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed) |
|
83 | 83 | @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) |
|
84 | 84 | date.strftime(@date_format) |
|
85 | 85 | end |
|
86 | 86 | |
|
87 | 87 | def format_time(time, include_date = true) |
|
88 | 88 | return nil unless time |
|
89 | 89 | time = time.to_time if time.is_a?(String) |
|
90 | 90 | zone = User.current.time_zone |
|
91 | 91 | if time.utc? |
|
92 | 92 | local = zone ? zone.adjust(time) : time.getlocal |
|
93 | 93 | else |
|
94 | 94 | local = zone ? zone.adjust(time.getutc) : time |
|
95 | 95 | end |
|
96 | 96 | @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format) |
|
97 | 97 | @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format) |
|
98 | 98 | include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def authoring(created, author) |
|
102 | 102 | time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) |
|
103 | 103 | l(:label_added_time_by, author || 'Anonymous', time_tag) |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | def day_name(day) |
|
107 | 107 | l(:general_day_names).split(',')[day-1] |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def month_name(month) |
|
111 | 111 | l(:actionview_datehelper_select_month_names).split(',')[month-1] |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def pagination_links_full(paginator, count=nil, options={}) |
|
115 | 115 | page_param = options.delete(:page_param) || :page |
|
116 | 116 | url_param = params.dup |
|
117 | 117 | # don't reuse params if filters are present |
|
118 | 118 | url_param.clear if url_param.has_key?(:set_filter) |
|
119 | 119 | |
|
120 | 120 | html = '' |
|
121 | 121 | html << link_to_remote(('« ' + l(:label_previous)), |
|
122 | 122 | {:update => 'content', |
|
123 | 123 | :url => url_param.merge(page_param => paginator.current.previous), |
|
124 | 124 | :complete => 'window.scrollTo(0,0)'}, |
|
125 | 125 | {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous |
|
126 | 126 | |
|
127 | 127 | html << (pagination_links_each(paginator, options) do |n| |
|
128 | 128 | link_to_remote(n.to_s, |
|
129 | 129 | {:url => {:params => url_param.merge(page_param => n)}, |
|
130 | 130 | :update => 'content', |
|
131 | 131 | :complete => 'window.scrollTo(0,0)'}, |
|
132 | 132 | {:href => url_for(:params => url_param.merge(page_param => n))}) |
|
133 | 133 | end || '') |
|
134 | 134 | |
|
135 | 135 | html << ' ' + link_to_remote((l(:label_next) + ' »'), |
|
136 | 136 | {:update => 'content', |
|
137 | 137 | :url => url_param.merge(page_param => paginator.current.next), |
|
138 | 138 | :complete => 'window.scrollTo(0,0)'}, |
|
139 | 139 | {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next |
|
140 | 140 | |
|
141 | 141 | unless count.nil? |
|
142 | 142 | html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ') |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | html |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | def per_page_links(selected=nil) |
|
149 | 149 | url_param = params.dup |
|
150 | 150 | url_param.clear if url_param.has_key?(:set_filter) |
|
151 | 151 | |
|
152 | 152 | links = Setting.per_page_options_array.collect do |n| |
|
153 | 153 | n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)}, |
|
154 | 154 | {:href => url_for(url_param.merge(:per_page => n))}) |
|
155 | 155 | end |
|
156 | 156 | links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def html_title(*args) |
|
160 | 160 | if args.empty? |
|
161 | 161 | title = [] |
|
162 | 162 | title << @project.name if @project |
|
163 | 163 | title += @html_title if @html_title |
|
164 | 164 | title << Setting.app_title |
|
165 | 165 | title.compact.join(' - ') |
|
166 | 166 | else |
|
167 | 167 | @html_title ||= [] |
|
168 | 168 | @html_title += args |
|
169 | 169 | end |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def accesskey(s) |
|
173 | 173 | Redmine::AccessKeys.key_for s |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | # Formats text according to system settings. |
|
177 | 177 | # 2 ways to call this method: |
|
178 | 178 | # * with a String: textilizable(text, options) |
|
179 | 179 | # * with an object and one of its attribute: textilizable(issue, :description, options) |
|
180 | 180 | def textilizable(*args) |
|
181 | 181 | options = args.last.is_a?(Hash) ? args.pop : {} |
|
182 | 182 | case args.size |
|
183 | 183 | when 1 |
|
184 | 184 | obj = nil |
|
185 | 185 | text = args.shift || '' |
|
186 | 186 | when 2 |
|
187 | 187 | obj = args.shift |
|
188 | 188 | text = obj.send(args.shift) |
|
189 | 189 | else |
|
190 | 190 | raise ArgumentError, 'invalid arguments to textilizable' |
|
191 | 191 | end |
|
192 | 192 | |
|
193 | 193 | # when using an image link, try to use an attachment, if possible |
|
194 | 194 | attachments = options[:attachments] |
|
195 | 195 | if attachments |
|
196 | 196 | text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m| |
|
197 | 197 | style = $1 |
|
198 | 198 | filename = $6 |
|
199 | 199 | rf = Regexp.new(filename, Regexp::IGNORECASE) |
|
200 | 200 | # search for the picture in attachments |
|
201 | 201 | if found = attachments.detect { |att| att.filename =~ rf } |
|
202 | 202 | image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id |
|
203 | 203 | "!#{style}#{image_url}!" |
|
204 | 204 | else |
|
205 | 205 | "!#{style}#{filename}!" |
|
206 | 206 | end |
|
207 | 207 | end |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | text = (Setting.text_formatting == 'textile') ? |
|
211 | 211 | Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } : |
|
212 | 212 | simple_format(auto_link(h(text))) |
|
213 | 213 | |
|
214 | 214 | # different methods for formatting wiki links |
|
215 | 215 | case options[:wiki_links] |
|
216 | 216 | when :local |
|
217 | 217 | # used for local links to html files |
|
218 | 218 | format_wiki_link = Proc.new {|project, title| "#{title}.html" } |
|
219 | 219 | when :anchor |
|
220 | 220 | # used for single-file wiki export |
|
221 | 221 | format_wiki_link = Proc.new {|project, title| "##{title}" } |
|
222 | 222 | else |
|
223 | 223 | format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title } |
|
224 | 224 | end |
|
225 | 225 | |
|
226 | 226 | project = options[:project] || @project |
|
227 | 227 | |
|
228 | 228 | # Wiki links |
|
229 | 229 | # |
|
230 | 230 | # Examples: |
|
231 | 231 | # [[mypage]] |
|
232 | 232 | # [[mypage|mytext]] |
|
233 | 233 | # wiki links can refer other project wikis, using project name or identifier: |
|
234 | 234 | # [[project:]] -> wiki starting page |
|
235 | 235 | # [[project:|mytext]] |
|
236 | 236 | # [[project:mypage]] |
|
237 | 237 | # [[project:mypage|mytext]] |
|
238 | 238 | text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m| |
|
239 | 239 | link_project = project |
|
240 | 240 | esc, all, page, title = $1, $2, $3, $5 |
|
241 | 241 | if esc.nil? |
|
242 | 242 | if page =~ /^([^\:]+)\:(.*)$/ |
|
243 | 243 | link_project = Project.find_by_name($1) || Project.find_by_identifier($1) |
|
244 | 244 | page = $2 |
|
245 | 245 | title ||= $1 if page.blank? |
|
246 | 246 | end |
|
247 | 247 | |
|
248 | 248 | if link_project && link_project.wiki |
|
249 | 249 | # check if page exists |
|
250 | 250 | wiki_page = link_project.wiki.find_page(page) |
|
251 | 251 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), |
|
252 | 252 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
253 | 253 | else |
|
254 | 254 | # project or wiki doesn't exist |
|
255 | 255 | title || page |
|
256 | 256 | end |
|
257 | 257 | else |
|
258 | 258 | all |
|
259 | 259 | end |
|
260 | 260 | end |
|
261 | 261 | |
|
262 | 262 | # Redmine links |
|
263 | 263 | # |
|
264 | 264 | # Examples: |
|
265 | 265 | # Issues: |
|
266 | 266 | # #52 -> Link to issue #52 |
|
267 | 267 | # Changesets: |
|
268 | 268 | # r52 -> Link to revision 52 |
|
269 | 269 | # Documents: |
|
270 | 270 | # document#17 -> Link to document with id 17 |
|
271 | 271 | # document:Greetings -> Link to the document with title "Greetings" |
|
272 | 272 | # document:"Some document" -> Link to the document with title "Some document" |
|
273 | 273 | # Versions: |
|
274 | 274 | # version#3 -> Link to version with id 3 |
|
275 | 275 | # version:1.0.0 -> Link to version named "1.0.0" |
|
276 | 276 | # version:"1.0 beta 2" -> Link to version named "1.0 beta 2" |
|
277 | 277 | # Attachments: |
|
278 | 278 | # attachment:file.zip -> Link to the attachment of the current object named file.zip |
|
279 | 279 | text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m| |
|
280 | 280 | leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 |
|
281 | 281 | link = nil |
|
282 | 282 | if esc.nil? |
|
283 | 283 | if prefix.nil? && sep == 'r' |
|
284 | 284 | if project && (changeset = project.changesets.find_by_revision(oid)) |
|
285 | 285 | link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset', |
|
286 | 286 | :title => truncate(changeset.comments, 100)) |
|
287 | 287 | end |
|
288 | 288 | elsif sep == '#' |
|
289 | 289 | oid = oid.to_i |
|
290 | 290 | case prefix |
|
291 | 291 | when nil |
|
292 | 292 | if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current)) |
|
293 | 293 | link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue', |
|
294 | 294 | :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})") |
|
295 | 295 | link = content_tag('del', link) if issue.closed? |
|
296 | 296 | end |
|
297 | 297 | when 'document' |
|
298 | 298 | if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) |
|
299 | 299 | link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document' |
|
300 | 300 | end |
|
301 | 301 | when 'version' |
|
302 | 302 | if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) |
|
303 | 303 | link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version' |
|
304 | 304 | end |
|
305 | 305 | end |
|
306 | 306 | elsif sep == ':' |
|
307 | 307 | # removes the double quotes if any |
|
308 | 308 | name = oid.gsub(%r{^"(.*)"$}, "\\1") |
|
309 | 309 | case prefix |
|
310 | 310 | when 'document' |
|
311 | 311 | if project && document = project.documents.find_by_title(name) |
|
312 | 312 | link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document' |
|
313 | 313 | end |
|
314 | 314 | when 'version' |
|
315 | 315 | if project && version = project.versions.find_by_name(name) |
|
316 | 316 | link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version' |
|
317 | 317 | end |
|
318 | 318 | when 'attachment' |
|
319 | 319 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
|
320 | 320 | link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment' |
|
321 | 321 | end |
|
322 | 322 | end |
|
323 | 323 | end |
|
324 | 324 | end |
|
325 | 325 | leading + (link || "#{prefix}#{sep}#{oid}") |
|
326 | 326 | end |
|
327 | 327 | |
|
328 | 328 | text |
|
329 | 329 | end |
|
330 | 330 | |
|
331 | 331 | # Same as Rails' simple_format helper without using paragraphs |
|
332 | 332 | def simple_format_without_paragraph(text) |
|
333 | 333 | text.to_s. |
|
334 | 334 | gsub(/\r\n?/, "\n"). # \r\n and \r -> \n |
|
335 | 335 | gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br |
|
336 | 336 | gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br |
|
337 | 337 | end |
|
338 | 338 | |
|
339 | 339 | def error_messages_for(object_name, options = {}) |
|
340 | 340 | options = options.symbolize_keys |
|
341 | 341 | object = instance_variable_get("@#{object_name}") |
|
342 | 342 | if object && !object.errors.empty? |
|
343 | 343 | # build full_messages here with controller current language |
|
344 | 344 | full_messages = [] |
|
345 | 345 | object.errors.each do |attr, msg| |
|
346 | 346 | next if msg.nil? |
|
347 | 347 | msg = msg.first if msg.is_a? Array |
|
348 | 348 | if attr == "base" |
|
349 | 349 | full_messages << l(msg) |
|
350 | 350 | else |
|
351 | 351 | full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" |
|
352 | 352 | end |
|
353 | 353 | end |
|
354 | 354 | # retrieve custom values error messages |
|
355 | 355 | if object.errors[:custom_values] |
|
356 | 356 | object.custom_values.each do |v| |
|
357 | 357 | v.errors.each do |attr, msg| |
|
358 | 358 | next if msg.nil? |
|
359 | 359 | msg = msg.first if msg.is_a? Array |
|
360 | 360 | full_messages << "« " + v.custom_field.name + " » " + l(msg) |
|
361 | 361 | end |
|
362 | 362 | end |
|
363 | 363 | end |
|
364 | 364 | content_tag("div", |
|
365 | 365 | content_tag( |
|
366 | 366 | options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":" |
|
367 | 367 | ) + |
|
368 | 368 | content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }), |
|
369 | 369 | "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation" |
|
370 | 370 | ) |
|
371 | 371 | else |
|
372 | 372 | "" |
|
373 | 373 | end |
|
374 | 374 | end |
|
375 | 375 | |
|
376 | 376 | def lang_options_for_select(blank=true) |
|
377 | 377 | (blank ? [["(auto)", ""]] : []) + |
|
378 | 378 | GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last } |
|
379 | 379 | end |
|
380 | 380 | |
|
381 | 381 | def label_tag_for(name, option_tags = nil, options = {}) |
|
382 | 382 | label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "") |
|
383 | 383 | content_tag("label", label_text) |
|
384 | 384 | end |
|
385 | 385 | |
|
386 | 386 | def labelled_tabular_form_for(name, object, options, &proc) |
|
387 | 387 | options[:html] ||= {} |
|
388 | 388 | options[:html].store :class, "tabular" |
|
389 | 389 | form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc) |
|
390 | 390 | end |
|
391 | 391 | |
|
392 | 392 | def check_all_links(form_name) |
|
393 | 393 | link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") + |
|
394 | 394 | " | " + |
|
395 | 395 | link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)") |
|
396 | 396 | end |
|
397 | 397 | |
|
398 | 398 | def progress_bar(pcts, options={}) |
|
399 | 399 | pcts = [pcts, pcts] unless pcts.is_a?(Array) |
|
400 | 400 | pcts[1] = pcts[1] - pcts[0] |
|
401 | 401 | pcts << (100 - pcts[1] - pcts[0]) |
|
402 | 402 | width = options[:width] || '100px;' |
|
403 | 403 | legend = options[:legend] || '' |
|
404 | 404 | content_tag('table', |
|
405 | 405 | content_tag('tr', |
|
406 | 406 | (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') + |
|
407 | 407 | (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') + |
|
408 | 408 | (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '') |
|
409 | 409 | ), :class => 'progress', :style => "width: #{width};") + |
|
410 | 410 | content_tag('p', legend, :class => 'pourcent') |
|
411 | 411 | end |
|
412 | 412 | |
|
413 | 413 | def context_menu_link(name, url, options={}) |
|
414 | 414 | options[:class] ||= '' |
|
415 | 415 | if options.delete(:selected) |
|
416 | 416 | options[:class] << ' icon-checked disabled' |
|
417 | 417 | options[:disabled] = true |
|
418 | 418 | end |
|
419 | 419 | if options.delete(:disabled) |
|
420 | 420 | options.delete(:method) |
|
421 | 421 | options.delete(:confirm) |
|
422 | 422 | options.delete(:onclick) |
|
423 | 423 | options[:class] << ' disabled' |
|
424 | 424 | url = '#' |
|
425 | 425 | end |
|
426 | 426 | link_to name, url, options |
|
427 | 427 | end |
|
428 | 428 | |
|
429 | 429 | def calendar_for(field_id) |
|
430 | 430 | image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + |
|
431 | 431 | javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") |
|
432 | 432 | end |
|
433 | 433 | |
|
434 | 434 | def wikitoolbar_for(field_id) |
|
435 | 435 | return '' unless Setting.text_formatting == 'textile' |
|
436 | 436 | javascript_include_tag('jstoolbar/jstoolbar') + |
|
437 | 437 | javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") + |
|
438 | 438 | javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();") |
|
439 | 439 | end |
|
440 | 440 | |
|
441 | 441 | def content_for(name, content = nil, &block) |
|
442 | 442 | @has_content ||= {} |
|
443 | 443 | @has_content[name] = true |
|
444 | 444 | super(name, content, &block) |
|
445 | 445 | end |
|
446 | 446 | |
|
447 | 447 | def has_content?(name) |
|
448 | 448 | (@has_content && @has_content[name]) || false |
|
449 | 449 | end |
|
450 | 450 | end |
@@ -1,39 +1,39 | |||
|
1 | 1 | <% labelled_tabular_form_for :issue, @issue, |
|
2 | 2 | :url => {:action => 'edit', :id => @issue}, |
|
3 | 3 | :html => {:id => 'issue-form', |
|
4 | 4 | :multipart => true} do |f| %> |
|
5 | 5 | <%= error_messages_for 'issue' %> |
|
6 | 6 | <div class="box"> |
|
7 | 7 | <% if @edit_allowed || !@allowed_statuses.empty? %> |
|
8 | 8 | <fieldset> |
|
9 | 9 | <legend><%= l(:label_change_properties) %> |
|
10 | 10 | <% if !@issue.new_record? && !@issue.errors.any? && @edit_allowed %> |
|
11 | 11 | <small>(<%= link_to l(:label_more), {}, :onclick => 'Effect.toggle("issue_descr_fields", "appear", {duration:0.3}); return false;' %>)</small> |
|
12 | 12 | <% end %> |
|
13 | 13 | </legend> |
|
14 | 14 | <%= render :partial => (@edit_allowed ? 'form' : 'form_update'), :locals => {:f => f} %> |
|
15 | 15 | </fieldset> |
|
16 | 16 | <% end %> |
|
17 | 17 | |
|
18 | 18 | <fieldset><legend><%= l(:field_notes) %></legend> |
|
19 | 19 | <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> |
|
20 | 20 | <%= wikitoolbar_for 'notes' %> |
|
21 | 21 | |
|
22 | 22 | <p id="attachments_p"><label><%=l(:label_attachment_new)%> |
|
23 | 23 | <%= image_to_function 'add.png', 'addFileField();return false;' %></label> |
|
24 | 24 | <%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p> |
|
25 | 25 | </fieldset> |
|
26 | 26 | </div> |
|
27 | 27 | |
|
28 | 28 | <%= f.hidden_field :lock_version %> |
|
29 | 29 | <%= submit_tag l(:button_submit) %> |
|
30 | 30 | <%= link_to_remote l(:label_preview), |
|
31 | 31 | { :url => { :controller => 'issues', :action => 'preview', :id => @issue }, |
|
32 | 32 | :method => 'post', |
|
33 | 33 | :update => 'preview', |
|
34 | 34 | :with => 'Form.serialize("issue-form")', |
|
35 |
:complete => " |
|
|
35 | :complete => "Element.scrollTo('preview')" | |
|
36 | 36 | }, :accesskey => accesskey(:preview) %> |
|
37 | 37 | <% end %> |
|
38 | 38 | |
|
39 | 39 | <div id="preview" class="wiki"></div> |
@@ -1,20 +1,19 | |||
|
1 | 1 | <h2><%=l(:label_issue_new)%></h2> |
|
2 | 2 | |
|
3 | 3 | <% labelled_tabular_form_for :issue, @issue, |
|
4 | 4 | :html => {:multipart => true, :id => 'issue-form'} do |f| %> |
|
5 | 5 | <%= error_messages_for 'issue' %> |
|
6 | 6 | <div class="box"> |
|
7 | 7 | <%= render :partial => 'issues/form', :locals => {:f => f} %> |
|
8 | 8 | </div> |
|
9 | 9 | <%= submit_tag l(:button_create) %> |
|
10 | 10 | <%= link_to_remote l(:label_preview), |
|
11 | 11 | { :url => { :controller => 'issues', :action => 'preview', :id => @issue }, |
|
12 | 12 | :method => 'post', |
|
13 | 13 | :update => 'preview', |
|
14 | 14 | :with => "Form.serialize('issue-form')", |
|
15 |
:complete => " |
|
|
15 | :complete => "Element.scrollTo('preview')" | |
|
16 | 16 | }, :accesskey => accesskey(:preview) %> |
|
17 | 17 | <% end %> |
|
18 | 18 | |
|
19 | <a name="preview-top"></a> | |
|
20 | 19 | <div id="preview" class="wiki"></div> |
@@ -1,108 +1,107 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= show_and_goto_link(l(:button_update), 'update', :class => 'icon icon-edit', :accesskey => accesskey(:edit)) if authorize_for('issues', 'edit') %> |
|
3 | 3 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time' %> |
|
4 | 4 | <%= watcher_tag(@issue, User.current) %> |
|
5 | 5 | <%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %> |
|
6 | 6 | <%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %> |
|
7 | 7 | <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> |
|
8 | 8 | </div> |
|
9 | 9 | |
|
10 | 10 | <h2><%= @issue.tracker.name %> #<%= @issue.id %></h2> |
|
11 | 11 | |
|
12 | 12 | <div class="issue <%= "status-#{@issue.status.position} priority-#{@issue.priority.position}" %>"> |
|
13 | 13 | <h3><%=h @issue.subject %></h3> |
|
14 | 14 | <p class="author"> |
|
15 | 15 | <%= authoring @issue.created_on, @issue.author %>. |
|
16 | 16 | <%= l(:label_updated_time, distance_of_time_in_words(Time.now, @issue.updated_on)) if @issue.created_on != @issue.updated_on %>. |
|
17 | 17 | </p> |
|
18 | 18 | |
|
19 | 19 | <table width="100%"> |
|
20 | 20 | <tr> |
|
21 | 21 | <td style="width:15%"><b><%=l(:field_status)%> :</b></td><td style="width:35%"><%= @issue.status.name %></td> |
|
22 | 22 | <td style="width:15%"><b><%=l(:field_start_date)%> :</b></td><td style="width:35%"><%= format_date(@issue.start_date) %></td> |
|
23 | 23 | </tr> |
|
24 | 24 | <tr> |
|
25 | 25 | <td><b><%=l(:field_priority)%> :</b></td><td><%= @issue.priority.name %></td> |
|
26 | 26 | <td><b><%=l(:field_due_date)%> :</b></td><td><%= format_date(@issue.due_date) %></td> |
|
27 | 27 | </tr> |
|
28 | 28 | <tr> |
|
29 | 29 | <td><b><%=l(:field_assigned_to)%> :</b></td><td><%= @issue.assigned_to ? link_to_user(@issue.assigned_to) : "-" %></td> |
|
30 | 30 | <td><b><%=l(:field_done_ratio)%> :</b></td><td><%= progress_bar @issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%" %></td> |
|
31 | 31 | </tr> |
|
32 | 32 | <tr> |
|
33 | 33 | <td><b><%=l(:field_category)%> :</b></td><td><%=h @issue.category ? @issue.category.name : "-" %></td> |
|
34 | 34 | <% if User.current.allowed_to?(:view_time_entries, @project) %> |
|
35 | 35 | <td><b><%=l(:label_spent_time)%> :</b></td> |
|
36 | 36 | <td><%= @issue.spent_hours > 0 ? (link_to lwr(:label_f_hour, @issue.spent_hours), {:controller => 'timelog', :action => 'details', :issue_id => @issue}, :class => 'icon icon-time') : "-" %></td> |
|
37 | 37 | <% end %> |
|
38 | 38 | </tr> |
|
39 | 39 | <tr> |
|
40 | 40 | <td><b><%=l(:field_fixed_version)%> :</b></td><td><%= @issue.fixed_version ? link_to_version(@issue.fixed_version) : "-" %></td> |
|
41 | 41 | <% if @issue.estimated_hours %> |
|
42 | 42 | <td><b><%=l(:field_estimated_hours)%> :</b></td><td><%= lwr(:label_f_hour, @issue.estimated_hours) %></td> |
|
43 | 43 | <% end %> |
|
44 | 44 | </tr> |
|
45 | 45 | <tr> |
|
46 | 46 | <% n = 0 |
|
47 | 47 | for custom_value in @custom_values %> |
|
48 | 48 | <td valign="top"><b><%= custom_value.custom_field.name %> :</b></td><td valign="top"><%= simple_format(h(show_value(custom_value))) %></td> |
|
49 | 49 | <% n = n + 1 |
|
50 | 50 | if (n > 1) |
|
51 | 51 | n = 0 %> |
|
52 | 52 | </tr><tr> |
|
53 | 53 | <%end |
|
54 | 54 | end %> |
|
55 | 55 | </tr> |
|
56 | 56 | </table> |
|
57 | 57 | <hr /> |
|
58 | 58 | |
|
59 | 59 | <p><strong><%=l(:field_description)%></strong></p> |
|
60 | 60 | <div class="wiki"> |
|
61 | 61 | <%= textilizable @issue, :description, :attachments => @issue.attachments %> |
|
62 | 62 | </div> |
|
63 | 63 | |
|
64 | 64 | <% if @issue.attachments.any? %> |
|
65 | 65 | <%= link_to_attachments @issue.attachments, :delete_url => (authorize_for('issues', 'destroy_attachment') ? {:controller => 'issues', :action => 'destroy_attachment', :id => @issue} : nil) %> |
|
66 | 66 | <% end %> |
|
67 | 67 | |
|
68 | 68 | <% if authorize_for('issue_relations', 'new') || @issue.relations.any? %> |
|
69 | 69 | <hr /> |
|
70 | 70 | <div id="relations"> |
|
71 | 71 | <%= render :partial => 'relations' %> |
|
72 | 72 | </div> |
|
73 | 73 | <% end %> |
|
74 | 74 | |
|
75 | 75 | </div> |
|
76 | 76 | |
|
77 | 77 | <% if @issue.changesets.any? && User.current.allowed_to?(:view_changesets, @project) %> |
|
78 | 78 | <div id="issue-changesets"> |
|
79 | 79 | <h3><%=l(:label_associated_revisions)%></h3> |
|
80 | 80 | <%= render :partial => 'changesets', :locals => { :changesets => @issue.changesets} %> |
|
81 | 81 | </div> |
|
82 | 82 | <% end %> |
|
83 | 83 | |
|
84 | 84 | <% if @journals.any? %> |
|
85 | 85 | <div id="history"> |
|
86 | 86 | <h3><%=l(:label_history)%></h3> |
|
87 | 87 | <%= render :partial => 'history', :locals => { :journals => @journals } %> |
|
88 | 88 | </div> |
|
89 | 89 | <% end %> |
|
90 | 90 | |
|
91 | 91 | <% if authorize_for('issues', 'edit') %> |
|
92 | <a name="update-anchor"></a> | |
|
93 | 92 | <div id="update" style="display:none;"> |
|
94 | 93 | <h3><%= l(:button_update) %></h3> |
|
95 | 94 | <%= render :partial => 'edit' %> |
|
96 | 95 | </div> |
|
97 | 96 | <% end %> |
|
98 | 97 | |
|
99 | 98 | <div class="contextual"> |
|
100 | 99 | <%= l(:label_export_to) %><%= link_to 'PDF', {:format => 'pdf'}, :class => 'icon icon-pdf' %> |
|
101 | 100 | </div> |
|
102 | 101 | |
|
103 | 102 | |
|
104 | 103 | <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> |
|
105 | 104 | |
|
106 | 105 | <% content_for :sidebar do %> |
|
107 | 106 | <%= render :partial => 'issues/sidebar' %> |
|
108 | 107 | <% end %> |
@@ -1,31 +1,30 | |||
|
1 | 1 | <h2><%= @page.pretty_title %></h2> |
|
2 | 2 | |
|
3 | 3 | <% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %> |
|
4 | 4 | <%= f.hidden_field :version %> |
|
5 | 5 | <%= error_messages_for 'content' %> |
|
6 | 6 | <div class="contextual"> |
|
7 | 7 | <%= l(:setting_text_formatting) %>: |
|
8 | 8 | <%= link_to l(:label_help), compute_public_path('wiki_syntax', 'help', 'html'), |
|
9 | 9 | :onclick => "window.open('#{ compute_public_path('wiki_syntax', 'help', 'html') }', '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes'); return false;" %> |
|
10 | 10 | </div> |
|
11 | 11 | <p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p> |
|
12 | 12 | <p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p> |
|
13 | 13 | <p><%= submit_tag l(:button_save) %> |
|
14 | 14 | <%= link_to_remote l(:label_preview), |
|
15 | 15 | { :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title }, |
|
16 | 16 | :method => 'post', |
|
17 | 17 | :update => 'preview', |
|
18 | 18 | :with => "Form.serialize('wiki_form')", |
|
19 |
:complete => " |
|
|
19 | :complete => "Element.scrollTo('preview')" | |
|
20 | 20 | }, :accesskey => accesskey(:preview) %></p> |
|
21 | 21 | <%= wikitoolbar_for 'content_text' %> |
|
22 | 22 | <% end %> |
|
23 | 23 | |
|
24 | <a name="preview-top"></a> | |
|
25 | 24 | <div id="preview" class="wiki"></div> |
|
26 | 25 | |
|
27 | 26 | <% content_for :header_tags do %> |
|
28 | 27 | <%= stylesheet_link_tag 'scm' %> |
|
29 | 28 | <% end %> |
|
30 | 29 | |
|
31 | 30 | <% html_title @page.pretty_title %> |
General Comments 0
You need to be logged in to leave comments.
Login now