/app/helpers/groups_helper.rb

https://github.com/meloon/crabgrass · Ruby · 155 lines · 100 code · 29 blank · 26 comment · 16 complexity · ea1158b9186fef64a504610c8482f546 MD5 · raw file

  1. module GroupsHelper
  2. ##
  3. ## URLS
  4. ##
  5. #def group_settings_url(options)
  6. # {:controller => '/groups/basic', :action => 'edit'}.merge(options)
  7. #end
  8. #def group_settings_context
  9. # add_context(I18n.t(:settings), groups_url(:action => 'edit', :id => @group))
  10. #end
  11. ##
  12. ## NAVIGATION
  13. ##
  14. def settings_tabs
  15. render :partial => 'groups/navigation/settings_tabs'
  16. end
  17. def edit_settings_link
  18. if may_edit_group?
  19. link_to I18n.t(:edit_settings), groups_url(:action => 'edit', :id => @group)
  20. end
  21. end
  22. def join_group_link
  23. return unless logged_in? and !current_user.direct_member_of? @group
  24. if may_join_memberships?
  25. link_to(I18n.t(:join_group_link, :group_type => @group.group_type), {:controller => 'groups/memberships', :action => 'join', :id => @group}, :method => :post)
  26. elsif may_create_join_request?
  27. link_to(I18n.t(:request_join_group_link, :group_type => @group.group_type), {:controller => 'groups/requests', :action => 'create_join', :id => @group})
  28. end
  29. end
  30. def destroy_group_link
  31. # eventually, this should fire a request to destroy.
  32. if may_destroy_group?
  33. link_to_with_confirm(I18n.t(:destroy_group_link, :group_type => @group.group_type),
  34. {:confirm => I18n.t(:destroy_confirmation, :thing => @group.group_type.downcase), :url => groups_url(:action => :destroy), :method => :post})
  35. end
  36. end
  37. def more_committees_link
  38. ## link_to_iff may_view_committee?, I18n.t(:view_all), ''
  39. end
  40. def create_committee_link
  41. if may_create_subcommittees?
  42. link_to I18n.t(:create_button), committees_params(:action => :new)
  43. end
  44. end
  45. def edit_featured_link(label=nil)
  46. label ||= I18n.t(:edit_featured_content_link).titlecase
  47. if may_edit_featured_pages?
  48. link_to label, groups_features_url(:action => :index)
  49. end
  50. end
  51. def edit_group_custom_appearance_link(appearance)
  52. if appearance and may_edit_appearance?
  53. link_to I18n.t(:edit_appearance), edit_custom_appearance_url(appearance)
  54. end
  55. end
  56. ## request navigation
  57. def requests_link
  58. if may_create_invite_request?
  59. link_to_active(I18n.t(:view_requests), {:controller => 'groups/requests', :action => :list, :id => @group})
  60. end
  61. end
  62. def invite_link
  63. if may_create_invite_request?
  64. link_to_active(I18n.t(:send_invites), {:controller => 'groups/requests', :action => 'create_invite', :id => @group})
  65. end
  66. end
  67. ## membership navigation
  68. def list_membership_link
  69. link_to_active_if_may(I18n.t(:edit), '/groups/memberships', 'edit', @group) or
  70. link_to_active_if_may(I18n.t(:see_all_link), '/groups/memberships', 'list', @group)
  71. end
  72. def membership_count_link
  73. link_if_may(I18n.t(:group_membership_count, :count=>(@group.users.size).to_s) + ARROW,
  74. '/groups/memberships', 'list', @group) or
  75. I18n.t(:group_membership_count, :count=>(@group.users.size).to_s)
  76. end
  77. def group_membership_link
  78. link_to_active_if_may I18n.t(:see_all_link), '/groups/memberships', 'groups', @group
  79. end
  80. def leave_group_link
  81. link_to_active_if_may(I18n.t(:leave_group_link, :group_type => @group.group_type),
  82. '/groups/memberships', 'leave', @group)
  83. end
  84. ##
  85. ## LAYOUT
  86. ##
  87. def show_section(name)
  88. @group.group_setting ||= GroupSetting.new
  89. default_template_data = {"section1" => "group_wiki", "section2" => "recent_pages"}
  90. default_template_data.merge!({"section3" => "recent_group_pages"}) if @group.network?
  91. @group.group_setting.template_data ||= default_template_data
  92. widgets = @group.group_setting.template_data
  93. widget = widgets[name]
  94. #@group.network? ? widget_folder = 'network' : widget_folder = 'group'
  95. render :partial => '/widgets/' + widget if widget.length > 0
  96. end
  97. ##
  98. ## CREATION
  99. ##
  100. def create_group_link
  101. if @active_tab == :groups
  102. if may_create_group?
  103. link_to_with_icon('plus', I18n.t(:create_a_new_thing, :thing => I18n.t(:group).downcase), groups_url(:action => 'new'))
  104. end
  105. elsif @active_tab == :networks
  106. if may_create_network?
  107. link_to_with_icon('plus', I18n.t(:create_a_new_thing, :thing => I18n.t(:network).downcase), networks_url(:action => 'new'))
  108. end
  109. end
  110. end
  111. ##
  112. ## TAGGING
  113. ##
  114. def link_to_group_tag(tag,options)
  115. options[:class] ||= ""
  116. path = (params[:path]||[]).dup
  117. name = tag.name.gsub(' ','+')
  118. if path.delete(name)
  119. options[:class] += ' invert'
  120. else
  121. path << name
  122. end
  123. options[:title] = tag.name
  124. link_to tag.name, groups_url(:action => 'tags') + '/' + path.join('/'), options
  125. end
  126. end