scinote-web/app/views/shared/_invite_users_modal.html.erb

166 lines
6.4 KiB
Text
Raw Normal View History

<%
# How to use this modal:
# 1. Render it in the page (HTML) of your choice
# 2. Add an element (e.g. <a href>) with following attributes:
# * data-trigger="invite-users",
# * data-modal-id="modal-id",
#
# Modal parameters:
# * modal_id: unique id so the JS works if multiple modals are present
# on the same page
# * type:
2017-01-25 19:01:23 +08:00
# * 'invite_to_team' => params: team
# * 'invite_to_team_with_role' => params: team, role
# * 'invite',
2017-01-25 19:01:23 +08:00
# * 'invite_with_team_selector',
# * 'invite_with_team_selector_and_role' => params: role
# * team: invite users to the specified team
# * role: all users are invited as the specified role
2016-11-06 18:37:53 +08:00
# * (optional) text_title: custom title text for modal
# * (optional) text_invite_heading: custom invite heading text for modal
%>
<%
text_title ||= nil
text_invite_heading ||= nil
2017-01-25 19:01:23 +08:00
invite_to_team = type.in?(%w(invite_to_team invite_to_team_with_role))
%>
<div
class="modal modal-invite-users"
tabindex="-1"
role="dialog"
aria-labelledby="invite-users-modal-label"
data-id="<%= modal_id %>"
data-role="invite-users-modal"
data-type="<%= type %>"
data-url="<%= invite_users_path %>"
data-backdrop="static"
data-keyboard="false"
2018-07-19 23:56:42 +08:00
data-max-tags="<%= Constants::INVITE_USERS_LIMIT %>"
2017-01-25 19:01:23 +08:00
<%= "data-team-id=#{team.id}" if invite_to_team %>
<%= "data-team-role=#{role}" if type.in?(%w(invite_to_team_with_role invite_with_team_selector_and_role)) %>
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">
2016-11-06 18:37:53 +08:00
<% if text_title %>
<%= text_title %>
<% else %>
2017-01-25 19:01:23 +08:00
<% if invite_to_team %>
<%= t('invite_users.to_team.title', team: team.name) %>
2016-11-06 18:37:53 +08:00
<% else %>
2017-01-25 19:01:23 +08:00
<%= t('invite_users.no_team.title') %>
2016-11-06 18:37:53 +08:00
<% end %>
<% end %>
</h4>
</div>
<div class="modal-body">
<div data-role="step-form">
<p>
2016-11-06 18:37:53 +08:00
<% if text_invite_heading %>
<%= text_invite_heading %>
<% else %>
2017-01-25 19:01:23 +08:00
<% if invite_to_team %>
<%= t('invite_users.to_team.heading', team: team.name) %>
2016-11-06 18:37:53 +08:00
<% else %>
2017-01-25 19:01:23 +08:00
<%= t('invite_users.no_team.heading') %>
2016-11-06 18:37:53 +08:00
<% end %>
<% end %>
</p>
2016-11-06 18:29:00 +08:00
<select class="emails-input" multiple data-role="tags-input" name="emails[]">
</select>
<br />
<em><%= t('invite_users.input_subtitle') %></em>
2017-01-25 19:01:23 +08:00
<% if type.in?(['invite_with_team_selector', 'invite_with_team_selector_and_role']) %>
<% # Only allow inviting to teams where user is admin %>
<% uos = current_user ? current_user.user_teams.where(role: UserTeam.roles[:admin]).joins(:team) : [] %>
<% if uos.count > 0 %>
2017-01-25 19:01:23 +08:00
<div class="team-selector">
<div class="heading">
2017-01-25 19:01:23 +08:00
<input type="checkbox" data-role="team-selector-checkbox" />
<span><%= t('invite_users.invite_to_team_heading') %></span>
</div>
<%= select_tag(
2017-01-25 19:01:23 +08:00
'team-select',
options_for_select(
2017-01-25 19:01:23 +08:00
uos.pluck('teams.name', 'teams.id')
),
{
class: 'form-control selectpicker',
2017-01-25 19:01:23 +08:00
'data-role' => 'team-selector-dropdown',
disabled: 'disabled'
}
) %>
</div>
<% end %>
<% end %>
<% if ENV['ENABLE_RECAPTCHA'] %>
<div id="recaptcha-service" class="g-recaptcha"
data-callback="recaptchaCallback"
data-sitekey=<%= ENV['RECAPTCHA_SITE_KEY'] %>></div>
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=en"></script>
<input type="hidden" id="recaptcha-invite-modal" value="">
<div class="form-group has-error hidden" id="recaptcha-error-msg" >
<span class="has-error help-block"></span>
</div>
<% end %>
</div>
2016-11-06 18:29:00 +08:00
<div class="results-container" data-role="step-results" data-clear="true">
</div>
</div>
<div class="modal-footer">
<div data-role="step-form">
<button type="button" class="btn btn-default" data-dismiss="modal">
<%= t('general.cancel') %>
</button>
<!-- Invite buttons -->
<button type="button" class="btn btn-success help_tooltips"
data-tooltiplink="<%= I18n.t('tooltips.link.invite_to_sci') %>"
data-tooltipcontent="<%= I18n.t('tooltips.text.invite_to_sci') %>"
data-role="invite-btn" data-action="invite"
disabled="disabled">
<%= t('invite_users.invite_btn') %>
</button>
<div class="btn-group" data-role="invite-with-role-div">
<button type="button" class="btn btn-success dropdown-toggle help_tooltips"
data-tooltiplink="<%= I18n.t('tooltips.link.invite_to_sci') %>"
data-tooltipcontent="<%= I18n.t('tooltips.text.invite_to_sci') %>"
data-toggle="dropdown" data-id="invite-btn" aria-haspopup="true"
aria-expanded="false" data-role="invite-with-role-btn"
disabled="disabled">
<%= t('invite_users.invite_btn') %>
&nbsp;
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
2016-11-08 23:43:25 +08:00
<li>
2018-07-19 23:56:42 +08:00
<%= link_to t('invite_users.invite_guest'), '#', data: { action: 'invite', 'team-role' => 'guest', remote: true } %>
2016-11-08 23:43:25 +08:00
</li>
<li>
2018-07-19 23:56:42 +08:00
<%= link_to t('invite_users.invite_user'), '#', data: { action: 'invite', 'team-role' => 'normal_user', remote: true } %>
2016-11-08 23:43:25 +08:00
</li>
<li>
2018-07-19 23:56:42 +08:00
<%= link_to t('invite_users.invite_admin'), '#', data: { action: 'invite', 'team-role' => 'admin', remote: true } %>
2016-11-08 23:43:25 +08:00
</li>
</ul>
</div>
</div>
<div data-role="step-results">
<button type="button" class="btn btn-default" data-dismiss="modal">
<%= t('general.close') %>
</button>
</div>
</div>
</div>
</div>
</div>