2017-01-25 16:48:49 +08:00
|
|
|
module TeamsHelper
|
|
|
|
# resets the current team if needed
|
|
|
|
def current_team_switch(team)
|
2022-05-19 19:46:03 +08:00
|
|
|
if team != current_team && current_user.member_of_team?(team)
|
2017-01-25 16:48:49 +08:00
|
|
|
current_user.current_team_id = team.id
|
|
|
|
current_user.save
|
2020-09-28 22:55:20 +08:00
|
|
|
update_current_team
|
2017-01-25 16:48:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def truncate_team_name(name, len = Constants::NAME_TRUNCATION_LENGTH)
|
|
|
|
if name.length > len
|
|
|
|
sanitize_input("<div class='modal-tooltip'>#{truncate(name, length: len)}
|
|
|
|
<span class='modal-tooltiptext'>#{name}</span>
|
|
|
|
</div>")
|
|
|
|
else
|
|
|
|
name
|
|
|
|
end
|
|
|
|
end
|
2017-01-30 22:55:21 +08:00
|
|
|
|
2020-04-23 22:02:36 +08:00
|
|
|
def switch_team_with_param
|
2020-10-02 20:25:44 +08:00
|
|
|
current_team_switch(current_user.teams.find_by(id: params[:team])) if params[:team]
|
2020-04-23 22:02:36 +08:00
|
|
|
end
|
2017-01-25 16:48:49 +08:00
|
|
|
end
|