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