##// END OF EJS Templates
Added toggle_link helper....
Jean-Philippe Lang -
r429:30734ba8e8f0
parent child
Show More
@@ -1,234 +1,241
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) ) )
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 link_to_issue(issue)
54 54 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
55 55 end
56 56
57 def toggle_link(name, id, options={})
58 onclick = "Element.toggle('#{id}'); "
59 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
60 onclick << "return false;"
61 link_to(name, "#", :onclick => onclick)
62 end
63
57 64 def image_to_function(name, function, html_options = {})
58 65 html_options.symbolize_keys!
59 66 tag(:input, html_options.merge({
60 67 :type => "image", :src => image_path(name),
61 68 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
62 69 }))
63 70 end
64 71
65 72 def format_date(date)
66 73 l_date(date) if date
67 74 end
68 75
69 76 def format_time(time)
70 77 l_datetime((time.is_a? String) ? time.to_time : time) if time
71 78 end
72 79
73 80 def day_name(day)
74 81 l(:general_day_names).split(',')[day-1]
75 82 end
76 83
77 84 def month_name(month)
78 85 l(:actionview_datehelper_select_month_names).split(',')[month-1]
79 86 end
80 87
81 88 def pagination_links_full(paginator, options={}, html_options={})
82 89 html = ''
83 90 html << link_to_remote(('&#171; ' + l(:label_previous)),
84 91 {:update => "content", :url => options.merge(:page => paginator.current.previous)},
85 92 {:href => url_for(:params => options.merge(:page => paginator.current.previous))}) + ' ' if paginator.current.previous
86 93
87 94 html << (pagination_links_each(paginator, options) do |n|
88 95 link_to_remote(n.to_s,
89 96 {:url => {:action => 'list', :params => options.merge(:page => n)}, :update => 'content'},
90 97 {:href => url_for(:params => options.merge(:page => n))})
91 98 end || '')
92 99
93 100 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
94 101 {:update => "content", :url => options.merge(:page => paginator.current.next)},
95 102 {:href => url_for(:params => options.merge(:page => paginator.current.next))}) if paginator.current.next
96 103 html
97 104 end
98 105
99 106 # textilize text according to system settings and RedCloth availability
100 107 def textilizable(text, options = {})
101 108 # different methods for formatting wiki links
102 109 case options[:wiki_links]
103 110 when :local
104 111 # used for local links to html files
105 112 format_wiki_link = Proc.new {|title| "#{title}.html" }
106 113 when :anchor
107 114 # used for single-file wiki export
108 115 format_wiki_link = Proc.new {|title| "##{title}" }
109 116 else
110 117 if @project
111 118 format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
112 119 else
113 120 format_wiki_link = Proc.new {|title| title }
114 121 end
115 122 end
116 123
117 124 # turn wiki links into textile links:
118 125 # example:
119 126 # [[link]] -> "link":link
120 127 # [[link|title]] -> "title":link
121 128 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) }
122 129
123 130 # turn issue ids to textile links
124 131 # example:
125 132 # #52 -> "#52":/issues/show/52
126 133 text = text.gsub(/#(\d+)(?=\b)/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) }
127 134
128 135 # turn revision ids to textile links (@project needed)
129 136 # example:
130 137 # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6)
131 138 text = text.gsub(/r(\d+)(?=\b)/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) } if @project
132 139
133 140 # finally textilize text
134 141 @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize")
135 142 text = @do_textilize ? auto_link(RedCloth.new(text).to_html) : simple_format(auto_link(h(text)))
136 143 end
137 144
138 145 def error_messages_for(object_name, options = {})
139 146 options = options.symbolize_keys
140 147 object = instance_variable_get("@#{object_name}")
141 148 if object && !object.errors.empty?
142 149 # build full_messages here with controller current language
143 150 full_messages = []
144 151 object.errors.each do |attr, msg|
145 152 next if msg.nil?
146 153 msg = msg.first if msg.is_a? Array
147 154 if attr == "base"
148 155 full_messages << l(msg)
149 156 else
150 157 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
151 158 end
152 159 end
153 160 # retrieve custom values error messages
154 161 if object.errors[:custom_values]
155 162 object.custom_values.each do |v|
156 163 v.errors.each do |attr, msg|
157 164 next if msg.nil?
158 165 msg = msg.first if msg.is_a? Array
159 166 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
160 167 end
161 168 end
162 169 end
163 170 content_tag("div",
164 171 content_tag(
165 172 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
166 173 ) +
167 174 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
168 175 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
169 176 )
170 177 else
171 178 ""
172 179 end
173 180 end
174 181
175 182 def lang_options_for_select(blank=true)
176 183 (blank ? [["(auto)", ""]] : []) +
177 184 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
178 185 end
179 186
180 187 def label_tag_for(name, option_tags = nil, options = {})
181 188 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
182 189 content_tag("label", label_text)
183 190 end
184 191
185 192 def labelled_tabular_form_for(name, object, options, &proc)
186 193 options[:html] ||= {}
187 194 options[:html].store :class, "tabular"
188 195 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
189 196 end
190 197
191 198 def check_all_links(form_name)
192 199 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
193 200 " | " +
194 201 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
195 202 end
196 203
197 204 def calendar_for(field_id)
198 205 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
199 206 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
200 207 end
201 208 end
202 209
203 210 class TabularFormBuilder < ActionView::Helpers::FormBuilder
204 211 include GLoc
205 212
206 213 def initialize(object_name, object, template, options, proc)
207 214 set_language_if_valid options.delete(:lang)
208 215 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
209 216 end
210 217
211 218 (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
212 219 src = <<-END_SRC
213 220 def #{selector}(field, options = {})
214 221 return super if options.delete :no_label
215 222 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
216 223 label = @template.content_tag("label", label_text,
217 224 :class => (@object && @object.errors[field] ? "error" : nil),
218 225 :for => (@object_name.to_s + "_" + field.to_s))
219 226 label + super
220 227 end
221 228 END_SRC
222 229 class_eval src, __FILE__, __LINE__
223 230 end
224 231
225 232 def select(field, choices, options = {}, html_options = {})
226 233 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
227 234 label = @template.content_tag("label", label_text,
228 235 :class => (@object && @object.errors[field] ? "error" : nil),
229 236 :for => (@object_name.to_s + "_" + field.to_s))
230 237 label + super
231 238 end
232 239
233 240 end
234 241
@@ -1,33 +1,32
1 1 <div class="contextual">
2 2 <%= link_to_if_authorized l(:button_edit), {:controller => 'news', :action => 'edit', :id => @news}, :class => 'icon icon-edit' %>
3 3 <%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy', :id => @news}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
4 4 </div>
5 5
6 6 <h2><%=h @news.title %></h2>
7 7
8 8 <p><em><% unless @news.summary.empty? %><%=h @news.summary %><br /><% end %>
9 9 <%= @news.author.display_name %>, <%= format_time(@news.created_on) %></em></p>
10 10 <br />
11 11 <%= textilizable auto_link @news.description %>
12 12 <br />
13 13
14 14 <div id="comments" style="margin-bottom:16px;">
15 15 <h3 class="icon22 icon22-comment"><%= l(:label_comment_plural) %></h3>
16 16 <% @news.comments.each do |comment| %>
17 17 <% next if comment.new_record? %>
18 18 <h4><%= format_time(comment.created_on) %> - <%= comment.author.name %></h4>
19 19 <div class="contextual">
20 20 <%= link_to_if_authorized l(:button_delete), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
21 21 </div>
22 22 <%= simple_format(auto_link(h comment.comment))%>
23 23 <% end if @news.comments_count > 0 %>
24 24 </div>
25 25
26 26 <% if authorize_for 'news', 'add_comment' %>
27 <% form_tag({:action => 'add_comment', :id => @news}) do %>
28 <%= error_messages_for 'comment' %>
29 <p><label for="comment_comment"><%= l(:label_comment_add) %></label><br />
30 <%= text_area 'comment', 'comment', :cols => 60, :rows => 6 %></p>
31 <%= submit_tag l(:button_add) %>
27 <p><%= toggle_link l(:label_comment_add), "add_comment_form", :focus => "comment_comment" %></p>
28 <% form_tag({:action => 'add_comment', :id => @news}, :id => "add_comment_form", :style => "display:none;") do %>
29 <%= text_area 'comment', 'comment', :cols => 60, :rows => 6 %>
30 <p><%= submit_tag l(:button_add) %></p>
32 31 <% end %>
33 32 <% end %> No newline at end of file
@@ -1,90 +1,90
1 1 <h2><%= l(:label_calendar) %></h2>
2 2
3 3 <% form_tag do %>
4 4 <table width="100%">
5 5 <tr>
6 6 <td align="left" style="width:15%">
7 7 <%= link_to_remote ('&#171; ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")),
8 8 {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }},
9 9 {:href => url_for(:action => 'calendar', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects])}
10 10 %>
11 11 </td>
12 12 <td align="center" style="width:55%">
13 13 <%= select_month(@month, :prefix => "month", :discard_type => true) %>
14 14 <%= select_year(@year, :prefix => "year", :discard_type => true) %>
15 15 <%= submit_tag l(:button_submit), :class => "button-small" %>
16 16 </td>
17 17 <td align="left" style="width:15%">
18 <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a>
18 <%= toggle_link l(:label_options), "trackerselect" %>
19 19 <div id="trackerselect" class="rightbox overlay" style="width:140px; display:none;">
20 20 <p><strong><%=l(:label_tracker_plural)%></strong></p>
21 21 <% @trackers.each do |tracker| %>
22 22 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
23 23 <%= tracker.name %><br />
24 24 <% end %>
25 25 <% if @project.children.any? %>
26 26 <p><strong><%=l(:label_subproject_plural)%></strong></p>
27 27 <%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%= l(:general_text_Yes) %>
28 28 <% end %>
29 29 <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p>
30 30 </div>
31 31 </td>
32 32 <td align="right" style="width:15%">
33 33 <%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' &#187;'),
34 34 {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }},
35 35 {:href => url_for(:action => 'calendar', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1), :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects])}
36 36 %>&nbsp;
37 37 </td>
38 38 </tr>
39 39 </table>
40 40 <% end %>
41 41
42 42 <table class="list with-cells">
43 43 <thead>
44 44 <tr>
45 45 <th></th>
46 46 <% 1.upto(7) do |d| %>
47 47 <th style="width:14%"><%= day_name(d) %></th>
48 48 <% end %>
49 49 </tr>
50 50 </thead>
51 51 <tbody>
52 52 <tr style="height:100px">
53 53 <% day = @date_from
54 54 while day <= @date_to
55 55 if day.cwday == 1 %>
56 56 <th><%= day.cweek %></th>
57 57 <% end %>
58 58 <td valign="top" class="<%= day.month==@month ? "even" : "odd" %>" style="width:14%; <%= Date.today == day ? 'background:#FDFED0;' : '' %>">
59 59 <p class="textright"><%= day==Date.today ? "<b>#{day.day}</b>" : day.day %></p>
60 60 <% ((@ending_events_by_days[day] || []) + (@starting_events_by_days[day] || [])).uniq.each do |i| %>
61 61 <% if i.is_a? Issue %>
62 62 <div class="tooltip">
63 63 <%= if day == i.start_date and day == i.due_date
64 64 image_tag('arrow_bw.png')
65 65 elsif day == i.start_date
66 66 image_tag('arrow_from.png')
67 67 elsif day == i.due_date
68 68 image_tag('arrow_to.png')
69 69 end %>
70 70 <small><%= link_to_issue i %>: <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small>
71 71 <span class="tip">
72 72 <%= render :partial => "issues/tooltip", :locals => { :issue => i }%>
73 73 </span>
74 74 </div>
75 75 <% else %>
76 76 <%= image_tag('milestone.png') %> <small><%= "#{l(:label_version)}: #{i.name}" %></small>
77 77 <% end %>
78 78 <% end %>
79 79 </td>
80 80 <%= '</tr><tr style="height:100px">' if day.cwday >= 7 and day!=@date_to %>
81 81 <%
82 82 day = day + 1
83 83 end %>
84 84 </tr>
85 85 </tbody>
86 86 </table>
87 87
88 88 <%= image_tag 'arrow_from.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_day) %><br />
89 89 <%= image_tag 'arrow_to.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_end_day) %><br />
90 90 <%= image_tag 'arrow_bw.png' %>&nbsp;&nbsp;<%= l(:text_tip_task_begin_end_day) %><br /> No newline at end of file
@@ -1,239 +1,239
1 1 <div class="contextual">
2 2 <%= l(:label_export_to) %>
3 3 <%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :output => 'pdf'}, :class => 'icon icon-pdf' %>
4 4 </div>
5 5
6 6 <h2><%= l(:label_gantt) %></h2>
7 7
8 8 <% form_tag do %>
9 9 <table width="100%">
10 10 <tr>
11 11 <td align="left">
12 12 <input type="text" name="months" size="2" value="<%= @months %>" />
13 13 <%= l(:label_months_from) %>
14 14 <%= select_month(@month_from, :prefix => "month", :discard_type => true) %>
15 15 <%= select_year(@year_from, :prefix => "year", :discard_type => true) %>
16 16 <%= hidden_field_tag 'zoom', @zoom %>
17 17 <%= submit_tag l(:button_submit), :class => "button-small" %>
18 18 </td>
19 19 <td>
20 <a href="#" onclick="Element.toggle('trackerselect')"><%= l(:label_options) %></a>
20 <%= toggle_link l(:label_options), "trackerselect" %>
21 21 <div id="trackerselect" class="rightbox overlay" style="width:140px; display: none;">
22 22 <p><strong><%=l(:label_tracker_plural)%></strong></p>
23 23 <% @trackers.each do |tracker| %>
24 24 <%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
25 25 <%= tracker.name %><br />
26 26 <% end %>
27 27 <% if @project.children.any? %>
28 28 <p><strong><%=l(:label_subproject_plural)%></strong></p>
29 29 <%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%= l(:general_text_Yes) %>
30 30 <% end %>
31 31 <p><center><%= submit_tag l(:button_apply), :class => 'button-small' %></center></p>
32 32 </div>
33 33 </td>
34 34 <td align="right">
35 35 <%= if @zoom < 4
36 36 link_to image_tag('zoom_in.png'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]}
37 37 else
38 38 image_tag 'zoom_in_g.png'
39 39 end %>
40 40 <%= if @zoom > 1
41 41 link_to image_tag('zoom_out.png'),{:zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]}
42 42 else
43 43 image_tag 'zoom_out_g.png'
44 44 end %>
45 45 </td>
46 46 </tr>
47 47 </table>
48 48 <% end %>
49 49
50 50 <% zoom = 1
51 51 @zoom.times { zoom = zoom * 2 }
52 52
53 53 subject_width = 260
54 54 header_heigth = 18
55 55
56 56 headers_height = header_heigth
57 57 show_weeks = false
58 58 show_days = false
59 59
60 60 if @zoom >1
61 61 show_weeks = true
62 62 headers_height = 2*header_heigth
63 63 if @zoom > 2
64 64 show_days = true
65 65 headers_height = 3*header_heigth
66 66 end
67 67 end
68 68
69 69 g_width = (@date_to - @date_from + 1)*zoom
70 70 g_height = [(20 * @events.length + 6)+150, 206].max
71 71 t_height = g_height + headers_height
72 72 %>
73 73
74 74 <table width="100%" style="border:0; border-collapse: collapse;">
75 75 <tr>
76 76 <td style="width:260px;">
77 77
78 78 <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
79 79 <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
80 80 <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
81 81 <%
82 82 #
83 83 # Tasks subjects
84 84 #
85 85 top = headers_height + 8
86 86 @events.each do |i| %>
87 87 <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>
88 88 <% if i.is_a? Issue %>
89 89 <%= link_to_issue i %>:
90 90 <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %>
91 91 <% else %>
92 92 <strong><%= "#{l(:label_version)}: #{i.name}" %></strong>
93 93 <% end %>
94 94 </small></div>
95 95 <% top = top + 20
96 96 end %>
97 97 </div>
98 98 </td>
99 99 <td>
100 100
101 101 <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
102 102 <div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
103 103 <%
104 104 #
105 105 # Months headers
106 106 #
107 107 month_f = @date_from
108 108 left = 0
109 109 height = (show_weeks ? header_heigth : header_heigth + g_height)
110 110 @months.times do
111 111 width = ((month_f >> 1) - month_f) * zoom - 1
112 112 %>
113 113 <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
114 114 <%= link_to "#{month_f.year}-#{month_f.month}", { :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }, :title => "#{month_name(month_f.month)} #{month_f.year}"%>
115 115 </div>
116 116 <%
117 117 left = left + width + 1
118 118 month_f = month_f >> 1
119 119 end %>
120 120
121 121 <%
122 122 #
123 123 # Weeks headers
124 124 #
125 125 if show_weeks
126 126 left = 0
127 127 height = (show_days ? header_heigth-1 : header_heigth-1 + g_height)
128 128 if @date_from.cwday == 1
129 129 # @date_from is monday
130 130 week_f = @date_from
131 131 else
132 132 # find next monday after @date_from
133 133 week_f = @date_from + (7 - @date_from.cwday + 1)
134 134 width = (7 - @date_from.cwday + 1) * zoom-1
135 135 %>
136 136 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">&nbsp;</div>
137 137 <%
138 138 left = left + width+1
139 139 end %>
140 140 <%
141 141 while week_f <= @date_to
142 142 width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1
143 143 %>
144 144 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
145 145 <small><%= week_f.cweek if width >= 16 %></small>
146 146 </div>
147 147 <%
148 148 left = left + width+1
149 149 week_f = week_f+7
150 150 end
151 151 end %>
152 152
153 153 <%
154 154 #
155 155 # Days headers
156 156 #
157 157 if show_days
158 158 left = 0
159 159 height = g_height + header_heigth - 1
160 160 wday = @date_from.cwday
161 161 (@date_to - @date_from + 1).to_i.times do
162 162 width = zoom - 1
163 163 %>
164 164 <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
165 165 <%= day_name(wday)[0,1] %>
166 166 </div>
167 167 <%
168 168 left = left + width+1
169 169 wday = wday + 1
170 170 wday = 1 if wday > 7
171 171 end
172 172 end %>
173 173
174 174 <%
175 175 #
176 176 # Today red line
177 177 #
178 178 if Date.today >= @date_from and Date.today <= @date_to %>
179 179 <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;">&nbsp;</div>
180 180 <% end %>
181 181
182 182 <%
183 183 #
184 184 # Tasks
185 185 #
186 186 top = headers_height + 10
187 187 @events.each do |i|
188 188 if i.is_a? Issue
189 189 i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from )
190 190 i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to )
191 191
192 192 i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
193 193 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
194 194 i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date )
195 195
196 196 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
197 197
198 198 i_left = ((i_start_date - @date_from)*zoom).floor
199 199 i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders)
200 200 d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width
201 201 l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
202 202 %>
203 203 <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo">&nbsp;</div>
204 204 <% if l_width > 0 %>
205 205 <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late">&nbsp;</div>
206 206 <% end %>
207 207 <% if d_width > 0 %>
208 208 <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done">&nbsp;</div>
209 209 <% end %>
210 210 <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task">
211 211 <%= i.status.name %>
212 212 <%= (i.done_ratio).to_i %>%
213 213 </div>
214 214 <% # === tooltip === %>
215 215 <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;">
216 216 <span class="tip">
217 217 <%= render :partial => "issues/tooltip", :locals => { :issue => i }%>
218 218 </span></div>
219 219 <% else
220 220 i_left = ((i.start_date - @date_from)*zoom).floor
221 221 %>
222 222 <div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone">&nbsp;</div>
223 223 <div style="top:<%= top %>px;left:<%= i_left + 12 %>px;background:#fff;" class="task">
224 224 <strong><%= i.name %></strong>
225 225 </div>
226 226 <% end %>
227 227 <% top = top + 20
228 228 end %>
229 229 </div>
230 230 </td>
231 231 </tr>
232 232 </table>
233 233
234 234 <table width="100%">
235 235 <tr>
236 236 <td align="left"><%= link_to ('&#171; ' + l(:label_previous)), :year => (@date_from << @months).year, :month => (@date_from << @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td>
237 237 <td align="right"><%= link_to (l(:label_next) + ' &#187;'), :year => (@date_from >> @months).year, :month => (@date_from >> @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td>
238 238 </tr>
239 239 </table> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now