##// END OF EJS Templates
textile for revisions comments...
Jean-Philippe Lang -
r122:0820e745d65b
parent child
Show More
@@ -1,184 +1,184
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 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
19
20 # Return current logged in user or nil
20 # Return current logged in user or nil
21 def loggedin?
21 def loggedin?
22 @logged_in_user
22 @logged_in_user
23 end
23 end
24
24
25 # Return true if user is logged in and is admin, otherwise false
25 # Return true if user is logged in and is admin, otherwise false
26 def admin_loggedin?
26 def admin_loggedin?
27 @logged_in_user and @logged_in_user.admin?
27 @logged_in_user and @logged_in_user.admin?
28 end
28 end
29
29
30 # Return true if user is authorized for controller/action, otherwise false
30 # Return true if user is authorized for controller/action, otherwise false
31 def authorize_for(controller, action)
31 def authorize_for(controller, action)
32 # check if action is allowed on public projects
32 # check if action is allowed on public projects
33 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
33 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
34 return true
34 return true
35 end
35 end
36 # check if user is authorized
36 # check if user is authorized
37 if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project.id) ) )
37 if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project.id) ) )
38 return true
38 return true
39 end
39 end
40 return false
40 return false
41 end
41 end
42
42
43 # Display a link if user is authorized
43 # Display a link if user is authorized
44 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
44 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
45 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action])
45 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action])
46 end
46 end
47
47
48 # Display a link to user's account page
48 # Display a link to user's account page
49 def link_to_user(user)
49 def link_to_user(user)
50 link_to user.display_name, :controller => 'account', :action => 'show', :id => user
50 link_to user.display_name, :controller => 'account', :action => 'show', :id => user
51 end
51 end
52
52
53 def format_date(date)
53 def format_date(date)
54 l_date(date) if date
54 l_date(date) if date
55 end
55 end
56
56
57 def format_time(time)
57 def format_time(time)
58 l_datetime(time) if time
58 l_datetime(time) if time
59 end
59 end
60
60
61 def day_name(day)
61 def day_name(day)
62 l(:general_day_names).split(',')[day-1]
62 l(:general_day_names).split(',')[day-1]
63 end
63 end
64
64
65 def month_name(month)
65 def month_name(month)
66 l(:actionview_datehelper_select_month_names).split(',')[month-1]
66 l(:actionview_datehelper_select_month_names).split(',')[month-1]
67 end
67 end
68
68
69 def pagination_links_full(paginator, options={}, html_options={})
69 def pagination_links_full(paginator, options={}, html_options={})
70 html = ''
70 html = ''
71 html << link_to_remote(('&#171; ' + l(:label_previous)),
71 html << link_to_remote(('&#171; ' + l(:label_previous)),
72 {:update => "content", :url => { :page => paginator.current.previous }},
72 {:update => "content", :url => { :page => paginator.current.previous }},
73 {:href => url_for(:action => 'list', :params => @params.merge({:page => paginator.current.previous}))}) + ' ' if paginator.current.previous
73 {:href => url_for(:action => 'list', :params => @params.merge({:page => paginator.current.previous}))}) + ' ' if paginator.current.previous
74
74
75 html << (pagination_links_each(paginator, options) do |n|
75 html << (pagination_links_each(paginator, options) do |n|
76 link_to_remote(n.to_s,
76 link_to_remote(n.to_s,
77 {:url => {:action => 'list', :params => @params.merge({:page => n})}, :update => 'content'},
77 {:url => {:action => 'list', :params => @params.merge({:page => n})}, :update => 'content'},
78 {:href => url_for(:action => 'list', :params => @params.merge({:page => n}))})
78 {:href => url_for(:action => 'list', :params => @params.merge({:page => n}))})
79 end || '')
79 end || '')
80
80
81 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
81 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
82 {:update => "content", :url => { :page => paginator.current.next }},
82 {:update => "content", :url => { :page => paginator.current.next }},
83 {:href => url_for(:action => 'list', :params => @params.merge({:page => paginator.current.next}))}) if paginator.current.next
83 {:href => url_for(:action => 'list', :params => @params.merge({:page => paginator.current.next}))}) if paginator.current.next
84 html
84 html
85 end
85 end
86
86
87 def textilizable(text)
87 def textilizable(text)
88 $RDM_TEXTILE_DISABLED ? text : RedCloth.new(text).to_html
88 $RDM_TEXTILE_DISABLED ? simple_format(auto_link(h(text))) : RedCloth.new(h(text)).to_html
89 end
89 end
90
90
91 def error_messages_for(object_name, options = {})
91 def error_messages_for(object_name, options = {})
92 options = options.symbolize_keys
92 options = options.symbolize_keys
93 object = instance_variable_get("@#{object_name}")
93 object = instance_variable_get("@#{object_name}")
94 if object && !object.errors.empty?
94 if object && !object.errors.empty?
95 # build full_messages here with controller current language
95 # build full_messages here with controller current language
96 full_messages = []
96 full_messages = []
97 object.errors.each do |attr, msg|
97 object.errors.each do |attr, msg|
98 next if msg.nil?
98 next if msg.nil?
99 if attr == "base"
99 if attr == "base"
100 full_messages << l(msg)
100 full_messages << l(msg)
101 else
101 else
102 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
102 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
103 end
103 end
104 end
104 end
105 # retrieve custom values error messages
105 # retrieve custom values error messages
106 if object.errors[:custom_values]
106 if object.errors[:custom_values]
107 object.custom_values.each do |v|
107 object.custom_values.each do |v|
108 v.errors.each do |attr, msg|
108 v.errors.each do |attr, msg|
109 next if msg.nil?
109 next if msg.nil?
110 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
110 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
111 end
111 end
112 end
112 end
113 end
113 end
114 content_tag("div",
114 content_tag("div",
115 content_tag(
115 content_tag(
116 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
116 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
117 ) +
117 ) +
118 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
118 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
119 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
119 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
120 )
120 )
121 else
121 else
122 ""
122 ""
123 end
123 end
124 end
124 end
125
125
126 def lang_options_for_select
126 def lang_options_for_select
127 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
127 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
128 end
128 end
129
129
130 def label_tag_for(name, option_tags = nil, options = {})
130 def label_tag_for(name, option_tags = nil, options = {})
131 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
131 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
132 content_tag("label", label_text)
132 content_tag("label", label_text)
133 end
133 end
134
134
135 def labelled_tabular_form_for(name, object, options, &proc)
135 def labelled_tabular_form_for(name, object, options, &proc)
136 options[:html] ||= {}
136 options[:html] ||= {}
137 options[:html].store :class, "tabular"
137 options[:html].store :class, "tabular"
138 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
138 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
139 end
139 end
140
140
141 def check_all_links(form_name)
141 def check_all_links(form_name)
142 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
142 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
143 " | " +
143 " | " +
144 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
144 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
145 end
145 end
146
146
147 def calendar_for(field_id)
147 def calendar_for(field_id)
148 image_tag("calendar", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
148 image_tag("calendar", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
149 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
149 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
150 end
150 end
151 end
151 end
152
152
153 class TabularFormBuilder < ActionView::Helpers::FormBuilder
153 class TabularFormBuilder < ActionView::Helpers::FormBuilder
154 include GLoc
154 include GLoc
155
155
156 def initialize(object_name, object, template, options, proc)
156 def initialize(object_name, object, template, options, proc)
157 set_language_if_valid options.delete(:lang)
157 set_language_if_valid options.delete(:lang)
158 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
158 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
159 end
159 end
160
160
161 (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
161 (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
162 src = <<-END_SRC
162 src = <<-END_SRC
163 def #{selector}(field, options = {})
163 def #{selector}(field, options = {})
164 return super if options.delete :no_label
164 return super if options.delete :no_label
165 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
165 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
166 label = @template.content_tag("label", label_text,
166 label = @template.content_tag("label", label_text,
167 :class => (@object && @object.errors[field] ? "error" : nil),
167 :class => (@object && @object.errors[field] ? "error" : nil),
168 :for => (@object_name.to_s + "_" + field.to_s))
168 :for => (@object_name.to_s + "_" + field.to_s))
169 label + super
169 label + super
170 end
170 end
171 END_SRC
171 END_SRC
172 class_eval src, __FILE__, __LINE__
172 class_eval src, __FILE__, __LINE__
173 end
173 end
174
174
175 def select(field, choices, options = {}, html_options = {})
175 def select(field, choices, options = {}, html_options = {})
176 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
176 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
177 label = @template.content_tag("label", label_text,
177 label = @template.content_tag("label", label_text,
178 :class => (@object && @object.errors[field] ? "error" : nil),
178 :class => (@object && @object.errors[field] ? "error" : nil),
179 :for => (@object_name.to_s + "_" + field.to_s))
179 :for => (@object_name.to_s + "_" + field.to_s))
180 label + super
180 label + super
181 end
181 end
182
182
183 end
183 end
184
184
@@ -1,35 +1,35
1 <%= stylesheet_link_tag "scm" %>
1 <%= stylesheet_link_tag "scm" %>
2
2
3 <div class="contextual">
3 <div class="contextual">
4 <%= start_form_tag %>
4 <%= start_form_tag %>
5 <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
5 <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
6 <%= submit_tag 'OK' %>
6 <%= submit_tag 'OK' %>
7 </div>
7 </div>
8
8
9 <h2><%= l(:label_revision) %> <%= @revision.identifier %></h2>
9 <h2><%= l(:label_revision) %> <%= @revision.identifier %></h2>
10
10
11 <p><em><%= @revision.author %>, <%= format_time(@revision.time) %></em></p>
11 <p><em><%= @revision.author %>, <%= format_time(@revision.time) %></em></p>
12 <%= simple_format @revision.message %>
12 <%= textilizable @revision.message %>
13
13
14 <div style="float:right;">
14 <div style="float:right;">
15 <div class="square action_A"></div> <div style="float:left;"><%= l(:label_added) %>&nbsp;</div>
15 <div class="square action_A"></div> <div style="float:left;"><%= l(:label_added) %>&nbsp;</div>
16 <div class="square action_M"></div> <div style="float:left;"><%= l(:label_modified) %>&nbsp;</div>
16 <div class="square action_M"></div> <div style="float:left;"><%= l(:label_modified) %>&nbsp;</div>
17 <div class="square action_D"></div> <div style="float:left;"><%= l(:label_deleted) %>&nbsp;</div>
17 <div class="square action_D"></div> <div style="float:left;"><%= l(:label_deleted) %>&nbsp;</div>
18 </div>
18 </div>
19
19
20 <h3><%= l(:label_attachment_plural) %></h3>
20 <h3><%= l(:label_attachment_plural) %></h3>
21 <table class="list">
21 <table class="list">
22 <tbody>
22 <tbody>
23 <% @revision.paths.each do |path| %>
23 <% @revision.paths.each do |path| %>
24 <tr class="<%= cycle 'odd', 'even' %>">
24 <tr class="<%= cycle 'odd', 'even' %>">
25 <td><div class="square action_<%= path[:action] %>"></div> <%= path[:path] %></td>
25 <td><div class="square action_<%= path[:action] %>"></div> <%= path[:path] %></td>
26 <td>
26 <td>
27 <% if path[:action] == "M" %>
27 <% if path[:action] == "M" %>
28 <%= link_to 'View diff', :action => 'diff', :id => @project, :path => path[:path].gsub(/^\//, ''), :rev => @revision.identifier %>
28 <%= link_to 'View diff', :action => 'diff', :id => @project, :path => path[:path].gsub(/^\//, ''), :rev => @revision.identifier %>
29 <% end %>
29 <% end %>
30 </td>
30 </td>
31 </tr>
31 </tr>
32 <% end %>
32 <% end %>
33 </tbody>
33 </tbody>
34 </table>
34 </table>
35 <p><%= lwr(:label_modification, @revision.paths.length) %></p> No newline at end of file
35 <p><%= lwr(:label_modification, @revision.paths.length) %></p>
@@ -1,38 +1,38
1 <%= stylesheet_link_tag "scm" %>
1 <%= stylesheet_link_tag "scm" %>
2
2
3 <div class="contextual">
3 <div class="contextual">
4 <%= start_form_tag %>
4 <%= start_form_tag %>
5 <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
5 <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
6 <%= submit_tag 'OK' %>
6 <%= submit_tag 'OK' %>
7 </div>
7 </div>
8
8
9 <h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => @entry.kind, :revision => @rev } %></h2>
9 <h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => @entry.kind, :revision => @rev } %></h2>
10
10
11 <% if @entry.is_file? %>
11 <% if @entry.is_file? %>
12 <h3><%=h @entry.name %></h3>
12 <h3><%=h @entry.name %></h3>
13 <p><%= link_to 'Download', {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' }, :class => "icon file" %> (<%= human_size @entry.size %>)</p>
13 <p><%= link_to 'Download', {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' }, :class => "icon file" %> (<%= human_size @entry.size %>)</p>
14 <% end %>
14 <% end %>
15
15
16 <h3>Revisions</h3>
16 <h3>Revisions</h3>
17
17
18 <table class="list">
18 <table class="list">
19 <thead><tr>
19 <thead><tr>
20 <th>#</th>
20 <th>#</th>
21 <th><%= l(:field_author) %></th>
21 <th><%= l(:field_author) %></th>
22 <th><%= l(:label_date) %></th>
22 <th><%= l(:label_date) %></th>
23 <th><%= l(:field_description) %></th>
23 <th><%= l(:field_description) %></th>
24 <th></th>
24 <th></th>
25 </tr></thead>
25 </tr></thead>
26 <tbody>
26 <tbody>
27 <% @revisions.each do |revision| %>
27 <% @revisions.each do |revision| %>
28 <tr class="<%= cycle 'odd', 'even' %>">
28 <tr class="<%= cycle 'odd', 'even' %>">
29 <th align="center"><%= link_to revision.identifier, :action => 'revision', :id => @project, :rev => revision.identifier %></th>
29 <th align="center"><%= link_to revision.identifier, :action => 'revision', :id => @project, :rev => revision.identifier %></th>
30 <td align="center"><em><%=h revision.author %></em></td>
30 <td align="center"><em><%=h revision.author %></em></td>
31 <td align="center"><%= format_time(revision.time) %></td>
31 <td align="center"><%= format_time(revision.time) %></td>
32 <td width="70%"><%= simple_format(h(revision.message)) %></td>
32 <td width="70%"><%= textilizable(revision.message) %></td>
33 <td align="center"><%= link_to 'Diff', :action => 'diff', :id => @project, :path => @path, :rev => revision.identifier if @entry.is_file? && revision != @revisions.last %></td>
33 <td align="center"><%= link_to 'Diff', :action => 'diff', :id => @project, :path => @path, :rev => revision.identifier if @entry.is_file? && revision != @revisions.last %></td>
34 </tr>
34 </tr>
35 <% end %>
35 <% end %>
36 </tbody>
36 </tbody>
37 </table>
37 </table>
38 <p><%= lwr(:label_modification, @revisions.length) %></p> No newline at end of file
38 <p><%= lwr(:label_modification, @revisions.length) %></p>
General Comments 0
You need to be logged in to leave comments. Login now