您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

workflows_helper.rb 3.4KB

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