Newer
Older
dmpopidor / app / views / branded / plans / _share_form.html.erb
<% administrator = Role.new(administrator: true, editor: true, commenter: true) %>
<% editor = Role.new(editor: true, commenter: true) %>
<% commenter = Role.new(commenter: true) %>
<% administerable = @plan.administerable_by?(current_user) %>
<% email_tooltip = _("Enter the email address of your collaborator: If they are already using %{tool_name}, they will see this plan on their dashboard, and recieve an email. If they are not currently using %{tool_name}, they will recieve an email inviting them to the tool so they can collaborate on your plan.") % {
  tool_name: Rails.configuration.branding[:application][:name]
} %>
<% permissions_tooltip = _('Co-owner: Has admin-rights to the plan (can invite other users, view the plan, answer questions, or comment). Editor: Has edit-rights to the plan (can view the plan, answer questions, or comment). Read Only: Has read-rights to the plan (can view the plan or comment)') %>



<div class="share-form">
  <h2><%= _('Manage collaborators')%></h2>
  <p><%= _('Invite specific people to read, edit, or administer your plan. Invitees will receive an email notification that they have access to this plan.') %></p>
  <% if @plan.roles.any? then %>
    <table class="table table-hover table-bordered" id="collaborator-table">
      <thead>
        <tr>
          <th scope="col"><%= _('Email address')%></th>
          <th scope="col"><%= _('Permissions')%></th>
          <% if administerable %>
            <th scope="col"><span aria-hidden="false" class="sr-only"><%= _('Actions') %></span></th>
          <% end %>
        </tr>
      </thead>
      <tbody>
        <% @plan_roles.each do |role| %>
          <tr>
            <td><%= role.user.name %></td>
            <td>
              <% if role.creator? %>
                  <span><%= display_role(role) %></span>
              <% else %>
                  <% if administerable && role.user != current_user %>
                        <%= form_for role, url: { controller: :roles, action: :update, id: role.id }, remote: true, html: { method: :put } do |f| %>
                        <div class="form-group col-xs-8">
                          <%= f.hidden_field :id %>
                          <%= f.select :access, {
                                "#{display_role(administrator)}": administrator.access,
                                "#{display_role(editor)}": editor.access,
                                "#{display_role(commenter)}": commenter.access
                              }, {}, { id: "#{role.id}-can-edit", class: "toggle-existing-user-access" } %>
                        </div>
                      <% end %>
                  <% else %>
                      <span><%= display_role(role) %></span>
                  <% end %>
              <% end %>
              <% if administerable %>
                  <% unless role.creator? || role.user == current_user then %>
                    <%= link_to _('Remove'), role, method: :delete, data: { confirm: _('Are you sure?') }, :class => "a-orange" %>
                  <% end %>
              <% end %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  <% end %>

  <% if administerable  %>
    <h2><%= _('Invite collaborators') %></h2>
    <% new_role = Role.new %>
    <% new_role.plan = @plan %>
    <%= form_for new_role, url: {controller: :roles, action: :create }, html: {method: :post} do |f| %>
      <div class="form-group col-xs-8">
        <%= f.hidden_field :plan_id %>
        <%= f.fields_for :user do |user| %>
          <%= user.label :email, _('Email'), class: 'control-label' %>
          <em class="sr-only"><%= email_tooltip %></em>
          <%= user.email_field :email, for: :user, name: "user", class: "form-control",
                            "aria-required": true,
                            'data-toggle': 'tooltip',
                            'data-html': true,
                            title: email_tooltip %>
      
        <% end %>
      </div>
      <em class="sr-only"><%= permissions_tooltip %></em>
      <%= field_set_tag  nil, class: 'col-xs-12',
                      'data-toggle': 'tooltip',
                      'data-html': true,
                      title: permissions_tooltip,
                      'data-placement':'right' do %>
        <legend><%= _('Permissions') %></legend>
        <div class="form-group">
          <div class="radio">
            <%= f.label :administrator_access do %>
              <%= f.radio_button :access, administrator.access, id: "role_administrator_access", "aria-required": true %>
              <%= _('Co-owner: can edit project details, change visibility, and add collaborators') %>
            <% end %>
          </div>
          <div class="radio">
            <%= f.label :editor_access do %>
              <%= f.radio_button :access, editor.access, id: "role_editor_access" %>
              <%= _('Editor: can comment and make changes') %>
            <% end %>
          </div>
          <div class="radio">
            <%= f.label :commenter_access do %>
              <%= f.radio_button :access, commenter.access, id: "role_commenter_access" %>
              <%= _('Read only: can view and comment, but not make changes') %>
            <% end %>
          </div>

          <%= f.button(_('Submit'), class: "btn btn-primary", type: "submit") %>
        </div>
      <% end %>
      <div class="clearfix"></div>
    <% end %>  
  <% end %>
  <h2><%= _('Set plan visibility') %></h2>
  <p class="form-control-static">
    <%= d_('dmpopidor', 'Public, Administrator or organisational visibility is intended for finished plans. Note: test plans are set to private visibility.') %>
  </p>
  <% allow_visibility = @plan.visibility_allowed? %>
  <%= form_for(@plan, url: visibility_plan_path, method: :post, html: { id: 'set_visibility' }) do |f| %>
    <fieldset <%= (allow_visibility ? '' : ' disabled') %>>
      <div class="form-group col-xs-8">
        <div class="radio">
          <%= f.label :visibility_privately_visible do %>
            <%= f.radio_button :visibility, :privately_visible %>
            <%= d_('dmpopidor', 'Private: visible to me and specified collaborators') %>
          <% end %>
        </div>
        <div class="radio">
          <%= f.label :visibility_administrator_visible do %>
            <%= f.radio_button :visibility, :administrator_visible %>
            <%= d_('dmpopidor', 'Administrator: visible to me, specified collaborators and administrators at my organisation') %>
          <% end %>
        </div>
        <div class="radio">
          <%= f.label :visibility_organisationally_visible do %>
            <%= f.radio_button :visibility, :organisationally_visible %>
            <%= _('Organisation: anyone at my organisation can view') %>
          <% end %>
        </div>
        <div class="radio">
          <%= f.label :visibility_publicly_visible do %>
            <%= f.radio_button :visibility, :publicly_visible %>
            <%= _('Public: anyone can view') %>
          <% end %>
        </div>
      </div>
      <div class="col-xs-8">
        <%= f.submit(_('Update'), class: "btn btn-primary") %>
      </div>
    </fieldset>
  <% end %>
</div>