2011-12-14 23:56:23 +04:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
2008-09-28 16:03:17 +04:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2008-09-28 16:03:17 +04: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.
|
2011-09-01 04:45:50 +04:00
|
|
|
#
|
2008-09-28 16:03:17 +04: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.
|
2011-09-01 04:45:50 +04:00
|
|
|
#
|
2008-09-28 16:03:17 +04: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.
|
|
|
|
|
|
|
|
module WorkflowsHelper
|
2014-02-25 06:54:47 +04:00
|
|
|
def options_for_workflow_select(name, objects, selected, options={})
|
|
|
|
option_tags = ''.html_safe
|
|
|
|
multiple = false
|
|
|
|
if selected
|
|
|
|
if selected.size == objects.size
|
|
|
|
selected = 'all'
|
|
|
|
else
|
|
|
|
selected = selected.map(&:id)
|
|
|
|
if selected.size > 1
|
|
|
|
multiple = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
selected = objects.first.try(:id)
|
|
|
|
end
|
|
|
|
all_tag_options = {:value => 'all', :selected => (selected == 'all')}
|
|
|
|
if multiple
|
|
|
|
all_tag_options.merge!(:style => "display:none;")
|
|
|
|
end
|
2014-02-26 00:17:15 +04:00
|
|
|
option_tags << content_tag('option', l(:label_all), all_tag_options)
|
2014-02-25 06:54:47 +04:00
|
|
|
option_tags << options_from_collection_for_select(objects, "id", "name", selected)
|
|
|
|
select_tag name, option_tags, {:multiple => multiple}.merge(options)
|
|
|
|
end
|
|
|
|
|
2012-07-16 20:33:27 +04:00
|
|
|
def field_required?(field)
|
2012-07-19 20:21:28 +04:00
|
|
|
field.is_a?(CustomField) ? field.is_required? : %w(project_id tracker_id subject priority_id is_private).include?(field)
|
2012-07-16 20:33:27 +04:00
|
|
|
end
|
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
def field_permission_tag(permissions, status, field, roles)
|
2012-07-15 18:12:17 +04:00
|
|
|
name = field.is_a?(CustomField) ? field.id.to_s : field
|
2012-07-16 20:33:27 +04:00
|
|
|
options = [["", ""], [l(:label_readonly), "readonly"]]
|
|
|
|
options << [l(:label_required), "required"] unless field_required?(field)
|
2013-07-13 13:20:11 +04:00
|
|
|
html_options = {}
|
2014-02-25 06:54:47 +04:00
|
|
|
|
|
|
|
if perm = permissions[status.id][name]
|
|
|
|
if perm.uniq.size > 1 || perm.size < @roles.size * @trackers.size
|
|
|
|
options << [l(:label_no_change_option), "no_change"]
|
|
|
|
selected = 'no_change'
|
|
|
|
else
|
|
|
|
selected = perm.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hidden = field.is_a?(CustomField) &&
|
|
|
|
!field.visible? &&
|
|
|
|
!roles.detect {|role| role.custom_fields.to_a.include?(field)}
|
2012-07-15 20:57:04 +04:00
|
|
|
|
2013-07-13 13:20:11 +04:00
|
|
|
if hidden
|
|
|
|
options[0][0] = l(:label_hidden)
|
|
|
|
selected = ''
|
|
|
|
html_options[:disabled] = true
|
|
|
|
end
|
|
|
|
|
2014-02-25 06:54:47 +04:00
|
|
|
select_tag("permissions[#{status.id}][#{name}]", options_for_select(options, selected), html_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def transition_tag(workflows, old_status, new_status, name)
|
|
|
|
w = workflows.select {|w| w.old_status_id == old_status.id && w.new_status_id == new_status.id}.size
|
|
|
|
|
|
|
|
tag_name = "transitions[#{ old_status.id }][#{new_status.id}][#{name}]"
|
|
|
|
if w == 0 || w == @roles.size * @trackers.size
|
|
|
|
|
|
|
|
hidden_field_tag(tag_name, "0") +
|
|
|
|
check_box_tag(tag_name, "1", w != 0,
|
|
|
|
:class => "old-status-#{old_status.id} new-status-#{new_status.id}")
|
|
|
|
else
|
|
|
|
select_tag tag_name,
|
2014-02-26 00:17:15 +04:00
|
|
|
options_for_select([
|
|
|
|
[l(:general_text_Yes), "1"],
|
|
|
|
[l(:general_text_No), "0"],
|
|
|
|
[l(:label_no_change_option), "no_change"]
|
|
|
|
], "no_change")
|
2014-02-25 06:54:47 +04:00
|
|
|
end
|
2012-07-15 18:12:17 +04:00
|
|
|
end
|
2008-09-28 16:03:17 +04:00
|
|
|
end
|