You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

workflows_helper.rb 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module WorkflowsHelper
  19. def options_for_workflow_select(name, objects, selected, options={})
  20. option_tags = ''.html_safe
  21. multiple = false
  22. if selected
  23. if selected.size == objects.size
  24. selected = 'all'
  25. else
  26. selected = selected.map(&:id)
  27. if selected.size > 1
  28. multiple = true
  29. end
  30. end
  31. else
  32. selected = objects.first.try(:id)
  33. end
  34. all_tag_options = {:value => 'all', :selected => (selected == 'all')}
  35. if multiple
  36. all_tag_options[:style] = "display:none;"
  37. end
  38. option_tags << content_tag('option', l(:label_all), all_tag_options)
  39. option_tags << options_from_collection_for_select(objects, "id", "name", selected)
  40. select_tag name, option_tags, {:multiple => multiple}.merge(options)
  41. end
  42. def field_required?(field)
  43. field.is_a?(CustomField) ? field.is_required? : %w(project_id tracker_id subject priority_id is_private).include?(field)
  44. end
  45. def field_permission_tag(permissions, status, field, roles)
  46. name = field.is_a?(CustomField) ? field.id.to_s : field
  47. options = [["", ""], [l(:label_readonly), "readonly"]]
  48. options << [l(:label_required), "required"] unless field_required?(field)
  49. html_options = {}
  50. if perm = permissions[status.id][name]
  51. if perm.uniq.size > 1 || perm.size < @roles.size * @trackers.size
  52. options << [l(:label_no_change_option), "no_change"]
  53. selected = 'no_change'
  54. else
  55. selected = perm.first
  56. end
  57. end
  58. hidden = field.is_a?(CustomField) &&
  59. !field.visible? &&
  60. !roles.detect {|role| role.custom_fields.to_a.include?(field)}
  61. if hidden
  62. options[0][0] = l(:label_hidden)
  63. selected = ''
  64. html_options[:disabled] = true
  65. end
  66. select_tag("permissions[#{status.id}][#{name}]", options_for_select(options, selected), html_options)
  67. end
  68. def transition_tag(transition_count, old_status, new_status, name)
  69. w = transition_count
  70. tag_name = "transitions[#{ old_status.try(:id) || 0 }][#{new_status.id}][#{name}]"
  71. if old_status == new_status
  72. check_box_tag(tag_name, "1", true,
  73. {:disabled => true, :class => "old-status-#{old_status.try(:id) || 0} new-status-#{new_status.id}"})
  74. elsif w == 0 || w == @roles.size * @trackers.size
  75. hidden_field_tag(tag_name, "0", :id => nil) +
  76. check_box_tag(tag_name, "1", w != 0,
  77. :class => "old-status-#{old_status.try(:id) || 0} new-status-#{new_status.id}")
  78. else
  79. select_tag(
  80. tag_name,
  81. options_for_select(
  82. [
  83. [l(:general_text_Yes), "1"],
  84. [l(:general_text_No), "0"],
  85. [l(:label_no_change_option), "no_change"]
  86. ],
  87. "no_change")
  88. )
  89. end
  90. end
  91. end