2011-11-13 17:56:20 +04:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
2010-11-06 20:47:27 +03:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2007-03-12 20:59:02 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2008-11-07 17:35:18 +03:00
|
|
|
#
|
2007-03-12 20:59:02 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2008-11-07 17:35:18 +03:00
|
|
|
#
|
2007-03-12 20:59:02 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2008-10-27 14:08:29 +03:00
|
|
|
require 'forwardable'
|
2008-12-12 19:01:35 +03:00
|
|
|
require 'cgi'
|
2008-06-09 22:40:59 +04:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
module ApplicationHelper
|
2007-11-12 17:36:33 +03:00
|
|
|
include Redmine::WikiFormatting::Macros::Definitions
|
2009-02-21 14:04:50 +03:00
|
|
|
include Redmine::I18n
|
2008-11-09 17:52:16 +03:00
|
|
|
include GravatarHelper::PublicMethods
|
2012-12-17 22:21:24 +04:00
|
|
|
include Redmine::Pagination::Helper
|
2007-03-12 20:59:02 +03:00
|
|
|
|
2008-10-27 14:08:29 +03:00
|
|
|
extend Forwardable
|
|
|
|
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
# Return true if user is authorized for controller/action, otherwise false
|
2007-08-29 20:52:35 +04:00
|
|
|
def authorize_for(controller, action)
|
|
|
|
User.current.allowed_to?({:controller => controller, :action => action}, @project)
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
# Display a link if user is authorized
|
2010-09-06 04:26:08 +04:00
|
|
|
#
|
|
|
|
# @param [String] name Anchor text (passed to link_to)
|
2010-10-16 03:11:00 +04:00
|
|
|
# @param [Hash] options Hash params. This will checked by authorize_for to see if the user is authorized
|
2010-09-06 04:26:08 +04:00
|
|
|
# @param [optional, Hash] html_options Options passed to link_to
|
|
|
|
# @param [optional, Hash] parameters_for_method_reference Extra parameters for link_to
|
2007-03-12 20:59:02 +03:00
|
|
|
def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
|
2010-10-16 03:11:00 +04:00
|
|
|
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
|
2008-08-28 22:56:47 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2009-11-11 13:48:54 +03:00
|
|
|
# Displays a link to user's account page if active
|
2008-12-07 16:12:19 +03:00
|
|
|
def link_to_user(user, options={})
|
2009-09-12 12:36:46 +04:00
|
|
|
if user.is_a?(User)
|
2009-11-11 13:48:54 +03:00
|
|
|
name = h(user.name(options[:format]))
|
2012-10-18 21:08:42 +04:00
|
|
|
if user.active? || (User.current.admin? && user.logged?)
|
2012-10-18 21:10:00 +04:00
|
|
|
link_to name, user_path(user), :class => user.css_classes
|
2009-11-11 13:48:54 +03:00
|
|
|
else
|
|
|
|
name
|
|
|
|
end
|
2009-09-12 12:36:46 +04:00
|
|
|
else
|
2009-11-11 13:48:54 +03:00
|
|
|
h(user.to_s)
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2009-11-14 15:53:50 +03:00
|
|
|
# Displays a link to +issue+ with its subject.
|
|
|
|
# Examples:
|
2011-05-18 06:46:24 +04:00
|
|
|
#
|
2009-11-14 15:53:50 +03:00
|
|
|
# link_to_issue(issue) # => Defect #6: This is the subject
|
|
|
|
# link_to_issue(issue, :truncate => 6) # => Defect #6: This i...
|
|
|
|
# link_to_issue(issue, :subject => false) # => Defect #6
|
2009-12-12 18:33:31 +03:00
|
|
|
# link_to_issue(issue, :project => true) # => Foo - Defect #6
|
2012-09-29 16:57:38 +04:00
|
|
|
# link_to_issue(issue, :subject => false, :tracker => false) # => #6
|
2009-11-14 15:53:50 +03:00
|
|
|
#
|
2008-03-16 15:21:54 +03:00
|
|
|
def link_to_issue(issue, options={})
|
2009-11-14 15:53:50 +03:00
|
|
|
title = nil
|
|
|
|
subject = nil
|
2012-09-29 16:57:38 +04:00
|
|
|
text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}"
|
2009-11-14 15:53:50 +03:00
|
|
|
if options[:subject] == false
|
|
|
|
title = truncate(issue.subject, :length => 60)
|
|
|
|
else
|
|
|
|
subject = issue.subject
|
|
|
|
if options[:truncate]
|
|
|
|
subject = truncate(subject, :length => options[:truncate])
|
|
|
|
end
|
|
|
|
end
|
2012-10-18 21:12:22 +04:00
|
|
|
s = link_to text, issue_path(issue), :class => issue.css_classes, :title => title
|
2012-01-02 21:40:03 +04:00
|
|
|
s << h(": #{subject}") if subject
|
|
|
|
s = h("#{issue.project} - ") + s if options[:project]
|
2009-11-14 15:53:50 +03:00
|
|
|
s
|
2007-04-07 22:30:01 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-07-22 21:55:19 +04:00
|
|
|
# Generates a link to an attachment.
|
|
|
|
# Options:
|
|
|
|
# * :text - Link text (default to attachment filename)
|
|
|
|
# * :download - Force download (default: false)
|
|
|
|
def link_to_attachment(attachment, options={})
|
|
|
|
text = options.delete(:text) || attachment.filename
|
2013-01-15 00:44:48 +04:00
|
|
|
route_method = options.delete(:download) ? :download_named_attachment_path : :named_attachment_path
|
|
|
|
html_options = options.slice!(:only_path)
|
|
|
|
url = send(route_method, attachment, attachment.filename, options)
|
|
|
|
link_to text, url, html_options
|
2008-07-22 21:55:19 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2009-12-23 02:23:54 +03:00
|
|
|
# Generates a link to a SCM revision
|
|
|
|
# Options:
|
|
|
|
# * :text - Link text (default to the formatted revision)
|
2012-01-15 22:19:19 +04:00
|
|
|
def link_to_revision(revision, repository, options={})
|
|
|
|
if repository.is_a?(Project)
|
|
|
|
repository = repository.repository
|
|
|
|
end
|
2009-12-23 02:23:54 +03:00
|
|
|
text = options.delete(:text) || format_revision(revision)
|
2011-01-02 12:45:05 +03:00
|
|
|
rev = revision.respond_to?(:identifier) ? revision.identifier : revision
|
2011-12-03 10:14:19 +04:00
|
|
|
link_to(
|
|
|
|
h(text),
|
2012-01-15 22:19:19 +04:00
|
|
|
{:controller => 'repositories', :action => 'revision', :id => repository.project, :repository_id => repository.identifier_param, :rev => rev},
|
2011-12-03 10:14:19 +04:00
|
|
|
:title => l(:label_revision_id, format_revision(revision))
|
|
|
|
)
|
2009-12-23 02:23:54 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2011-01-23 20:02:10 +03:00
|
|
|
# Generates a link to a message
|
|
|
|
def link_to_message(message, options={}, html_options = nil)
|
|
|
|
link_to(
|
2013-01-14 23:22:09 +04:00
|
|
|
truncate(message.subject, :length => 60),
|
|
|
|
board_message_path(message.board_id, message.parent_id || message.id, {
|
2011-01-23 20:02:10 +03:00
|
|
|
:r => (message.parent_id && message.id),
|
|
|
|
:anchor => (message.parent_id ? "message-#{message.id}" : nil)
|
2013-01-14 23:22:09 +04:00
|
|
|
}.merge(options)),
|
2011-01-23 20:02:10 +03:00
|
|
|
html_options
|
|
|
|
)
|
|
|
|
end
|
2009-12-23 02:23:54 +03:00
|
|
|
|
2010-08-08 11:07:20 +04:00
|
|
|
# Generates a link to a project if active
|
|
|
|
# Examples:
|
2011-05-18 06:46:24 +04:00
|
|
|
#
|
2010-08-08 11:07:20 +04:00
|
|
|
# link_to_project(project) # => link to the specified project overview
|
|
|
|
# link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options
|
|
|
|
# link_to_project(project, {}, :class => "project") # => html options with default url (project overview)
|
|
|
|
#
|
|
|
|
def link_to_project(project, options={}, html_options = nil)
|
2012-06-25 21:49:35 +04:00
|
|
|
if project.archived?
|
2013-01-14 23:16:29 +04:00
|
|
|
h(project.name)
|
|
|
|
elsif options.key?(:action)
|
|
|
|
ActiveSupport::Deprecation.warn "#link_to_project with :action option is deprecated and will be removed in Redmine 3.0."
|
2012-10-18 22:11:42 +04:00
|
|
|
url = {:controller => 'projects', :action => 'show', :id => project}.merge(options)
|
2013-01-14 23:16:29 +04:00
|
|
|
link_to project.name, url, html_options
|
|
|
|
else
|
|
|
|
link_to project.name, project_path(project, options), html_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Generates a link to a project settings if active
|
|
|
|
def link_to_project_settings(project, options={}, html_options=nil)
|
|
|
|
if project.active?
|
|
|
|
link_to project.name, settings_project_path(project, options), html_options
|
|
|
|
elsif project.archived?
|
|
|
|
h(project.name)
|
|
|
|
else
|
|
|
|
link_to project.name, project_path(project, options), html_options
|
2010-08-08 11:07:20 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-23 22:45:14 +04:00
|
|
|
def wiki_page_path(page, options={})
|
|
|
|
url_for({:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}.merge(options))
|
|
|
|
end
|
|
|
|
|
2012-07-07 17:48:07 +04:00
|
|
|
def thumbnail_tag(attachment)
|
2013-01-15 00:51:49 +04:00
|
|
|
link_to image_tag(thumbnail_path(attachment)),
|
|
|
|
named_attachment_path(attachment, attachment.filename),
|
2012-07-07 17:48:07 +04:00
|
|
|
:title => attachment.filename
|
|
|
|
end
|
|
|
|
|
2007-04-07 22:56:12 +04:00
|
|
|
def toggle_link(name, id, options={})
|
2012-07-22 17:29:26 +04:00
|
|
|
onclick = "$('##{id}').toggle(); "
|
|
|
|
onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ")
|
2007-04-07 22:56:12 +04:00
|
|
|
onclick << "return false;"
|
|
|
|
link_to(name, "#", :onclick => onclick)
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
def image_to_function(name, function, html_options = {})
|
|
|
|
html_options.symbolize_keys!
|
2008-11-07 17:35:18 +03:00
|
|
|
tag(:input, html_options.merge({
|
|
|
|
:type => "image", :src => image_path(name),
|
|
|
|
:onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
|
2007-03-12 20:59:02 +03:00
|
|
|
}))
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-11-30 14:18:22 +03:00
|
|
|
def format_activity_title(text)
|
2009-02-21 14:04:50 +03:00
|
|
|
h(truncate_single_line(text, :length => 100))
|
2008-11-30 14:18:22 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2008-11-30 14:18:22 +03:00
|
|
|
def format_activity_day(date)
|
2012-05-26 16:07:56 +04:00
|
|
|
date == User.current.today ? l(:label_today).titleize : format_date(date)
|
2008-11-30 14:18:22 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2008-11-30 14:18:22 +03:00
|
|
|
def format_activity_description(text)
|
2011-12-03 10:15:55 +04:00
|
|
|
h(truncate(text.to_s, :length => 120).gsub(%r{[\r\n]*<(pre|code)>.*$}m, '...')
|
|
|
|
).gsub(/[\r\n]+/, "<br />").html_safe
|
2008-09-20 18:07:52 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2009-12-06 13:28:20 +03:00
|
|
|
def format_version_name(version)
|
|
|
|
if version.project == @project
|
2013-02-17 14:16:21 +04:00
|
|
|
h(version)
|
2009-12-06 13:28:20 +03:00
|
|
|
else
|
|
|
|
h("#{version.project} - #{version}")
|
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2008-09-20 18:07:52 +04:00
|
|
|
def due_date_distance_in_words(date)
|
|
|
|
if date
|
|
|
|
l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
|
|
|
|
end
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2012-08-10 21:09:48 +04:00
|
|
|
# Renders a tree of projects as a nested set of unordered lists
|
|
|
|
# The given collection may be a subset of the whole project tree
|
|
|
|
# (eg. some intermediate nodes are private and can not be seen)
|
|
|
|
def render_project_nested_lists(projects)
|
|
|
|
s = ''
|
|
|
|
if projects.any?
|
|
|
|
ancestors = []
|
|
|
|
original_project = @project
|
2012-08-10 22:41:24 +04:00
|
|
|
projects.sort_by(&:lft).each do |project|
|
2012-08-10 21:09:48 +04:00
|
|
|
# set the project environment to please macros.
|
|
|
|
@project = project
|
|
|
|
if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
|
|
|
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
|
|
|
|
else
|
|
|
|
ancestors.pop
|
|
|
|
s << "</li>"
|
|
|
|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
|
|
|
ancestors.pop
|
|
|
|
s << "</ul></li>\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
classes = (ancestors.empty? ? 'root' : 'child')
|
|
|
|
s << "<li class='#{classes}'><div class='#{classes}'>"
|
|
|
|
s << h(block_given? ? yield(project) : project.name)
|
|
|
|
s << "</div>\n"
|
|
|
|
ancestors << project
|
|
|
|
end
|
|
|
|
s << ("</li></ul>\n" * ancestors.size)
|
|
|
|
@project = original_project
|
|
|
|
end
|
|
|
|
s.html_safe
|
|
|
|
end
|
|
|
|
|
2011-03-12 21:27:02 +03:00
|
|
|
def render_page_hierarchy(pages, node=nil, options={})
|
2008-11-22 14:44:07 +03:00
|
|
|
content = ''
|
|
|
|
if pages[node]
|
|
|
|
content << "<ul class=\"pages-hierarchy\">\n"
|
|
|
|
pages[node].each do |page|
|
|
|
|
content << "<li>"
|
2012-10-21 22:46:26 +04:00
|
|
|
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title, :version => nil},
|
2011-03-12 21:27:02 +03:00
|
|
|
:title => (options[:timestamp] && page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
|
|
|
|
content << "\n" + render_page_hierarchy(pages, page.id, options) if pages[page.id]
|
2008-11-22 14:44:07 +03:00
|
|
|
content << "</li>\n"
|
|
|
|
end
|
|
|
|
content << "</ul>\n"
|
|
|
|
end
|
2011-10-06 15:03:29 +04:00
|
|
|
content.html_safe
|
2008-11-22 14:44:07 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-01-03 17:11:44 +03:00
|
|
|
# Renders flash messages
|
|
|
|
def render_flash_messages
|
|
|
|
s = ''
|
|
|
|
flash.each do |k,v|
|
2012-04-29 12:25:50 +04:00
|
|
|
s << content_tag('div', v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
|
2009-01-03 17:11:44 +03:00
|
|
|
end
|
2011-08-20 14:51:38 +04:00
|
|
|
s.html_safe
|
2009-01-03 17:11:44 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-09-12 13:13:13 +04:00
|
|
|
# Renders tabs and their content
|
|
|
|
def render_tabs(tabs)
|
|
|
|
if tabs.any?
|
|
|
|
render :partial => 'common/tabs', :locals => {:tabs => tabs}
|
|
|
|
else
|
|
|
|
content_tag 'p', l(:label_no_data), :class => "nodata"
|
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-01-24 14:31:15 +03:00
|
|
|
# Renders the project quick-jump box
|
|
|
|
def render_project_jump_box
|
2011-04-14 20:32:03 +04:00
|
|
|
return unless User.current.logged?
|
2012-06-25 21:49:35 +04:00
|
|
|
projects = User.current.memberships.collect(&:project).compact.select(&:active?).uniq
|
2009-01-24 14:31:15 +03:00
|
|
|
if projects.any?
|
2012-06-26 21:36:29 +04:00
|
|
|
options =
|
|
|
|
("<option value=''>#{ l(:label_jump_to_a_project) }</option>" +
|
|
|
|
'<option value="" disabled="disabled">---</option>').html_safe
|
|
|
|
|
|
|
|
options << project_tree_options_for_select(projects, :selected => @project) do |p|
|
|
|
|
{ :value => project_path(:id => p, :jump => current_menu_item) }
|
2009-01-24 14:31:15 +03:00
|
|
|
end
|
2012-06-26 21:36:29 +04:00
|
|
|
|
|
|
|
select_tag('project_quick_jump_box', options, :onchange => 'if (this.value != \'\') { window.location = this.value; }')
|
2009-01-24 14:31:15 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-01-24 14:31:15 +03:00
|
|
|
def project_tree_options_for_select(projects, options = {})
|
|
|
|
s = ''
|
|
|
|
project_tree(projects) do |project, level|
|
2012-06-26 21:36:29 +04:00
|
|
|
name_prefix = (level > 0 ? ' ' * 2 * level + '» ' : '').html_safe
|
2010-03-03 06:37:40 +03:00
|
|
|
tag_options = {:value => project.id}
|
|
|
|
if project == options[:selected] || (options[:selected].respond_to?(:include?) && options[:selected].include?(project))
|
|
|
|
tag_options[:selected] = 'selected'
|
|
|
|
else
|
|
|
|
tag_options[:selected] = nil
|
|
|
|
end
|
2009-01-24 14:31:15 +03:00
|
|
|
tag_options.merge!(yield(project)) if block_given?
|
|
|
|
s << content_tag('option', name_prefix + h(project), tag_options)
|
|
|
|
end
|
2011-08-20 14:52:52 +04:00
|
|
|
s.html_safe
|
2009-01-24 14:31:15 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-01-24 14:31:15 +03:00
|
|
|
# Yields the given block for each project with its level in the tree
|
2010-10-23 02:38:45 +04:00
|
|
|
#
|
|
|
|
# Wrapper for Project#project_tree
|
2009-01-24 14:31:15 +03:00
|
|
|
def project_tree(projects, &block)
|
2010-10-23 02:38:45 +04:00
|
|
|
Project.project_tree(projects, &block)
|
2009-01-24 14:31:15 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-09-12 12:36:46 +04:00
|
|
|
def principals_check_box_tags(name, principals)
|
|
|
|
s = ''
|
2013-01-23 21:44:28 +04:00
|
|
|
principals.each do |principal|
|
2013-02-10 20:41:26 +04:00
|
|
|
s << "<label>#{ check_box_tag name, principal.id, false, :id => nil } #{h principal}</label>\n"
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-08-20 14:53:50 +04:00
|
|
|
s.html_safe
|
2009-09-12 12:36:46 +04:00
|
|
|
end
|
2011-08-20 09:57:14 +04:00
|
|
|
|
2011-07-23 23:05:22 +04:00
|
|
|
# Returns a string for users/groups option tags
|
|
|
|
def principals_options_for_select(collection, selected=nil)
|
|
|
|
s = ''
|
2012-01-21 15:06:59 +04:00
|
|
|
if collection.include?(User.current)
|
2012-07-29 14:15:20 +04:00
|
|
|
s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
|
2012-01-21 15:06:59 +04:00
|
|
|
end
|
2011-07-23 23:05:22 +04:00
|
|
|
groups = ''
|
|
|
|
collection.sort.each do |element|
|
|
|
|
selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)
|
|
|
|
(element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
|
|
|
|
end
|
|
|
|
unless groups.empty?
|
|
|
|
s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
|
|
|
|
end
|
2012-04-21 05:44:38 +04:00
|
|
|
s.html_safe
|
2011-07-23 23:05:22 +04:00
|
|
|
end
|
2008-11-22 14:44:07 +03:00
|
|
|
|
2012-12-01 20:19:52 +04:00
|
|
|
# Options for the new membership projects combo-box
|
|
|
|
def options_for_membership_project_select(principal, projects)
|
|
|
|
options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---")
|
|
|
|
options << project_tree_options_for_select(projects) do |p|
|
2013-03-01 14:54:31 +04:00
|
|
|
{:disabled => principal.projects.to_a.include?(p)}
|
2012-12-01 20:19:52 +04:00
|
|
|
end
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2008-06-04 22:13:14 +04:00
|
|
|
# Truncates and returns the string as a single line
|
|
|
|
def truncate_single_line(string, *args)
|
2009-10-29 20:55:59 +03:00
|
|
|
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
|
2008-06-04 22:13:14 +04:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-03-18 23:02:17 +03:00
|
|
|
# Truncates at line break after 250 characters or options[:length]
|
|
|
|
def truncate_lines(string, options={})
|
|
|
|
length = options[:length] || 250
|
|
|
|
if string.to_s =~ /\A(.{#{length}}.*?)$/m
|
|
|
|
"#{$1}..."
|
|
|
|
else
|
|
|
|
string
|
|
|
|
end
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2012-01-08 21:14:17 +04:00
|
|
|
def anchor(text)
|
|
|
|
text.to_s.gsub(' ', '_')
|
|
|
|
end
|
|
|
|
|
2008-02-26 21:15:58 +03:00
|
|
|
def html_hours(text)
|
2011-08-20 14:54:18 +04:00
|
|
|
text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe
|
2008-02-26 21:15:58 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-12-06 14:21:10 +03:00
|
|
|
def authoring(created, author, options={})
|
2011-08-20 14:54:41 +04:00
|
|
|
l(options[:label] || :label_added_time_by, :author => link_to_user(author), :age => time_tag(created)).html_safe
|
2009-07-04 16:36:26 +04:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-07-04 16:36:26 +04:00
|
|
|
def time_tag(time)
|
|
|
|
text = distance_of_time_in_words(Time.now, time)
|
|
|
|
if @project
|
2012-05-26 16:07:56 +04:00
|
|
|
link_to(text, {:controller => 'activities', :action => 'index', :id => @project, :from => User.current.time_to_date(time)}, :title => format_time(time))
|
2009-07-04 16:36:26 +04:00
|
|
|
else
|
|
|
|
content_tag('acronym', text, :title => format_time(time))
|
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
|
|
|
|
2012-02-25 10:01:48 +04:00
|
|
|
def syntax_highlight_lines(name, content)
|
|
|
|
lines = []
|
|
|
|
syntax_highlight(name, content).each_line { |line| lines << line }
|
|
|
|
lines
|
|
|
|
end
|
|
|
|
|
2008-06-09 22:40:59 +04:00
|
|
|
def syntax_highlight(name, content)
|
2010-03-14 15:57:08 +03:00
|
|
|
Redmine::SyntaxHighlighting.highlight_by_filename(content, name)
|
2008-06-09 22:40:59 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-07-06 16:43:51 +04:00
|
|
|
def to_path_param(path)
|
2012-05-02 17:19:16 +04:00
|
|
|
str = path.to_s.split(%r{[/\\]}).select{|p| !p.blank?}.join("/")
|
|
|
|
str.blank? ? nil : str
|
2008-07-06 16:43:51 +04:00
|
|
|
end
|
|
|
|
|
2011-11-23 01:32:45 +04:00
|
|
|
def reorder_links(name, url, method = :post)
|
2011-10-06 15:04:32 +04:00
|
|
|
link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)),
|
|
|
|
url.merge({"#{name}[move_to]" => 'highest'}),
|
2011-11-23 01:32:45 +04:00
|
|
|
:method => method, :title => l(:label_sort_highest)) +
|
2011-10-06 15:04:32 +04:00
|
|
|
link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)),
|
|
|
|
url.merge({"#{name}[move_to]" => 'higher'}),
|
2011-11-23 01:32:45 +04:00
|
|
|
:method => method, :title => l(:label_sort_higher)) +
|
2011-10-06 15:04:32 +04:00
|
|
|
link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)),
|
|
|
|
url.merge({"#{name}[move_to]" => 'lower'}),
|
2011-11-23 01:32:45 +04:00
|
|
|
:method => method, :title => l(:label_sort_lower)) +
|
2011-10-06 15:04:32 +04:00
|
|
|
link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)),
|
|
|
|
url.merge({"#{name}[move_to]" => 'lowest'}),
|
2011-11-23 01:32:45 +04:00
|
|
|
:method => method, :title => l(:label_sort_lowest))
|
2009-02-26 12:21:41 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-03-27 21:41:42 +03:00
|
|
|
def breadcrumb(*args)
|
2008-07-26 15:46:24 +04:00
|
|
|
elements = args.flatten
|
2011-08-21 15:11:25 +04:00
|
|
|
elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
|
2008-03-27 21:41:42 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-01-29 16:53:17 +03:00
|
|
|
def other_formats_links(&block)
|
2011-11-23 00:57:20 +04:00
|
|
|
concat('<p class="other-formats">'.html_safe + l(:label_export_to))
|
2009-01-29 16:53:17 +03:00
|
|
|
yield Redmine::Views::OtherFormatsBuilder.new(self)
|
2011-11-23 00:57:20 +04:00
|
|
|
concat('</p>'.html_safe)
|
2009-01-29 16:53:17 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2009-02-20 21:34:57 +03:00
|
|
|
def page_header_title
|
|
|
|
if @project.nil? || @project.new_record?
|
|
|
|
h(Setting.app_title)
|
|
|
|
else
|
|
|
|
b = []
|
2011-04-14 20:29:51 +04:00
|
|
|
ancestors = (@project.root? ? [] : @project.ancestors.visible.all)
|
2009-02-20 21:34:57 +03:00
|
|
|
if ancestors.any?
|
|
|
|
root = ancestors.shift
|
2010-08-08 11:07:20 +04:00
|
|
|
b << link_to_project(root, {:jump => current_menu_item}, :class => 'root')
|
2009-02-20 21:34:57 +03:00
|
|
|
if ancestors.size > 2
|
2011-10-06 15:02:24 +04:00
|
|
|
b << "\xe2\x80\xa6"
|
2009-02-20 21:34:57 +03:00
|
|
|
ancestors = ancestors[-2, 2]
|
|
|
|
end
|
2010-08-08 11:07:20 +04:00
|
|
|
b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') }
|
2009-02-20 21:34:57 +03:00
|
|
|
end
|
|
|
|
b << h(@project)
|
2011-10-06 19:02:14 +04:00
|
|
|
b.join(" \xc2\xbb ").html_safe
|
2009-02-20 21:34:57 +03:00
|
|
|
end
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-01-03 01:41:53 +03:00
|
|
|
def html_title(*args)
|
|
|
|
if args.empty?
|
2011-11-19 15:43:11 +04:00
|
|
|
title = @html_title || []
|
2011-09-16 05:50:33 +04:00
|
|
|
title << @project.name if @project
|
2011-11-19 15:43:11 +04:00
|
|
|
title << Setting.app_title unless Setting.app_title == title.last
|
2009-10-24 16:33:08 +04:00
|
|
|
title.select {|t| !t.blank? }.join(' - ')
|
2008-01-03 01:41:53 +03:00
|
|
|
else
|
|
|
|
@html_title ||= []
|
|
|
|
@html_title += args
|
|
|
|
end
|
2007-09-08 00:52:45 +04:00
|
|
|
end
|
2007-10-05 22:05:41 +04:00
|
|
|
|
2010-08-04 05:17:45 +04:00
|
|
|
# Returns the theme, controller name, and action as css classes for the
|
|
|
|
# HTML body.
|
|
|
|
def body_css_classes
|
|
|
|
css = []
|
|
|
|
if theme = Redmine::Themes.theme(Setting.ui_theme)
|
|
|
|
css << 'theme-' + theme.name
|
|
|
|
end
|
|
|
|
|
2012-02-26 23:20:37 +04:00
|
|
|
css << 'controller-' + controller_name
|
|
|
|
css << 'action-' + action_name
|
2010-08-04 05:17:45 +04:00
|
|
|
css.join(' ')
|
|
|
|
end
|
|
|
|
|
2007-10-05 22:05:41 +04:00
|
|
|
def accesskey(s)
|
2013-05-01 17:13:53 +04:00
|
|
|
@used_accesskeys ||= []
|
|
|
|
key = Redmine::AccessKeys.key_for(s)
|
|
|
|
return nil if @used_accesskeys.include?(key)
|
|
|
|
@used_accesskeys << key
|
|
|
|
key
|
2007-10-05 22:05:41 +04:00
|
|
|
end
|
|
|
|
|
2007-11-12 17:36:33 +03:00
|
|
|
# Formats text according to system settings.
|
|
|
|
# 2 ways to call this method:
|
|
|
|
# * with a String: textilizable(text, options)
|
|
|
|
# * with an object and one of its attribute: textilizable(issue, :description, options)
|
|
|
|
def textilizable(*args)
|
|
|
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
|
|
case args.size
|
|
|
|
when 1
|
2008-07-26 16:54:54 +04:00
|
|
|
obj = options[:object]
|
2008-02-17 17:17:20 +03:00
|
|
|
text = args.shift
|
2007-11-12 17:36:33 +03:00
|
|
|
when 2
|
|
|
|
obj = args.shift
|
2010-02-06 13:40:21 +03:00
|
|
|
attr = args.shift
|
|
|
|
text = obj.send(attr).to_s
|
2007-11-12 17:36:33 +03:00
|
|
|
else
|
|
|
|
raise ArgumentError, 'invalid arguments to textilizable'
|
|
|
|
end
|
2008-02-17 17:17:20 +03:00
|
|
|
return '' if text.blank?
|
2010-03-15 22:37:01 +03:00
|
|
|
project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
|
|
|
|
only_path = options.delete(:only_path) == false ? false : true
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2012-08-17 18:46:55 +04:00
|
|
|
text = text.dup
|
|
|
|
macros = catch_macros(text)
|
2011-11-18 20:25:00 +04:00
|
|
|
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-12-29 21:21:22 +03:00
|
|
|
@parsed_headings = []
|
2012-02-14 12:09:23 +04:00
|
|
|
@heading_anchors = {}
|
2011-11-18 22:22:41 +04:00
|
|
|
@current_section = 0 if options[:edit_section_links]
|
2012-02-11 14:02:24 +04:00
|
|
|
|
|
|
|
parse_sections(text, project, obj, attr, only_path, options)
|
2012-08-17 18:46:55 +04:00
|
|
|
text = parse_non_pre_blocks(text, obj, macros) do |text|
|
|
|
|
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
|
2010-03-15 22:54:50 +03:00
|
|
|
send method_name, text, project, obj, attr, only_path, options
|
|
|
|
end
|
2010-03-15 22:37:01 +03:00
|
|
|
end
|
2012-02-11 14:02:24 +04:00
|
|
|
parse_headings(text, project, obj, attr, only_path, options)
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-12-29 21:21:22 +03:00
|
|
|
if @parsed_headings.any?
|
|
|
|
replace_toc(text, @parsed_headings)
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2011-12-18 02:15:36 +04:00
|
|
|
text.html_safe
|
2010-03-15 22:54:50 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2012-08-17 18:46:55 +04:00
|
|
|
def parse_non_pre_blocks(text, obj, macros)
|
2010-03-15 22:54:50 +03:00
|
|
|
s = StringScanner.new(text)
|
|
|
|
tags = []
|
|
|
|
parsed = ''
|
|
|
|
while !s.eos?
|
|
|
|
s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
|
|
|
|
text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
|
|
|
|
if tags.empty?
|
|
|
|
yield text
|
2012-08-17 18:46:55 +04:00
|
|
|
inject_macros(text, obj, macros) if macros.any?
|
|
|
|
else
|
|
|
|
inject_macros(text, obj, macros, false) if macros.any?
|
2010-03-15 22:54:50 +03:00
|
|
|
end
|
|
|
|
parsed << text
|
|
|
|
if tag
|
|
|
|
if closing
|
|
|
|
if tags.last == tag.downcase
|
|
|
|
tags.pop
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tags << tag.downcase
|
|
|
|
end
|
|
|
|
parsed << full_tag
|
|
|
|
end
|
|
|
|
end
|
2010-03-15 22:57:35 +03:00
|
|
|
# Close any non closing tags
|
|
|
|
while tag = tags.pop
|
|
|
|
parsed << "</#{tag}>"
|
|
|
|
end
|
2012-02-25 04:00:58 +04:00
|
|
|
parsed
|
2010-03-15 22:37:01 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-03-15 22:37:01 +03:00
|
|
|
def parse_inline_attachments(text, project, obj, attr, only_path, options)
|
2007-09-03 00:41:47 +04:00
|
|
|
# when using an image link, try to use an attachment, if possible
|
2013-01-11 01:40:04 +04:00
|
|
|
attachments = options[:attachments] || []
|
|
|
|
attachments += obj.attachments if obj.respond_to?(:attachments)
|
|
|
|
if attachments.present?
|
2011-11-23 09:30:53 +04:00
|
|
|
text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
|
2011-05-18 06:46:24 +04:00
|
|
|
filename, ext, alt, alttext = $1.downcase, $2, $3, $4
|
2007-09-03 00:41:47 +04:00
|
|
|
# search for the picture in attachments
|
2011-11-24 09:31:29 +04:00
|
|
|
if found = Attachment.latest_attach(attachments, filename)
|
2013-01-15 01:03:53 +04:00
|
|
|
image_url = download_named_attachment_path(found, found.filename, :only_path => only_path)
|
2009-12-27 13:52:02 +03:00
|
|
|
desc = found.description.to_s.gsub('"', '')
|
|
|
|
if !desc.blank? && alttext.blank?
|
|
|
|
alt = " title=\"#{desc}\" alt=\"#{desc}\""
|
|
|
|
end
|
2012-02-25 04:00:58 +04:00
|
|
|
"src=\"#{image_url}\"#{alt}"
|
2007-09-03 00:41:47 +04:00
|
|
|
else
|
2012-02-25 04:00:58 +04:00
|
|
|
m
|
2007-09-03 00:41:47 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-15 22:37:01 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2010-03-15 22:37:01 +03:00
|
|
|
# Wiki links
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
# [[mypage]]
|
|
|
|
# [[mypage|mytext]]
|
|
|
|
# wiki links can refer other project wikis, using project name or identifier:
|
|
|
|
# [[project:]] -> wiki starting page
|
|
|
|
# [[project:|mytext]]
|
|
|
|
# [[project:mypage]]
|
|
|
|
# [[project:mypage|mytext]]
|
|
|
|
def parse_wiki_links(text, project, obj, attr, only_path, options)
|
|
|
|
text.gsub!(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
|
2007-08-17 15:21:58 +04:00
|
|
|
link_project = project
|
2008-01-15 21:12:12 +03:00
|
|
|
esc, all, page, title = $1, $2, $3, $5
|
|
|
|
if esc.nil?
|
|
|
|
if page =~ /^([^\:]+)\:(.*)$/
|
2013-01-27 16:03:47 +04:00
|
|
|
identifier, page = $1, $2
|
|
|
|
link_project = Project.find_by_identifier(identifier) || Project.find_by_name(identifier)
|
|
|
|
title ||= identifier if page.blank?
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-01-15 21:12:12 +03:00
|
|
|
if link_project && link_project.wiki
|
2008-07-28 21:20:31 +04:00
|
|
|
# extract anchor
|
|
|
|
anchor = nil
|
|
|
|
if page =~ /^(.+?)\#(.+)$/
|
|
|
|
page, anchor = $1, $2
|
|
|
|
end
|
2011-10-02 21:25:29 +04:00
|
|
|
anchor = sanitize_anchor_name(anchor) if anchor.present?
|
2008-01-15 21:12:12 +03:00
|
|
|
# check if page exists
|
|
|
|
wiki_page = link_project.wiki.find_page(page)
|
2011-10-02 18:44:07 +04:00
|
|
|
url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
|
|
|
|
"##{anchor}"
|
|
|
|
else
|
|
|
|
case options[:wiki_links]
|
2011-10-02 19:32:34 +04:00
|
|
|
when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '')
|
2011-10-02 19:57:17 +04:00
|
|
|
when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
|
2010-03-15 22:37:01 +03:00
|
|
|
else
|
2010-10-29 01:25:38 +04:00
|
|
|
wiki_page_id = page.present? ? Wiki.titleize(page) : nil
|
2011-12-17 15:44:04 +04:00
|
|
|
parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
|
|
|
|
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
|
2012-10-21 22:46:26 +04:00
|
|
|
:id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent)
|
2010-03-15 22:37:01 +03:00
|
|
|
end
|
2011-10-02 18:44:07 +04:00
|
|
|
end
|
2011-11-24 23:47:36 +04:00
|
|
|
link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
|
2008-01-15 21:12:12 +03:00
|
|
|
else
|
|
|
|
# project or wiki doesn't exist
|
2012-02-25 04:00:58 +04:00
|
|
|
all
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
2007-09-08 00:07:54 +04:00
|
|
|
else
|
2012-02-25 04:00:58 +04:00
|
|
|
all
|
2007-09-08 00:07:54 +04:00
|
|
|
end
|
2007-08-15 21:31:01 +04:00
|
|
|
end
|
2010-03-15 22:37:01 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-03-15 22:37:01 +03:00
|
|
|
# Redmine links
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
# Issues:
|
|
|
|
# #52 -> Link to issue #52
|
|
|
|
# Changesets:
|
|
|
|
# r52 -> Link to revision 52
|
|
|
|
# commit:a85130f -> Link to scmid starting with a85130f
|
|
|
|
# Documents:
|
|
|
|
# document#17 -> Link to document with id 17
|
|
|
|
# document:Greetings -> Link to the document with title "Greetings"
|
|
|
|
# document:"Some document" -> Link to the document with title "Some document"
|
|
|
|
# Versions:
|
|
|
|
# version#3 -> Link to version with id 3
|
|
|
|
# version:1.0.0 -> Link to version named "1.0.0"
|
|
|
|
# version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
|
|
|
|
# Attachments:
|
|
|
|
# attachment:file.zip -> Link to the attachment of the current object named file.zip
|
|
|
|
# Source files:
|
|
|
|
# source:some/file -> Link to the file located at /some/file in the project's repository
|
|
|
|
# source:some/file@52 -> Link to the file's revision 52
|
|
|
|
# source:some/file#L120 -> Link to line 120 of the file
|
|
|
|
# source:some/file@52#L120 -> Link to line 120 of the file's revision 52
|
|
|
|
# export:some/file -> Force the download of the file
|
2011-01-23 19:12:38 +03:00
|
|
|
# Forum messages:
|
2010-03-15 22:37:01 +03:00
|
|
|
# message#1218 -> Link to message with id 1218
|
2011-01-23 19:12:38 +03:00
|
|
|
#
|
|
|
|
# Links can refer other objects from other projects, using project identifier:
|
|
|
|
# identifier:r52
|
|
|
|
# identifier:document:"Some document"
|
|
|
|
# identifier:version:1.0.0
|
|
|
|
# identifier:source:some/file
|
2013-01-23 00:40:39 +04:00
|
|
|
def parse_redmine_links(text, default_project, obj, attr, only_path, options)
|
2013-01-27 20:02:49 +04:00
|
|
|
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-_]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m|
|
2012-02-15 21:49:31 +04:00
|
|
|
leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $1, $2, $3, $4, $5, $10, $11, $8 || $12 || $18, $14 || $19, $15, $17
|
2007-09-03 00:41:47 +04:00
|
|
|
link = nil
|
2013-01-23 00:40:39 +04:00
|
|
|
project = default_project
|
2011-01-23 19:12:38 +03:00
|
|
|
if project_identifier
|
|
|
|
project = Project.visible.find_by_identifier(project_identifier)
|
|
|
|
end
|
2008-01-15 21:12:12 +03:00
|
|
|
if esc.nil?
|
|
|
|
if prefix.nil? && sep == 'r'
|
2012-01-22 18:23:10 +04:00
|
|
|
if project
|
|
|
|
repository = nil
|
|
|
|
if repo_identifier
|
|
|
|
repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
|
|
|
|
else
|
|
|
|
repository = project.repository
|
|
|
|
end
|
|
|
|
# project.changesets.visible raises an SQL error because of a double join on repositories
|
|
|
|
if repository && (changeset = Changeset.visible.find_by_repository_id_and_revision(repository.id, identifier))
|
|
|
|
link = link_to(h("#{project_prefix}#{repo_prefix}r#{identifier}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.revision},
|
|
|
|
:class => 'changeset',
|
|
|
|
:title => truncate_single_line(changeset.comments, :length => 100))
|
|
|
|
end
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
|
|
|
elsif sep == '#'
|
2010-02-18 21:53:30 +03:00
|
|
|
oid = identifier.to_i
|
2008-01-15 21:12:12 +03:00
|
|
|
case prefix
|
|
|
|
when nil
|
2012-07-25 01:51:10 +04:00
|
|
|
if oid.to_s == identifier && issue = Issue.visible.find_by_id(oid, :include => :status)
|
2012-02-15 21:49:31 +04:00
|
|
|
anchor = comment_id ? "note-#{comment_id}" : nil
|
|
|
|
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => anchor},
|
2009-11-14 15:59:32 +03:00
|
|
|
:class => issue.css_classes,
|
2009-02-21 14:04:50 +03:00
|
|
|
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
|
|
|
when 'document'
|
2011-01-23 19:47:59 +03:00
|
|
|
if document = Document.visible.find_by_id(oid)
|
2008-02-17 17:17:20 +03:00
|
|
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
|
|
|
:class => 'document'
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
|
|
|
when 'version'
|
2011-01-23 19:47:59 +03:00
|
|
|
if version = Version.visible.find_by_id(oid)
|
2008-02-17 17:17:20 +03:00
|
|
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
|
|
|
:class => 'version'
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
2008-08-11 02:18:23 +04:00
|
|
|
when 'message'
|
2011-01-23 19:47:59 +03:00
|
|
|
if message = Message.visible.find_by_id(oid, :include => :parent)
|
2011-01-23 20:02:10 +03:00
|
|
|
link = link_to_message(message, {:only_path => only_path}, :class => 'message')
|
2008-08-11 02:18:23 +04:00
|
|
|
end
|
2011-11-19 15:16:23 +04:00
|
|
|
when 'forum'
|
|
|
|
if board = Board.visible.find_by_id(oid)
|
|
|
|
link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
|
|
|
|
:class => 'board'
|
|
|
|
end
|
|
|
|
when 'news'
|
|
|
|
if news = News.visible.find_by_id(oid)
|
|
|
|
link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
|
|
|
|
:class => 'news'
|
|
|
|
end
|
2010-02-13 13:32:06 +03:00
|
|
|
when 'project'
|
|
|
|
if p = Project.visible.find_by_id(oid)
|
2010-08-08 11:07:20 +04:00
|
|
|
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
2010-02-13 13:32:06 +03:00
|
|
|
end
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
|
|
|
elsif sep == ':'
|
|
|
|
# removes the double quotes if any
|
2010-02-18 21:53:30 +03:00
|
|
|
name = identifier.gsub(%r{^"(.*)"$}, "\\1")
|
2008-01-15 21:12:12 +03:00
|
|
|
case prefix
|
|
|
|
when 'document'
|
2011-01-23 19:47:59 +03:00
|
|
|
if project && document = project.documents.visible.find_by_title(name)
|
2008-02-17 17:17:20 +03:00
|
|
|
link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
|
|
|
|
:class => 'document'
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
|
|
|
when 'version'
|
2011-01-23 19:47:59 +03:00
|
|
|
if project && version = project.versions.visible.find_by_name(name)
|
2008-02-17 17:17:20 +03:00
|
|
|
link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
|
|
|
|
:class => 'version'
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
2011-11-19 15:16:23 +04:00
|
|
|
when 'forum'
|
|
|
|
if project && board = project.boards.visible.find_by_name(name)
|
|
|
|
link = link_to h(board.name), {:only_path => only_path, :controller => 'boards', :action => 'show', :id => board, :project_id => board.project},
|
|
|
|
:class => 'board'
|
|
|
|
end
|
|
|
|
when 'news'
|
|
|
|
if project && news = project.news.visible.find_by_title(name)
|
|
|
|
link = link_to h(news.title), {:only_path => only_path, :controller => 'news', :action => 'show', :id => news},
|
|
|
|
:class => 'news'
|
|
|
|
end
|
2012-01-22 18:23:10 +04:00
|
|
|
when 'commit', 'source', 'export'
|
|
|
|
if project
|
|
|
|
repository = nil
|
2013-01-27 20:02:49 +04:00
|
|
|
if name =~ %r{^(([a-z0-9\-_]+)\|)(.+)$}
|
2012-01-22 18:23:10 +04:00
|
|
|
repo_prefix, repo_identifier, name = $1, $2, $3
|
|
|
|
repository = project.repositories.detect {|repo| repo.identifier == repo_identifier}
|
|
|
|
else
|
|
|
|
repository = project.repository
|
|
|
|
end
|
|
|
|
if prefix == 'commit'
|
2012-12-03 22:21:32 +04:00
|
|
|
if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
|
2012-01-22 18:23:10 +04:00
|
|
|
link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier},
|
|
|
|
:class => 'changeset',
|
2013-03-22 01:53:28 +04:00
|
|
|
:title => truncate_single_line(changeset.comments, :length => 100)
|
2012-01-22 18:23:10 +04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if repository && User.current.allowed_to?(:browse_repository, project)
|
2012-12-22 00:59:35 +04:00
|
|
|
name =~ %r{^[/\\]*(.*?)(@([^/\\@]+?))?(#(L\d+))?$}
|
2012-01-22 18:23:10 +04:00
|
|
|
path, rev, anchor = $1, $3, $5
|
2012-10-09 21:02:22 +04:00
|
|
|
link = link_to h("#{project_prefix}#{prefix}:#{repo_prefix}#{name}"), {:controller => 'repositories', :action => (prefix == 'export' ? 'raw' : 'entry'), :id => project, :repository_id => repository.identifier_param,
|
2012-01-22 18:23:10 +04:00
|
|
|
:path => to_path_param(path),
|
|
|
|
:rev => rev,
|
2012-10-09 21:02:22 +04:00
|
|
|
:anchor => anchor},
|
2012-01-22 18:23:10 +04:00
|
|
|
:class => (prefix == 'export' ? 'source download' : 'source')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
repo_prefix = nil
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2008-01-15 21:12:12 +03:00
|
|
|
when 'attachment'
|
2010-03-14 11:33:53 +03:00
|
|
|
attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
|
2013-01-16 01:08:27 +04:00
|
|
|
if attachments && attachment = Attachment.latest_attach(attachments, name)
|
2013-01-15 01:13:09 +04:00
|
|
|
link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment')
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
2010-02-13 13:32:06 +03:00
|
|
|
when 'project'
|
2012-12-03 22:21:32 +04:00
|
|
|
if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
|
2010-08-08 11:07:20 +04:00
|
|
|
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
2010-02-13 13:32:06 +03:00
|
|
|
end
|
2008-01-15 21:12:12 +03:00
|
|
|
end
|
2007-09-08 00:07:54 +04:00
|
|
|
end
|
2007-05-26 19:42:37 +04:00
|
|
|
end
|
2012-02-25 04:00:58 +04:00
|
|
|
(leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}"))
|
2007-05-26 19:42:37 +04:00
|
|
|
end
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2012-09-06 21:03:13 +04:00
|
|
|
HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
|
2011-11-18 20:25:00 +04:00
|
|
|
|
|
|
|
def parse_sections(text, project, obj, attr, only_path, options)
|
|
|
|
return unless options[:edit_section_links]
|
|
|
|
text.gsub!(HEADING_RE) do
|
2012-02-25 04:00:58 +04:00
|
|
|
heading = $1
|
2011-11-18 22:22:41 +04:00
|
|
|
@current_section += 1
|
|
|
|
if @current_section > 1
|
2011-11-18 20:25:00 +04:00
|
|
|
content_tag('div',
|
2011-11-18 22:22:41 +04:00
|
|
|
link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)),
|
2011-11-18 20:25:00 +04:00
|
|
|
:class => 'contextual',
|
2012-02-25 04:00:58 +04:00
|
|
|
:title => l(:button_edit_section)) + heading.html_safe
|
2011-11-18 20:25:00 +04:00
|
|
|
else
|
2012-02-25 04:00:58 +04:00
|
|
|
heading
|
2011-11-18 20:25:00 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-11-06 20:47:27 +03:00
|
|
|
# Headings and TOC
|
2010-12-29 21:21:22 +03:00
|
|
|
# Adds ids and links to headings unless options[:headings] is set to false
|
2010-11-06 20:47:27 +03:00
|
|
|
def parse_headings(text, project, obj, attr, only_path, options)
|
2010-12-29 21:21:22 +03:00
|
|
|
return if options[:headings] == false
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-11-06 20:47:27 +03:00
|
|
|
text.gsub!(HEADING_RE) do
|
2011-11-18 20:25:00 +04:00
|
|
|
level, attrs, content = $2.to_i, $3, $4
|
2010-11-06 20:47:27 +03:00
|
|
|
item = strip_tags(content).strip
|
2011-10-02 21:25:29 +04:00
|
|
|
anchor = sanitize_anchor_name(item)
|
2011-10-02 19:57:17 +04:00
|
|
|
# used for single-file wiki export
|
|
|
|
anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
|
2012-02-14 12:09:23 +04:00
|
|
|
@heading_anchors[anchor] ||= 0
|
|
|
|
idx = (@heading_anchors[anchor] += 1)
|
|
|
|
if idx > 1
|
|
|
|
anchor = "#{anchor}-#{idx}"
|
|
|
|
end
|
2010-12-29 21:21:22 +03:00
|
|
|
@parsed_headings << [level, anchor, item]
|
2011-03-15 01:01:43 +03:00
|
|
|
"<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>"
|
2010-12-29 21:21:22 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2012-08-17 18:46:55 +04:00
|
|
|
MACROS_RE = /(
|
2011-11-18 20:25:00 +04:00
|
|
|
(!)? # escaping
|
|
|
|
(
|
|
|
|
\{\{ # opening tag
|
|
|
|
([\w]+) # macro name
|
2012-08-18 12:25:22 +04:00
|
|
|
(\(([^\n\r]*?)\))? # optional arguments
|
2012-09-02 14:24:56 +04:00
|
|
|
([\n\r].*?[\n\r])? # optional block of text
|
2011-11-18 20:25:00 +04:00
|
|
|
\}\} # closing tag
|
|
|
|
)
|
2012-08-18 12:25:22 +04:00
|
|
|
)/mx unless const_defined?(:MACROS_RE)
|
2012-08-17 18:46:55 +04:00
|
|
|
|
|
|
|
MACRO_SUB_RE = /(
|
|
|
|
\{\{
|
|
|
|
macro\((\d+)\)
|
|
|
|
\}\}
|
2012-09-02 15:09:43 +04:00
|
|
|
)/x unless const_defined?(:MACRO_SUB_RE)
|
2011-11-18 20:25:00 +04:00
|
|
|
|
2012-08-17 18:46:55 +04:00
|
|
|
# Extracts macros from text
|
|
|
|
def catch_macros(text)
|
|
|
|
macros = {}
|
2011-11-18 20:25:00 +04:00
|
|
|
text.gsub!(MACROS_RE) do
|
2012-08-17 18:46:55 +04:00
|
|
|
all, macro = $1, $4.downcase
|
|
|
|
if macro_exists?(macro) || all =~ MACRO_SUB_RE
|
|
|
|
index = macros.size
|
|
|
|
macros[index] = all
|
|
|
|
"{{macro(#{index})}}"
|
2011-11-18 20:25:00 +04:00
|
|
|
else
|
|
|
|
all
|
|
|
|
end
|
|
|
|
end
|
2012-08-17 18:46:55 +04:00
|
|
|
macros
|
|
|
|
end
|
|
|
|
|
|
|
|
# Executes and replaces macros in text
|
|
|
|
def inject_macros(text, obj, macros, execute=true)
|
|
|
|
text.gsub!(MACRO_SUB_RE) do
|
|
|
|
all, index = $1, $2.to_i
|
|
|
|
orig = macros.delete(index)
|
|
|
|
if execute && orig && orig =~ MACROS_RE
|
2012-08-18 12:25:22 +04:00
|
|
|
esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip)
|
2012-08-17 18:46:55 +04:00
|
|
|
if esc.nil?
|
2012-08-18 12:25:22 +04:00
|
|
|
h(exec_macro(macro, obj, args, block) || all)
|
2012-08-17 18:46:55 +04:00
|
|
|
else
|
|
|
|
h(all)
|
|
|
|
end
|
|
|
|
elsif orig
|
|
|
|
h(orig)
|
|
|
|
else
|
|
|
|
h(all)
|
|
|
|
end
|
|
|
|
end
|
2011-11-18 20:25:00 +04:00
|
|
|
end
|
|
|
|
|
2010-12-29 21:21:22 +03:00
|
|
|
TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-12-29 21:21:22 +03:00
|
|
|
# Renders the TOC with given headings
|
|
|
|
def replace_toc(text, headings)
|
2010-11-06 20:47:27 +03:00
|
|
|
text.gsub!(TOC_RE) do
|
2012-09-06 21:03:13 +04:00
|
|
|
# Keep only the 4 first levels
|
|
|
|
headings = headings.select{|level, anchor, item| level <= 4}
|
2010-11-06 20:47:27 +03:00
|
|
|
if headings.empty?
|
|
|
|
''
|
|
|
|
else
|
|
|
|
div_class = 'toc'
|
|
|
|
div_class << ' right' if $1 == '>'
|
|
|
|
div_class << ' left' if $1 == '<'
|
2010-11-06 21:52:07 +03:00
|
|
|
out = "<ul class=\"#{div_class}\"><li>"
|
|
|
|
root = headings.map(&:first).min
|
|
|
|
current = root
|
|
|
|
started = false
|
2010-11-06 20:47:27 +03:00
|
|
|
headings.each do |level, anchor, item|
|
2010-11-06 21:52:07 +03:00
|
|
|
if level > current
|
|
|
|
out << '<ul><li>' * (level - current)
|
|
|
|
elsif level < current
|
|
|
|
out << "</li></ul>\n" * (current - level) + "</li><li>"
|
|
|
|
elsif started
|
|
|
|
out << '</li><li>'
|
|
|
|
end
|
|
|
|
out << "<a href=\"##{anchor}\">#{item}</a>"
|
|
|
|
current = level
|
|
|
|
started = true
|
2010-11-06 20:47:27 +03:00
|
|
|
end
|
2010-11-06 21:52:07 +03:00
|
|
|
out << '</li></ul>' * (current - root)
|
|
|
|
out << '</li></ul>'
|
2010-11-06 20:47:27 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-07-14 15:25:03 +04:00
|
|
|
# Same as Rails' simple_format helper without using paragraphs
|
|
|
|
def simple_format_without_paragraph(text)
|
|
|
|
text.to_s.
|
|
|
|
gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
|
|
|
|
gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
|
2011-10-06 15:03:58 +04:00
|
|
|
gsub(/([^\n]\n)(?=[^\n])/, '\1<br />'). # 1 newline -> br
|
|
|
|
html_safe
|
2007-07-14 15:25:03 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
def lang_options_for_select(blank=true)
|
2012-11-18 22:01:24 +04:00
|
|
|
(blank ? [["(auto)", ""]] : []) + languages_options
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
def label_tag_for(name, option_tags = nil, options = {})
|
|
|
|
label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
|
|
|
|
content_tag("label", label_text)
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2011-11-26 21:56:52 +04:00
|
|
|
def labelled_form_for(*args, &proc)
|
|
|
|
args << {} unless args.last.is_a?(Hash)
|
|
|
|
options = args.last
|
2012-04-25 21:17:49 +04:00
|
|
|
if args.first.is_a?(Symbol)
|
|
|
|
options.merge!(:as => args.shift)
|
|
|
|
end
|
2011-12-09 22:45:38 +04:00
|
|
|
options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
|
2011-11-26 21:56:52 +04:00
|
|
|
form_for(*args, &proc)
|
|
|
|
end
|
|
|
|
|
2011-12-09 22:40:28 +04:00
|
|
|
def labelled_fields_for(*args, &proc)
|
|
|
|
args << {} unless args.last.is_a?(Hash)
|
|
|
|
options = args.last
|
2011-12-09 22:45:38 +04:00
|
|
|
options.merge!({:builder => Redmine::Views::LabelledFormBuilder})
|
2011-12-09 22:40:28 +04:00
|
|
|
fields_for(*args, &proc)
|
|
|
|
end
|
|
|
|
|
|
|
|
def labelled_remote_form_for(*args, &proc)
|
2012-07-18 23:13:30 +04:00
|
|
|
ActiveSupport::Deprecation.warn "ApplicationHelper#labelled_remote_form_for is deprecated and will be removed in Redmine 2.2."
|
2011-12-09 22:40:28 +04:00
|
|
|
args << {} unless args.last.is_a?(Hash)
|
|
|
|
options = args.last
|
2012-04-29 11:42:48 +04:00
|
|
|
options.merge!({:builder => Redmine::Views::LabelledFormBuilder, :remote => true})
|
2012-04-29 08:08:44 +04:00
|
|
|
form_for(*args, &proc)
|
2011-12-09 22:40:28 +04:00
|
|
|
end
|
|
|
|
|
2012-02-26 22:07:13 +04:00
|
|
|
def error_messages_for(*objects)
|
|
|
|
html = ""
|
|
|
|
objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
|
|
|
|
errors = objects.map {|o| o.errors.full_messages}.flatten
|
|
|
|
if errors.any?
|
|
|
|
html << "<div id='errorExplanation'><ul>\n"
|
|
|
|
errors.each do |error|
|
|
|
|
html << "<li>#{h error}</li>\n"
|
|
|
|
end
|
|
|
|
html << "</ul></div>\n"
|
|
|
|
end
|
|
|
|
html.html_safe
|
|
|
|
end
|
|
|
|
|
2012-07-07 18:36:49 +04:00
|
|
|
def delete_link(url, options={})
|
|
|
|
options = {
|
|
|
|
:method => :delete,
|
|
|
|
:data => {:confirm => l(:text_are_you_sure)},
|
|
|
|
:class => 'icon icon-del'
|
|
|
|
}.merge(options)
|
|
|
|
|
|
|
|
link_to l(:button_delete), url, options
|
|
|
|
end
|
|
|
|
|
2012-07-18 21:47:19 +04:00
|
|
|
def preview_link(url, form, target='preview', options={})
|
|
|
|
content_tag 'a', l(:label_preview), {
|
|
|
|
:href => "#",
|
|
|
|
:onclick => %|submitPreview("#{escape_javascript url_for(url)}", "#{escape_javascript form}", "#{escape_javascript target}"); return false;|,
|
|
|
|
:accesskey => accesskey(:preview)
|
|
|
|
}.merge(options)
|
|
|
|
end
|
|
|
|
|
2012-07-28 19:26:45 +04:00
|
|
|
def link_to_function(name, function, html_options={})
|
|
|
|
content_tag(:a, name, {:href => '#', :onclick => "#{function}; return false;"}.merge(html_options))
|
|
|
|
end
|
|
|
|
|
2012-09-25 22:23:11 +04:00
|
|
|
# Helper to render JSON in views
|
|
|
|
def raw_json(arg)
|
|
|
|
arg.to_json.to_s.gsub('/', '\/').html_safe
|
|
|
|
end
|
|
|
|
|
2012-08-26 14:40:09 +04:00
|
|
|
def back_url
|
|
|
|
url = params[:back_url]
|
|
|
|
if url.nil? && referer = request.env['HTTP_REFERER']
|
|
|
|
url = CGI.unescape(referer.to_s)
|
|
|
|
end
|
|
|
|
url
|
|
|
|
end
|
|
|
|
|
2008-04-16 21:27:53 +04:00
|
|
|
def back_url_hidden_field_tag
|
2012-08-26 14:40:09 +04:00
|
|
|
url = back_url
|
|
|
|
hidden_field_tag('back_url', url, :id => nil) unless url.blank?
|
2008-04-16 21:27:53 +04:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
def check_all_links(form_name)
|
|
|
|
link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
|
2011-08-20 15:51:26 +04:00
|
|
|
" | ".html_safe +
|
2008-11-07 17:35:18 +03:00
|
|
|
link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-12-05 22:21:25 +03:00
|
|
|
def progress_bar(pcts, options={})
|
|
|
|
pcts = [pcts, pcts] unless pcts.is_a?(Array)
|
2009-11-21 13:50:36 +03:00
|
|
|
pcts = pcts.collect(&:round)
|
2007-12-05 22:21:25 +03:00
|
|
|
pcts[1] = pcts[1] - pcts[0]
|
|
|
|
pcts << (100 - pcts[1] - pcts[0])
|
2007-11-17 18:34:10 +03:00
|
|
|
width = options[:width] || '100px;'
|
|
|
|
legend = options[:legend] || ''
|
|
|
|
content_tag('table',
|
|
|
|
content_tag('tr',
|
2011-08-20 15:51:49 +04:00
|
|
|
(pcts[0] > 0 ? content_tag('td', '', :style => "width: #{pcts[0]}%;", :class => 'closed') : ''.html_safe) +
|
|
|
|
(pcts[1] > 0 ? content_tag('td', '', :style => "width: #{pcts[1]}%;", :class => 'done') : ''.html_safe) +
|
|
|
|
(pcts[2] > 0 ? content_tag('td', '', :style => "width: #{pcts[2]}%;", :class => 'todo') : ''.html_safe)
|
|
|
|
), :class => 'progress', :style => "width: #{width};").html_safe +
|
2013-01-04 12:30:25 +04:00
|
|
|
content_tag('p', legend, :class => 'percent').html_safe
|
2007-11-17 18:34:10 +03:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-03-17 23:46:22 +03:00
|
|
|
def checked_image(checked=true)
|
|
|
|
if checked
|
|
|
|
image_tag 'toggle_check.png'
|
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-03-04 22:02:57 +03:00
|
|
|
def context_menu(url)
|
|
|
|
unless @context_menu_included
|
|
|
|
content_for :header_tags do
|
|
|
|
javascript_include_tag('context_menu') +
|
|
|
|
stylesheet_link_tag('context_menu')
|
|
|
|
end
|
2010-08-22 23:12:21 +04:00
|
|
|
if l(:direction) == 'rtl'
|
|
|
|
content_for :header_tags do
|
|
|
|
stylesheet_link_tag('context_menu_rtl')
|
|
|
|
end
|
|
|
|
end
|
2010-03-04 22:02:57 +03:00
|
|
|
@context_menu_included = true
|
|
|
|
end
|
2012-07-22 17:29:26 +04:00
|
|
|
javascript_tag "contextMenuInit('#{ url_for(url) }')"
|
2010-03-04 22:02:57 +03:00
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-03-12 20:59:02 +03:00
|
|
|
def calendar_for(field_id)
|
2008-04-01 01:48:01 +04:00
|
|
|
include_calendar_headers_tags
|
2012-07-22 18:43:19 +04:00
|
|
|
javascript_tag("$(function() { $('##{field_id}').datepicker(datepickerOptions); });")
|
2007-03-12 20:59:02 +03:00
|
|
|
end
|
2008-04-01 01:48:01 +04:00
|
|
|
|
|
|
|
def include_calendar_headers_tags
|
|
|
|
unless @calendar_headers_tags_included
|
|
|
|
@calendar_headers_tags_included = true
|
|
|
|
content_for :header_tags do
|
2012-09-11 21:26:42 +04:00
|
|
|
start_of_week = Setting.start_of_week
|
|
|
|
start_of_week = l(:general_first_day_of_week, :default => '1') if start_of_week.blank?
|
|
|
|
# Redmine uses 1..7 (monday..sunday) in settings and locales
|
|
|
|
# JQuery uses 0..6 (sunday..saturday), 7 needs to be changed to 0
|
|
|
|
start_of_week = start_of_week.to_i % 7
|
2012-09-11 21:15:54 +04:00
|
|
|
|
2012-09-05 21:22:08 +04:00
|
|
|
tags = javascript_tag(
|
2012-09-11 21:15:54 +04:00
|
|
|
"var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: #{start_of_week}, " +
|
2012-09-05 21:22:08 +04:00
|
|
|
"showOn: 'button', buttonImageOnly: true, buttonImage: '" +
|
|
|
|
path_to_image('/images/calendar.png') +
|
2013-03-20 01:53:22 +04:00
|
|
|
"', showButtonPanel: true, showWeek: true, showOtherMonths: true, selectOtherMonths: true, changeMonth: true, changeYear: true};")
|
2012-07-22 18:43:19 +04:00
|
|
|
jquery_locale = l('jquery.locale', :default => current_language.to_s)
|
|
|
|
unless jquery_locale == 'en'
|
|
|
|
tags << javascript_include_tag("i18n/jquery.ui.datepicker-#{jquery_locale}.js")
|
2009-12-13 07:06:55 +03:00
|
|
|
end
|
2012-07-22 18:43:19 +04:00
|
|
|
tags
|
2008-04-01 01:48:01 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2012-04-28 13:10:46 +04:00
|
|
|
# Overrides Rails' stylesheet_link_tag with themes and plugins support.
|
|
|
|
# Examples:
|
|
|
|
# stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults
|
|
|
|
# stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets
|
|
|
|
#
|
|
|
|
def stylesheet_link_tag(*sources)
|
|
|
|
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
|
|
|
plugin = options.delete(:plugin)
|
|
|
|
sources = sources.map do |source|
|
|
|
|
if plugin
|
|
|
|
"/plugin_assets/#{plugin}/stylesheets/#{source}"
|
|
|
|
elsif current_theme && current_theme.stylesheets.include?(source)
|
|
|
|
current_theme.stylesheet_path(source)
|
|
|
|
else
|
|
|
|
source
|
|
|
|
end
|
|
|
|
end
|
|
|
|
super sources, options
|
|
|
|
end
|
|
|
|
|
2012-04-28 13:47:09 +04:00
|
|
|
# Overrides Rails' image_tag with themes and plugins support.
|
2012-04-28 13:18:12 +04:00
|
|
|
# Examples:
|
2012-04-28 13:47:09 +04:00
|
|
|
# image_tag('image.png') # => picks image.png from the current theme or defaults
|
2012-04-28 13:18:12 +04:00
|
|
|
# image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
|
|
|
|
#
|
|
|
|
def image_tag(source, options={})
|
|
|
|
if plugin = options.delete(:plugin)
|
|
|
|
source = "/plugin_assets/#{plugin}/images/#{source}"
|
2012-04-28 13:47:09 +04:00
|
|
|
elsif current_theme && current_theme.images.include?(source)
|
|
|
|
source = current_theme.image_path(source)
|
2012-04-28 13:18:12 +04:00
|
|
|
end
|
|
|
|
super source, options
|
|
|
|
end
|
|
|
|
|
2012-04-28 13:10:46 +04:00
|
|
|
# Overrides Rails' javascript_include_tag with plugins support
|
|
|
|
# Examples:
|
|
|
|
# javascript_include_tag('scripts') # => picks scripts.js from defaults
|
|
|
|
# javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets
|
|
|
|
#
|
|
|
|
def javascript_include_tag(*sources)
|
|
|
|
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
|
|
|
if plugin = options.delete(:plugin)
|
|
|
|
sources = sources.map do |source|
|
|
|
|
if plugin
|
|
|
|
"/plugin_assets/#{plugin}/javascripts/#{source}"
|
|
|
|
else
|
|
|
|
source
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
super sources, options
|
|
|
|
end
|
|
|
|
|
2007-09-22 17:17:49 +04:00
|
|
|
def content_for(name, content = nil, &block)
|
|
|
|
@has_content ||= {}
|
|
|
|
@has_content[name] = true
|
|
|
|
super(name, content, &block)
|
|
|
|
end
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2007-09-22 17:17:49 +04:00
|
|
|
def has_content?(name)
|
|
|
|
(@has_content && @has_content[name]) || false
|
|
|
|
end
|
2011-08-20 09:57:14 +04:00
|
|
|
|
2012-05-01 14:19:06 +04:00
|
|
|
def sidebar_content?
|
|
|
|
has_content?(:sidebar) || view_layouts_base_sidebar_hook_response.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def view_layouts_base_sidebar_hook_response
|
|
|
|
@view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar)
|
|
|
|
end
|
|
|
|
|
2011-07-03 16:28:54 +04:00
|
|
|
def email_delivery_enabled?
|
|
|
|
!!ActionMailer::Base.perform_deliveries
|
|
|
|
end
|
2008-10-27 14:08:29 +03:00
|
|
|
|
2008-11-09 17:52:16 +03:00
|
|
|
# Returns the avatar image tag for the given +user+ if avatars are enabled
|
|
|
|
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
|
|
|
|
def avatar(user, options = { })
|
2008-10-31 03:41:28 +03:00
|
|
|
if Setting.gravatar_enabled?
|
2012-08-10 20:35:58 +04:00
|
|
|
options.merge!({:ssl => (request && request.ssl?), :default => Setting.gravatar_default})
|
2008-11-09 17:52:16 +03:00
|
|
|
email = nil
|
|
|
|
if user.respond_to?(:mail)
|
|
|
|
email = user.mail
|
|
|
|
elsif user.to_s =~ %r{<(.+?)>}
|
|
|
|
email = $1
|
|
|
|
end
|
|
|
|
return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
|
2010-09-10 07:09:02 +04:00
|
|
|
else
|
|
|
|
''
|
2008-10-31 03:41:28 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2011-10-02 21:25:29 +04:00
|
|
|
def sanitize_anchor_name(anchor)
|
2012-08-14 04:30:23 +04:00
|
|
|
if ''.respond_to?(:encoding) || RUBY_PLATFORM == 'java'
|
2013-03-01 12:57:01 +04:00
|
|
|
anchor.gsub(%r{[^\s\-\p{Word}]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
|
2012-08-13 23:36:00 +04:00
|
|
|
else
|
|
|
|
# TODO: remove when ruby1.8 is no longer supported
|
|
|
|
anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
|
|
|
|
end
|
2011-10-02 21:25:29 +04:00
|
|
|
end
|
|
|
|
|
2011-02-21 12:53:29 +03:00
|
|
|
# Returns the javascript tags that are included in the html layout head
|
|
|
|
def javascript_heads
|
2012-12-26 15:47:51 +04:00
|
|
|
tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application')
|
2011-02-21 12:53:29 +03:00
|
|
|
unless User.current.pref.warn_on_leaving_unsaved == '0'
|
2012-07-22 17:29:26 +04:00
|
|
|
tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
|
2011-02-21 12:53:29 +03:00
|
|
|
end
|
|
|
|
tags
|
|
|
|
end
|
2008-10-31 03:41:28 +03:00
|
|
|
|
2010-07-29 18:58:33 +04:00
|
|
|
def favicon
|
2011-08-20 09:05:26 +04:00
|
|
|
"<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />".html_safe
|
2010-07-29 18:58:33 +04:00
|
|
|
end
|
2011-04-12 23:22:44 +04:00
|
|
|
|
|
|
|
def robot_exclusion_tag
|
2011-11-28 16:20:37 +04:00
|
|
|
'<meta name="robots" content="noindex,follow,noarchive" />'.html_safe
|
2011-04-12 23:22:44 +04:00
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2010-12-11 13:19:11 +03:00
|
|
|
# Returns true if arg is expected in the API response
|
|
|
|
def include_in_api_response?(arg)
|
|
|
|
unless @included_in_api_response
|
|
|
|
param = params[:include]
|
|
|
|
@included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
|
|
|
|
@included_in_api_response.collect!(&:strip)
|
|
|
|
end
|
|
|
|
@included_in_api_response.include?(arg.to_s)
|
|
|
|
end
|
2010-07-29 18:58:33 +04:00
|
|
|
|
2010-12-11 16:13:49 +03:00
|
|
|
# Returns options or nil if nometa param or X-Redmine-Nometa header
|
|
|
|
# was set in the request
|
|
|
|
def api_meta(options)
|
|
|
|
if params[:nometa].present? || request.headers['X-Redmine-Nometa']
|
|
|
|
# compatibility mode for activeresource clients that raise
|
|
|
|
# an error when unserializing an array with attributes
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
options
|
|
|
|
end
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2008-10-27 14:08:29 +03:00
|
|
|
private
|
2008-11-07 17:35:18 +03:00
|
|
|
|
2008-10-27 14:08:29 +03:00
|
|
|
def wiki_helper
|
|
|
|
helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
|
|
|
|
extend helper
|
|
|
|
return self
|
|
|
|
end
|
2011-05-18 06:46:24 +04:00
|
|
|
|
2011-04-03 18:01:32 +04:00
|
|
|
def link_to_content_update(text, url_params = {}, html_options = {})
|
2011-04-03 18:06:53 +04:00
|
|
|
link_to(text, url_params, html_options)
|
2009-01-26 04:47:51 +03:00
|
|
|
end
|
2006-06-28 22:11:03 +04:00
|
|
|
end
|