##// END OF EJS Templates
Fixed pagination on users/list (status filter lost)...
Jean-Philippe Lang -
r406:1c0971b12c60
parent child
Show More
@@ -1,230 +1,230
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
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 image_to_function(name, function, html_options = {})
54 54 html_options.symbolize_keys!
55 55 tag(:input, html_options.merge({
56 56 :type => "image", :src => image_path(name),
57 57 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
58 58 }))
59 59 end
60 60
61 61 def format_date(date)
62 62 l_date(date) if date
63 63 end
64 64
65 65 def format_time(time)
66 66 l_datetime((time.is_a? String) ? time.to_time : time) if time
67 67 end
68 68
69 69 def day_name(day)
70 70 l(:general_day_names).split(',')[day-1]
71 71 end
72 72
73 73 def month_name(month)
74 74 l(:actionview_datehelper_select_month_names).split(',')[month-1]
75 75 end
76 76
77 77 def pagination_links_full(paginator, options={}, html_options={})
78 78 html = ''
79 79 html << link_to_remote(('&#171; ' + l(:label_previous)),
80 {:update => "content", :url => { :page => paginator.current.previous }},
81 {:href => url_for(:action => 'list', :params =>{:page => paginator.current.previous})}) + ' ' if paginator.current.previous
80 {:update => "content", :url => options.merge(:page => paginator.current.previous)},
81 {:href => url_for(:params => options.merge(:page => paginator.current.previous))}) + ' ' if paginator.current.previous
82 82
83 83 html << (pagination_links_each(paginator, options) do |n|
84 84 link_to_remote(n.to_s,
85 {:url => {:action => 'list', :params => {:page => n}}, :update => 'content'},
86 {:href => url_for(:action => 'list', :params => {:page => n})})
85 {:url => {:action => 'list', :params => options.merge(:page => n)}, :update => 'content'},
86 {:href => url_for(:params => options.merge(:page => n))})
87 87 end || '')
88 88
89 89 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
90 {:update => "content", :url => { :page => paginator.current.next }},
91 {:href => url_for(:action => 'list', :params => {:page => paginator.current.next})}) if paginator.current.next
90 {:update => "content", :url => options.merge(:page => paginator.current.next)},
91 {:href => url_for(:params => options.merge(:page => paginator.current.next))}) if paginator.current.next
92 92 html
93 93 end
94 94
95 95 # textilize text according to system settings and RedCloth availability
96 96 def textilizable(text, options = {})
97 97 # different methods for formatting wiki links
98 98 case options[:wiki_links]
99 99 when :local
100 100 # used for local links to html files
101 101 format_wiki_link = Proc.new {|title| "#{title}.html" }
102 102 when :anchor
103 103 # used for single-file wiki export
104 104 format_wiki_link = Proc.new {|title| "##{title}" }
105 105 else
106 106 if @project
107 107 format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
108 108 else
109 109 format_wiki_link = Proc.new {|title| title }
110 110 end
111 111 end
112 112
113 113 # turn wiki links into textile links:
114 114 # example:
115 115 # [[link]] -> "link":link
116 116 # [[link|title]] -> "title":link
117 117 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) }
118 118
119 119 # turn issue ids to textile links
120 120 # example:
121 121 # #52 -> "#52":/issues/show/52
122 122 text = text.gsub(/#(\d+)(?=\b)/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) }
123 123
124 124 # turn revision ids to textile links (@project needed)
125 125 # example:
126 126 # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6)
127 127 text = text.gsub(/r(\d+)(?=\b)/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) } if @project
128 128
129 129 # finally textilize text
130 130 @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize")
131 131 text = @do_textilize ? auto_link(RedCloth.new(text).to_html) : simple_format(auto_link(h(text)))
132 132 end
133 133
134 134 def error_messages_for(object_name, options = {})
135 135 options = options.symbolize_keys
136 136 object = instance_variable_get("@#{object_name}")
137 137 if object && !object.errors.empty?
138 138 # build full_messages here with controller current language
139 139 full_messages = []
140 140 object.errors.each do |attr, msg|
141 141 next if msg.nil?
142 142 msg = msg.first if msg.is_a? Array
143 143 if attr == "base"
144 144 full_messages << l(msg)
145 145 else
146 146 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
147 147 end
148 148 end
149 149 # retrieve custom values error messages
150 150 if object.errors[:custom_values]
151 151 object.custom_values.each do |v|
152 152 v.errors.each do |attr, msg|
153 153 next if msg.nil?
154 154 msg = msg.first if msg.is_a? Array
155 155 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
156 156 end
157 157 end
158 158 end
159 159 content_tag("div",
160 160 content_tag(
161 161 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
162 162 ) +
163 163 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
164 164 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
165 165 )
166 166 else
167 167 ""
168 168 end
169 169 end
170 170
171 171 def lang_options_for_select(blank=true)
172 172 (blank ? [["(auto)", ""]] : []) +
173 173 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
174 174 end
175 175
176 176 def label_tag_for(name, option_tags = nil, options = {})
177 177 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
178 178 content_tag("label", label_text)
179 179 end
180 180
181 181 def labelled_tabular_form_for(name, object, options, &proc)
182 182 options[:html] ||= {}
183 183 options[:html].store :class, "tabular"
184 184 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
185 185 end
186 186
187 187 def check_all_links(form_name)
188 188 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
189 189 " | " +
190 190 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
191 191 end
192 192
193 193 def calendar_for(field_id)
194 194 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
195 195 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
196 196 end
197 197 end
198 198
199 199 class TabularFormBuilder < ActionView::Helpers::FormBuilder
200 200 include GLoc
201 201
202 202 def initialize(object_name, object, template, options, proc)
203 203 set_language_if_valid options.delete(:lang)
204 204 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
205 205 end
206 206
207 207 (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
208 208 src = <<-END_SRC
209 209 def #{selector}(field, options = {})
210 210 return super if options.delete :no_label
211 211 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
212 212 label = @template.content_tag("label", label_text,
213 213 :class => (@object && @object.errors[field] ? "error" : nil),
214 214 :for => (@object_name.to_s + "_" + field.to_s))
215 215 label + super
216 216 end
217 217 END_SRC
218 218 class_eval src, __FILE__, __LINE__
219 219 end
220 220
221 221 def select(field, choices, options = {}, html_options = {})
222 222 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
223 223 label = @template.content_tag("label", label_text,
224 224 :class => (@object && @object.errors[field] ? "error" : nil),
225 225 :for => (@object_name.to_s + "_" + field.to_s))
226 226 label + super
227 227 end
228 228
229 229 end
230 230
@@ -1,60 +1,60
1 1 <div class="contextual">
2 2 <%= link_to l(:label_user_new), {:action => 'add'}, :class => 'icon icon-add' %>
3 3 </div>
4 4
5 5 <h2><%=l(:label_user_plural)%></h2>
6 6
7 7 <% form_tag() do %>
8 8 <fieldset><legend><%= l(:label_filter_plural) %></legend>
9 9 <label><%= l(:field_status) %> :</label>
10 10 <%= select_tag 'status', status_options_for_select(@status), :class => "small", :onchange => "this.form.submit(); return false;" %>
11 11 <%= submit_tag l(:button_apply), :class => "small" %>
12 12 </fieldset>
13 13 <% end %>
14 14 &nbsp;
15 15
16 16 <table class="list">
17 17 <thead><tr>
18 18 <%= sort_header_tag('login', :caption => l(:field_login)) %>
19 19 <%= sort_header_tag('firstname', :caption => l(:field_firstname)) %>
20 20 <%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
21 21 <th><%=l(:field_mail)%></th>
22 22 <%= sort_header_tag('admin', :caption => l(:field_admin)) %>
23 23 <%= sort_header_tag('status', :caption => l(:field_status)) %>
24 24 <%= sort_header_tag('created_on', :caption => l(:field_created_on)) %>
25 25 <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on)) %>
26 26 <th></th>
27 27 </tr></thead>
28 28 <tbody>
29 29 <% for user in @users %>
30 30 <tr class="<%= cycle("odd", "even") %>">
31 31 <td><%= link_to user.login, :action => 'edit', :id => user %></td>
32 32 <td><%= user.firstname %></td>
33 33 <td><%= user.lastname %></td>
34 34 <td><%= user.mail %></td>
35 35 <td align="center"><%= image_tag 'true.png' if user.admin? %></td>
36 36 <td align="center"><%= image_tag 'locked.png' if user.locked? %><%= image_tag 'user_new.png' if user.registered? %></td>
37 37 <td align="center"><%= format_time(user.created_on) %></td>
38 38 <td align="center"><%= format_time(user.last_login_on) unless user.last_login_on.nil? %></td>
39 39 <td align="center">
40 40 <% form_tag({:action => 'edit', :id => user}) do %>
41 41 <% if user.locked? %>
42 42 <%= hidden_field_tag 'user[status]', User::STATUS_ACTIVE %>
43 43 <%= submit_tag l(:button_unlock), :class => "button-small" %>
44 44 <% elsif user.registered? %>
45 45 <%= hidden_field_tag 'user[status]', User::STATUS_ACTIVE %>
46 46 <%= submit_tag l(:button_activate), :class => "button-small" %>
47 47 <% else %>
48 48 <%= hidden_field_tag 'user[status]', User::STATUS_LOCKED %>
49 49 <%= submit_tag l(:button_lock), :class => "button-small" %>
50 50 <% end %>
51 51 <% end %>
52 52 </td>
53 53 </tr>
54 54 <% end %>
55 55 </tbody>
56 56 </table>
57 57
58 <p><%= pagination_links_full @user_pages %>
58 <p><%= pagination_links_full @user_pages, :status => @status %>
59 59 [ <%= @user_pages.current.first_item %> - <%= @user_pages.current.last_item %> / <%= @user_count %> ]
60 60 </p> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now