|
|
|
@@ -22,6 +22,7 @@ require 'cgi'
|
|
|
|
|
|
|
|
|
|
module ApplicationHelper
|
|
|
|
|
include Redmine::WikiFormatting::Macros::Definitions
|
|
|
|
|
include Redmine::I18n
|
|
|
|
|
include GravatarHelper::PublicMethods
|
|
|
|
|
|
|
|
|
|
extend Forwardable
|
|
|
|
@@ -89,26 +90,9 @@ module ApplicationHelper
|
|
|
|
|
html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
|
|
|
|
|
link_to name, {}, html_options
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_date(date)
|
|
|
|
|
return nil unless date
|
|
|
|
|
# "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
|
|
|
|
|
@date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
|
|
|
|
|
date.strftime(@date_format)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_time(time, include_date = true)
|
|
|
|
|
return nil unless time
|
|
|
|
|
time = time.to_time if time.is_a?(String)
|
|
|
|
|
zone = User.current.time_zone
|
|
|
|
|
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
|
|
|
|
|
@date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
|
|
|
|
|
@time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
|
|
|
|
|
include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_activity_title(text)
|
|
|
|
|
h(truncate_single_line(text, 100))
|
|
|
|
|
h(truncate_single_line(text, :length => 100))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_activity_day(date)
|
|
|
|
@@ -116,14 +100,7 @@ module ApplicationHelper
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def format_activity_description(text)
|
|
|
|
|
h(truncate(text.to_s, 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def distance_of_date_in_words(from_date, to_date = 0)
|
|
|
|
|
from_date = from_date.to_date if from_date.respond_to?(:to_date)
|
|
|
|
|
to_date = to_date.to_date if to_date.respond_to?(:to_date)
|
|
|
|
|
distance_in_days = (to_date - from_date).abs
|
|
|
|
|
lwr(:actionview_datehelper_time_in_words_day, distance_in_days)
|
|
|
|
|
h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')).gsub(/[\r\n]+/, "<br />")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def due_date_distance_in_words(date)
|
|
|
|
@@ -235,20 +212,7 @@ module ApplicationHelper
|
|
|
|
|
{:controller => 'projects', :action => 'activity', :id => @project, :from => created.to_date},
|
|
|
|
|
:title => format_time(created))
|
|
|
|
|
author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
|
|
|
|
|
l(options[:label] || :label_added_time_by, author_tag, time_tag)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def l_or_humanize(s, options={})
|
|
|
|
|
k = "#{options[:prefix]}#{s}".to_sym
|
|
|
|
|
l_has_string?(k) ? l(k) : s.to_s.humanize
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def day_name(day)
|
|
|
|
|
l(:general_day_names).split(',')[day-1]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def month_name(month)
|
|
|
|
|
l(:actionview_datehelper_select_month_names).split(',')[month-1]
|
|
|
|
|
l(options[:label] || :label_added_time_by, :author => author_tag, :age => time_tag)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def syntax_highlight(name, content)
|
|
|
|
@@ -308,9 +272,9 @@ module ApplicationHelper
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def other_formats_links(&block)
|
|
|
|
|
concat('<p class="other-formats">' + l(:label_export_to), block.binding)
|
|
|
|
|
concat('<p class="other-formats">' + l(:label_export_to))
|
|
|
|
|
yield Redmine::Views::OtherFormatsBuilder.new(self)
|
|
|
|
|
concat('</p>', block.binding)
|
|
|
|
|
concat('</p>')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def page_header_title
|
|
|
|
@@ -479,7 +443,7 @@ module ApplicationHelper
|
|
|
|
|
if project && (changeset = project.changesets.find_by_revision(oid))
|
|
|
|
|
link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
|
|
|
|
|
:class => 'changeset',
|
|
|
|
|
:title => truncate_single_line(changeset.comments, 100))
|
|
|
|
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
|
|
|
|
end
|
|
|
|
|
elsif sep == '#'
|
|
|
|
|
oid = oid.to_i
|
|
|
|
@@ -488,7 +452,7 @@ module ApplicationHelper
|
|
|
|
|
if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
|
|
|
|
|
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
|
|
|
|
|
:class => (issue.closed? ? 'issue closed' : 'issue'),
|
|
|
|
|
:title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
|
|
|
|
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
|
|
|
|
link = content_tag('del', link) if issue.closed?
|
|
|
|
|
end
|
|
|
|
|
when 'document'
|
|
|
|
@@ -503,7 +467,7 @@ module ApplicationHelper
|
|
|
|
|
end
|
|
|
|
|
when 'message'
|
|
|
|
|
if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
|
|
|
|
|
link = link_to h(truncate(message.subject, 60)), {:only_path => only_path,
|
|
|
|
|
link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path,
|
|
|
|
|
:controller => 'messages',
|
|
|
|
|
:action => 'show',
|
|
|
|
|
:board_id => message.board,
|
|
|
|
@@ -530,7 +494,7 @@ module ApplicationHelper
|
|
|
|
|
if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
|
|
|
|
|
link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
|
|
|
|
|
:class => 'changeset',
|
|
|
|
|
:title => truncate_single_line(changeset.comments, 100)
|
|
|
|
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
|
|
|
|
end
|
|
|
|
|
when 'source', 'export'
|
|
|
|
|
if project && project.repository
|
|
|
|
@@ -565,46 +529,9 @@ module ApplicationHelper
|
|
|
|
|
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def error_messages_for(object_name, options = {})
|
|
|
|
|
options = options.symbolize_keys
|
|
|
|
|
object = instance_variable_get("@#{object_name}")
|
|
|
|
|
if object && !object.errors.empty?
|
|
|
|
|
# build full_messages here with controller current language
|
|
|
|
|
full_messages = []
|
|
|
|
|
object.errors.each do |attr, msg|
|
|
|
|
|
next if msg.nil?
|
|
|
|
|
msg = [msg] unless msg.is_a?(Array)
|
|
|
|
|
if attr == "base"
|
|
|
|
|
full_messages << l(*msg)
|
|
|
|
|
else
|
|
|
|
|
full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(*msg) unless attr == "custom_values"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# retrieve custom values error messages
|
|
|
|
|
if object.errors[:custom_values]
|
|
|
|
|
object.custom_values.each do |v|
|
|
|
|
|
v.errors.each do |attr, msg|
|
|
|
|
|
next if msg.nil?
|
|
|
|
|
msg = [msg] unless msg.is_a?(Array)
|
|
|
|
|
full_messages << "« " + v.custom_field.name + " » " + l(*msg)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
content_tag("div",
|
|
|
|
|
content_tag(
|
|
|
|
|
options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
|
|
|
|
|
) +
|
|
|
|
|
content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
|
|
|
|
|
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
""
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def lang_options_for_select(blank=true)
|
|
|
|
|
(blank ? [["(auto)", ""]] : []) +
|
|
|
|
|
GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
|
|
|
|
|
valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def label_tag_for(name, option_tags = nil, options = {})
|
|
|
|
|