##// END OF EJS Templates
views cleaning...
Jean-Philippe Lang -
r20:893a43316548
parent child
Show More
@@ -1,150 +1,156
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 pagination_links_full(paginator, options={}, html_options={})
62 62 html =''
63 63 html << link_to(('&#171; ' + l(:label_previous) ), { :page => paginator.current.previous }) + ' ' if paginator.current.previous
64 64 html << (pagination_links(paginator, options, html_options) || '')
65 65 html << ' ' + link_to((l(:label_next) + ' &#187;'), { :page => paginator.current.next }) if paginator.current.next
66 66 html
67 67 end
68 68
69 69 def error_messages_for(object_name, options = {})
70 70 options = options.symbolize_keys
71 71 object = instance_variable_get("@#{object_name}")
72 72 if object && !object.errors.empty?
73 73 # build full_messages here with controller current language
74 74 full_messages = []
75 75 object.errors.each do |attr, msg|
76 76 next if msg.nil?
77 77 if attr == "base"
78 78 full_messages << l(msg)
79 79 else
80 80 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
81 81 end
82 82 end
83 83 # retrieve custom values error messages
84 84 if object.errors[:custom_values]
85 85 object.custom_values.each do |v|
86 86 v.errors.each do |attr, msg|
87 87 next if msg.nil?
88 88 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
89 89 end
90 90 end
91 91 end
92 92 content_tag("div",
93 93 content_tag(
94 94 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
95 95 ) +
96 96 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
97 97 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
98 98 )
99 99 else
100 100 ""
101 101 end
102 102 end
103 103
104 104 def lang_options_for_select
105 105 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
106 106 end
107 107
108 108 def label_tag_for(name, option_tags = nil, options = {})
109 109 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
110 110 content_tag("label", label_text)
111 111 end
112 112
113 113 def labelled_tabular_form_for(name, object, options, &proc)
114 114 options[:html] ||= {}
115 115 options[:html].store :class, "tabular"
116 116 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
117 117 end
118
119 def check_all_links(form_name)
120 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
121 " | " +
122 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
123 end
118 124 end
119 125
120 126 class TabularFormBuilder < ActionView::Helpers::FormBuilder
121 127 include GLoc
122 128
123 129 def initialize(object_name, object, template, options, proc)
124 130 set_language_if_valid options.delete(:lang)
125 131 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
126 132 end
127 133
128 134 (field_helpers - %w(radio_button) + %w(date_select)).each do |selector|
129 135 src = <<-END_SRC
130 136 def #{selector}(field, options = {})
131 137 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
132 138 label = @template.content_tag("label", label_text,
133 139 :class => (@object.errors[field] ? "error" : nil),
134 140 :for => (@object_name.to_s + "_" + field.to_s))
135 141 label + super
136 142 end
137 143 END_SRC
138 144 class_eval src, __FILE__, __LINE__
139 145 end
140 146
141 147 def select(field, choices, options = {})
142 148 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
143 149 label = @template.content_tag("label", label_text,
144 150 :class => (@object.errors[field] ? "error" : nil),
145 151 :for => (@object_name.to_s + "_" + field.to_s))
146 152 label + super
147 153 end
148 154
149 155 end
150 156
@@ -1,25 +1,24
1 1 <h2><%=l(:field_mail_notification)%></h2>
2 2
3 <p><%=l(:text_select_mail_notifications)%></p>
4
5 3 <%= start_form_tag ({}, :id => 'mail_options_form')%>
6 4
5 <div class="box">
6 <p><%=l(:text_select_mail_notifications)%></p>
7
7 8 <% actions = @actions.group_by {|p| p.group_id } %>
8 9 <% actions.keys.sort.each do |group_id| %>
9 10 <fieldset style="margin-top: 6px;"><legend><strong><%= l(Permission::GROUPS[group_id]) %></strong></legend>
10 11 <% actions[group_id].each do |p| %>
11 12 <div style="width:170px;float:left;"><%= check_box_tag "action_ids[]", p.id, p.mail_enabled? %>
12 13 <%= l(p.description.to_sym) %>
13 14 </div>
14 15 <% end %>
15 16 </fieldset>
16 17 <% end %>
17 18
18
19 19 <br />
20 <p>
21 <a href="javascript:checkAll('mail_options_form', true)"><%=l(:button_check_all)%></a> |
22 <a href="javascript:checkAll('mail_options_form', false)"><%=l(:button_uncheck_all)%></a>
23 </p>
20 <p><%= check_all_links 'mail_options_form' %></p>
21 </div>
22
24 23 <%= submit_tag l(:button_save) %>
25 <%= end_form_tag %> No newline at end of file
24 <%= end_form_tag %>
@@ -1,25 +1,25
1 1 <h2><%=l(:label_change_log)%></h2>
2 2
3
4 3 <%= start_form_tag %>
5 4 <% @trackers.each do |tracker| %>
6 5 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
7 6 <%= tracker.name %>
8 7 <% end %>
9 8 &nbsp;&nbsp;<%= submit_tag l(:button_apply), :class => 'button-small' %>
10 <%= end_form_tag %>
11
12 <p>&nbsp;</p>
9 <%= end_form_tag %><br />
10 &nbsp;
13 11
12 <div class="box">
14 13 <% ver_id = nil
15 14 @fixed_issues.each do |issue| %>
16 15 <% unless ver_id == issue.fixed_version_id %>
17 16 <% if ver_id %></ul><% end %>
18 17 <p><strong><%= issue.fixed_version.name %></strong> - <%= format_date(issue.fixed_version.effective_date) %><br />
19 18 <%=h issue.fixed_version.description %></p>
20 19 <ul>
21 20 <% ver_id = issue.fixed_version_id
22 21 end %>
23 22 <li><%= link_to issue.long_id, :controller => 'issues', :action => 'show', :id => issue %> [<%= issue.tracker.name %>]: <%= issue.subject %></li>
24 23 <% end %>
25 24
25 </div> No newline at end of file
@@ -1,21 +1,23
1 1 <h2><%=l(:label_document_plural)%></h2>
2 2
3 <% if @documents.empty? %><p><i><%= l(:label_no_data) %></i></p><% end %>
4
3 5 <% documents = @documents.group_by {|d| d.category } %>
4 6 <% documents.each do |category, docs| %>
5 7 <h3><%= category.name %></h3>
6 8 <ul>
7 9 <% docs.each do |d| %>
8 10 <li>
9 11 <b><%= link_to d.title, :controller => 'documents', :action => 'show', :id => d %></b>
10 12 <br />
11 13 <%=l(:field_description)%>: <%= d.description %><br />
12 14 <%= format_time(d.created_on) %>
13 15 </li>
14 16
15 17 <% end %>
16 18 </ul>
17 19 <% end %>
18 20
19 21 <p>
20 22 <%= link_to_if_authorized '&#187; ' + l(:label_document_new), :controller => 'projects', :action => 'add_document', :id => @project %>
21 23 </p>
@@ -1,14 +1,16
1 1 <h2><%=l(:label_news_plural)%></h2>
2 2
3 <% if @news.empty? %><p><i><%= l(:label_no_data) %></i></p><% end %>
4
3 5 <% for news in @news %>
4 6 <p>
5 7 <b><%= news.title %></b> <small>(<%= link_to_user news.author %> <%= format_time(news.created_on) %>)</small><br />
6 8 <%= news.summary %><br />
7 9 <small>[<%= link_to l(:label_read), :controller => 'news', :action => 'show', :id => news %>]</small>
8 10 </p>
9 11 <% end %>
10 12
11 13 <%= pagination_links_full @news_pages %>
12 14 <p>
13 15 <%= link_to_if_authorized '&#187; ' + l(:label_news_new), :controller => 'projects', :action => 'add_news', :id => @project %>
14 16 </p>
@@ -1,72 +1,72
1 1 <h2><%=l(:label_overview)%></h2>
2 2
3 3 <div class="splitcontentleft">
4 <%= @project.description %>
4 <%= simple_format auto_link @project.description %>
5 5 <ul>
6 6 <li><%=l(:field_homepage)%>: <%= link_to @project.homepage, @project.homepage %></li>
7 7 <li><%=l(:field_created_on)%>: <%= format_date(@project.created_on) %></li>
8 8 <% for custom_value in @custom_values %>
9 9 <% if !custom_value.value.empty? %>
10 10 <li><%= custom_value.custom_field.name%>: <%= custom_value.value%></li>
11 11 <% end %>
12 12 <% end %>
13 13 </ul>
14 14
15 15 <div class="box">
16 16 <h3><%= image_tag "tracker" %> <%=l(:label_tracker_plural)%></h3>
17 17 <ul>
18 18 <% for tracker in @trackers %>
19 19 <li><%= link_to tracker.name, :controller => 'projects', :action => 'list_issues', :id => @project,
20 20 :set_filter => 1,
21 21 "tracker_id" => tracker.id %>:
22 22 <%= issue_count = Issue.count(:conditions => ["project_id=? and tracker_id=? and issue_statuses.is_closed=?", @project.id, tracker.id, false], :include => :status) %>
23 23 <%= lwr(:label_open_issues, issue_count) %>
24 24 </li>
25 25 <% end %>
26 26 </ul>
27 27 <% if authorize_for 'projects', 'add_issue' %>
28 28 &#187; <%=l(:label_issue_new)%>:
29 29 <ul>
30 30 <% @trackers.each do |tracker| %>
31 31 <li><%= link_to tracker.name, :controller => 'projects', :action => 'add_issue', :id => @project, :tracker_id => tracker %></li>
32 32 <% end %>
33 33 </ul>
34 34 <% end %>
35 35 <center><small>[ <%= link_to l(:label_issue_view_all), :controller => 'projects', :action => 'list_issues', :id => @project, :set_filter => 1 %> ]</small></center>
36 36 </div>
37 37 </div>
38 38
39 39 <div class="splitcontentright">
40 40 <div class="box">
41 41 <h3><%= image_tag "users" %> <%=l(:label_member_plural)%></h3>
42 42 <% for member in @members %>
43 43 <%= link_to_user member.user %> (<%= member.role.name %>)<br />
44 44 <% end %>
45 45 </div>
46 46
47 47 <% if @subprojects %>
48 48 <div class="box">
49 49 <h3><%= image_tag "projects" %> <%=l(:label_subproject_plural)%></h3>
50 50 <% for subproject in @subprojects %>
51 51 <%= link_to subproject.name, :action => 'show', :id => subproject %><br />
52 52 <% end %>
53 53 </div>
54 54 <% end %>
55 55
56 56 <div class="box">
57 57 <h3><%=l(:label_news_latest)%></h3>
58 58 <% for news in @news %>
59 59 <p><b><%= news.title %></b> <small>(<%= link_to_user news.author %> <%= format_time(news.created_on) %>)</small><br />
60 60 <%= news.summary %>
61 61 <small>[<%= link_to l(:label_read), :controller => 'news', :action => 'show', :id => news %>]</small></p>
62 62 <hr />
63 63 <% end %>
64 64 <center><small>[ <%= link_to l(:label_news_view_all), :controller => 'projects', :action => 'list_news', :id => @project %> ]</small></center>
65 65 </div>
66 66 </div>
67 67
68 68
69 69
70 70
71 71
72 72
@@ -1,21 +1,20
1 1 <%= error_messages_for 'role' %>
2 2 <div class="box">
3 3 <!--[form:role]-->
4 4 <p><%= f.text_field :name, :required => true %></p>
5 5
6 6 <strong><%=l(:label_permissions)%>:</strong>
7 7 <% permissions = @permissions.group_by {|p| p.group_id } %>
8 8 <% permissions.keys.sort.each do |group_id| %>
9 9 <fieldset style="margin-top: 6px;"><legend><strong><%= l(Permission::GROUPS[group_id]) %></strong></legend>
10 10 <% permissions[group_id].each do |p| %>
11 11 <div style="width:170px;float:left;"><%= check_box_tag "permission_ids[]", p.id, (@role.permissions.include? p) %>
12 12 <%= l(p.description.to_sym) %>
13 13 </div>
14 14 <% end %>
15 15 </fieldset>
16 16 <% end %>
17 <br />
18 <a href="javascript:checkAll('role_form', true)"><%=l(:button_check_all)%></a> |
19 <a href="javascript:checkAll('role_form', false)"><%=l(:button_uncheck_all)%></a><br />
17 <br />
18 <%= check_all_links 'role_form' %>
20 19 <!--[eoform:role]-->
21 20 </div>
General Comments 0
You need to be logged in to leave comments. Login now