<commit_before><%
   object ||= nil
   set_parameters_for_sharing_form object
   disable_advanced_view ||= nil
   disable_can_publish_check ||= false
   show_advanced_permissions = !@resource.respond_to?(:has_advanced_permissions?) || @resource.has_advanced_permissions?
   default_projects_access_type = @resource.is_asset? ? Policy::ACCESSIBLE : Policy::EDITING
   default_consortium_access_type = Policy::VISIBLE
%>
<%# initialization: required to keep javascript independent of the access type codes, to allow the use the constants instead -%>
<%= render :partial=>"assets/sharing_constants" %>


<%# this hidden input will submit all permission data with the form -%>
<%= hidden_field_tag "sharing[permissions][contributor_types]", "" -%>
<%= hidden_field_tag "sharing[permissions][values]", "" -%>

<%="<div class='fieldWithErrors'>" if !@resource.errors.empty? and !@policy.valid? %>
<div class="fold">

  <div class="foldTitle">
    <%= help_icon("Here you can specify who can <b>see</b>#{', <b>download</b>' if @resource.is_downloadable?} and <b>edit</b> this #{@resource_type}.") -%>
    Sharing
  </div>

  <div class="foldContent" >

    <div class="box_infotext">
      <p>
        Here you can specify who can <b>view</b> the summary of<% if @resource.is_downloadable? %>, <b>get</b> access to the content of,<% end %> and <b>edit</b> the <%= @resource_type -%>.
        <%= link_to_function "More info " + expand_image, visual_effect(:toggle_blind, "more_sharing_info", :duration => 0.3) -%>
      </p>
      <div id="more_sharing_info" class="box_simple" style="display: none;">        
          You may:
        <ul style="padding-left:1em;">
          <li>Keep the <%= @resource_type -%> private, and only visible to yourself.</li>
          <li>Share within the selected projects and with all other users that are a member of a <%= Seek::Config.project_name %> project.</li>
          <% if try_block{@resource.can_publish?} %>
            <li>Share with the all visitors (including anonymous visitors with no login)</li>
          <% end %>
          <% if !disable_advanced_view%>
            <li>Define more fine-grained sharing in the <em>Advanced sharing</em>: you can share within your Project/Institution only,<br/> with specific individuals, or set up custom favourite groups for people you regularly need to share with.</li>
          <% end %>
        </ul>
      </div>
    </div>
    <br/>
    <style>
      span.additional_permissions {
        display:block;
        margin-left: 4em;
        font-weight: bold;
        color: red;
      }
    </style>

    <div id='simple sharing' class="sharing_box_form">
        <!-- private -->
        <p><label for="sharing_scope_<%= Policy::PRIVATE -%>">
            <input type="hidden" id='access_type_select_<%= Policy::PRIVATE -%>' name="sharing[access_type_<%= Policy::PRIVATE -%>]" value="<%= Policy::NO_ACCESS -%>">
            <input <%= 'checked="checked"' if @sharing_mode == Policy::PRIVATE %> id="sharing_scope_<%= Policy::PRIVATE -%>" name="sharing[sharing_scope]"
                                                                                  value="<%= Policy::PRIVATE -%>" type="radio" />
            - Keep this <%= @resource_type -%> private (only visible to you)
          </label>
          <%= additional_advanced_permissions_included @resource, Policy::PRIVATE -%>
        </p>

        <p style="font-weight: bold; margin-top: 0.5em;">Or share it with..</p>

        <!-- within your project ... and with all sysmo project members ...-->
        <p>
          <label>
            <input type="radio" <%= 'checked="checked"' if @sharing_mode == Policy::ALL_SYSMO_USERS -%> id="sharing_scope_<%= Policy::ALL_SYSMO_USERS -%>" name="sharing[sharing_scope]" value="<%= Policy::ALL_SYSMO_USERS -%>" />
            - Members of projects associated with this <%= @resource_type -%>:
          </label>
             <select name="sharing[your_proj_access_type]" id="sharing_your_proj_access_type">
                 <%= policy_selection_options([Policy::VISIBLE,Policy::ACCESSIBLE,Policy::EDITING,Policy::MANAGING], @resource, your_project_access_type(@policy, @resource) || default_projects_access_type) -%>
             </select>
             <br/>
            <span style="margin-left:10em;">... and all other project members:</span>
             <%= render :partial => "assets/sharing_form_access_type_dropdown", :locals => { :access_type_selector_for_scope => Policy::ALL_SYSMO_USERS,
               :sharing_scope => Policy::ALL_SYSMO_USERS, :access_type => (@resource.respond_to?(:policy) && @resource.policy.try(:sharing_scope)==Policy::ALL_SYSMO_USERS ? @access_mode : default_consortium_access_type), :access_type_options=>[Policy::NO_ACCESS,Policy::VISIBLE,Policy::ACCESSIBLE,Policy::EDITING] } -%>
             <%= additional_advanced_permissions_included @resource, Policy::ALL_SYSMO_USERS -%>
        </p>

        <!-- public -->
        <p>
          <label for="sharing_scope_<%= Policy::EVERYONE -%>">
            <input type="radio" <%= 'checked="checked"' if @sharing_mode == Policy::EVERYONE -%> id="sharing_scope_<%= Policy::EVERYONE -%>" name="sharing[sharing_scope]"
                   value="<%= Policy::EVERYONE -%>" <%= 'disabled="true"' if !disable_can_publish_check && @resource.respond_to?(:can_publish?) && !@resource.can_publish? -%>/>
            - All visitors (including anonymous visitors with no login):
          </label>
           <%= render :partial => "assets/sharing_form_access_type_dropdown", :locals => { :access_type_selector_for_scope => Policy::EVERYONE,
            :sharing_scope => @sharing_mode, :access_type => @access_mode } -%>
           <%= additional_advanced_permissions_included @resource, Policy::EVERYONE -%>
        </p>

    </div>

    <!-- some javascript to set the default permissions for new records -->
    <% if @resource.new_record? && @resource.errors.empty? -%>
        <script type="text/javascript">
          $("sharing_scope_<%= Policy::ALL_SYSMO_USERS-%>").checked=true;

        </script>
    <% end -%>

    <% if !disable_advanced_view %>
      <%= link_to_function "Advanced permissions " + expand_image, :class => 'advanced_sharing_link', :style => "display:" + (show_advanced_permissions ? 'none;' : 'block;'), :id =>'advanced_sharing_expand_image' do |page|
          page.visual_effect :toggle_blind, "advanced sharing", :duration => 0.5
          page["advanced_sharing_expand_image"].toggle
          page["advanced_sharing_collapse_image"].toggle
      end
      -%>
      <%= link_to_function "Advanced permissions " + collapse_image, :class => 'advanced_sharing_link', :style => "display:" + (show_advanced_permissions ? 'block;' : 'none;'), :id =>'advanced_sharing_collapse_image' do |page|
          page.visual_effect :toggle_blind, "advanced sharing", :duration => 0.5
          page["advanced_sharing_expand_image"].toggle
          page["advanced_sharing_collapse_image"].toggle
      end
      -%>
      <br/>

      <div id="advanced sharing" class='sharing_box_form' style="display:<%= show_advanced_permissions ? 'block;' : 'none;' -%>">
        <p style="font-weight: bold;">Additional fine-grained sharing permissions</p>

        <div id="specific_sharing" style="display:block; margin-top: 1em;">
          <div class="box_editing" style="padding-left: 1em; font-size: 93%;">
            <p style="color: #666666;">
              So far you have selected to share this <%= @resource_type -%> with:
            </p>

            <p id="shared_with_list" class="box_editing_inner" style="line-height: 1.5;">
              <span class="none_text" id="shared_with_text">Loading...</span>
            </p>

            <p style="margin-top: 1em;">
              Build up the list of people and groups to share with.
              Select from the options below and click "Add" to apply
              your choices and add collaborators to your current selection:
            </p>

            <!-- favourite groups -->
            <div class="fold" style="width: 70%; margin: 0.6em 0;">

              <div class="foldTitle">
                <%= image_tag icon_filename_for_key("spinner"), :id => "f_group_deleting_spinner", :alt=>"loading...", :title=>"loading...", :style => "display: none; vertical-align: middle; float: right;" -%>
                <%= help_icon("Here you can choose your favourite groups to share this #{@resource_type} with.") -%>
                Favourite Groups
              </div>

              <div class="foldContent" style="display: none; background-color: #F2F2F2;">
                <p style="margin: 1em 0 0 0; padding: 0; line-height: 1; text-align: center;">
                  <% favourite_groups = FavouriteGroup.get_all_without_blacklists_and_whitelists(current_user.id) -%>
                  <% f_group_select_options = (favourite_groups.blank? ? "<option value=\"\">You don't have any favourite groups</option>" : options_for_select(favourite_groups)) -%>

                  <%= select_tag "favourite_group_select", f_group_select_options, :style => "width: 82%; vertical-align: middle; margin-right: 0.4em;", :disabled => (favourite_groups.blank?) -%>

                  <%= link_to "Add", "", :id => "add_f_group_link", :style => "font-weight: bold; vertical-align: middle;", :disabled => (favourite_groups.blank?),
                              :onclick => "javascript: if($('favourite_group_select').disabled) return(false); addContributor('FavouriteGroup', $('favourite_group_select').options[$('favourite_group_select').selectedIndex].text, parseInt($('favourite_group_select').options[$('favourite_group_select').selectedIndex].value), #{Policy::DETERMINED_BY_GROUP}); return(false);" -%>
                </p>
                <ul style="text-align: left; margin: 1em 0 0.5em 3.2em;">
                  <li id="edit_f_group_li" style="display: <%= favourite_groups.blank? ? "none" : "block" -%>; list-style-type: disc; padding: 0;"><%= favourite_group_popup_link_action_edit(@resource.class.name) -%></li>
                  <li id="delete_f_group_li" style="display: <%= favourite_groups.blank? ? "none" : "block" -%>; list-style-type: disc; padding: 0;">
                    <%= link_to "Delete selected favourite group", delete_favourite_group_path(0), :onclick => "deleteSelectedFavouriteGroup(); return(false);" -%>
                  </li>
                  <li id="create_f_group_li" style="list-style-type: disc; padding: 0.5em 0 0 0;"><%= favourite_group_popup_link_action_new(@resource.class.name) -%></li>

                </ul>
              </div>
            </div>


            <!-- projects / institutions -->
            <div class="fold" style="width: 70%; margin: 0.6em 0;">

              <div class="foldTitle">
                <%= help_icon("Here you can choose projects, institutions and workgroups to share this #{@resource_type} with.") -%>
                Projects and Institutions
              </div>

              <div class="foldContent" style="display: none; background-color: #F2F2F2; padding-bottom: 1.3em;">
                <p style="margin: 0.6em 0; padding: 0; line-height: 1; font-weight: bold; text-align: center;">
                  <% right_arrow_image = icon_filename_for_key("arrow_right") -%>

                  <span class="note_text" id="proj_select_step_1">Step 1</span>
                  <%= image_tag right_arrow_image, :style => "vertical-align: middle; padding: 0 0.8em;" -%>

                  <span class="note_text_disabled" id="proj_select_step_2">Step 2</span>
                  <%= image_tag right_arrow_image, :style => "vertical-align: middle; padding: 0 0.8em;" -%>

                  <span class="note_text_disabled" id="proj_select_step_3">Step 3</span>
                </p>

                <center>
                  <div style="width: 95%; text-align: left; margin-top: 2em;">
                    <input type="hidden" id="proj_select_step_index" value="1">

                    <!-- step 1 -->
                    <div id="proj_select_step_div_1" style="display: block; margin: 0; padding: 0;">
                      <%= image_tag icon_filename_for_key("spinner"), :id => "institutions_loading_spinner", :alt=>"loading...", :title=>"loading...", :style => "display: none; vertical-align: middle; float: right;" -%>
                      <span class="note_text" style="line-height: 1.5;">Step 1:</span> Select a project
                      <%= select("proj_project", "select",
                                 Project.find(:all).collect { |p| [p.name, p.id] },
                                 {:include_blank => 'All Projects @ Institution (from Step 2)'}, {:style => "width: 100%; vertical-align: middle; margin: 0.3em 0;"}) -%>
                    </div>

                    <!-- step 2 -->
                    <div id="proj_select_step_div_2" style="display: none; margin: 0; padding: 0;">
                      <span class="note_text" style="line-height: 1.5;">Step 2:</span> Select scope of the project
                      <%= select_tag("proj_institution_select", nil, {:style => "width: 100%; vertical-align: middle; margin: 0.3em 0;"}) -%>
                    </div>

                    <!-- step 3 -->
                    <div id="proj_select_step_div_3" style="display: none; margin: 0; padding: 0;">
                      <span class="note_text" style="line-height: 1.5;">Step 3:</span> Choose access rights, review and
                      submit

                      <select name="proj_access_type_select" id="proj_access_type_select" onchange="javascript: replaceReviewWorkGroupURL();" style="width: 100%; vertical-align: middle; margin: 0.3em 0;">
                        <%= policy_selection_options [Policy::NO_ACCESS, Policy::VISIBLE, Policy::ACCESSIBLE, Policy::EDITING, Policy::MANAGING], @resource -%>
                      </select>
                    </div>


                    <p style="margin: 0; padding: 0.3em 0 0 0; line-height: 1; font-weight: bold; text-align: right;">
                      <span id="proj_select_prev_link" style="display: none; float: left;">
                        <%= link_to "< Previous step", "", :onclick => "javascript: projectInstitutionStepAction(-1); return(false);", :style => "font-weight: bold;" -%>
                      </span>
                      <span id="proj_select_next_link" style="display: inline; float: right;">
                        <%= link_to "Next step >", "", :onclick => "javascript: projectInstitutionStepAction(1); return(false);", :style => "font-weight: bold;" -%>
                      </span>

                    <div id="proj_select_add_link" style="display: none; float: right;">
                      <ul style="margin-left: 1.2em; text-align: left;">
                        <li style="list-style-type: disc; padding: 0.3em 0;">
                          <%= link_to "Add immediately", "", :onclick => "javascript: addProjectInstitution(); return(false);", :style => "font-weight: bold; padding: 0;" -%>
                        </li>
                        <li style="list-style-type: disc; padding: 0;">
                          <div id="work_group_parent_span"><%= workgroup_member_review_popup_link(@resource.class.name) -%></div>
                        </li>
                      </ul>
                    </div>
                    </p>
                    <div class="clearer"></div>
                  </div>
                </center>
              </div>
            </div>

            <!-- individual people -->
            <div class="fold" style="width: 70%; margin: 0.6em 0;">

              <div class="foldTitle">
                <%= help_icon("Here you can specify individual people to share this #{@resource_type} with.") -%>
                Individual People
              </div>

              <div class="foldContent" style="display: none; background-color: #F2F2F2; padding-bottom: 1.3em;">
                <div id="facebook" class="clearfix">

                  <p style="text-align: justify;">
                    Please type names of people to share this <%= @resource_type -%> with into the box below -
                    suggestions will be displayed as you type.
                    Select access rights from drop-down menu; these will be applied to all chosen people.
                    Clicking "Add" will add selected people to the list.
                  </p>

                  <table>
                    <tr>
                      <td class="box_editing_inner">
                        <div tabindex="-1" id="ids" class="clearfix tokenizer" onclick="$('ip_autocomplete_input').focus();" style="width: 340px;">
                          <span class="tokenizer_stretcher">^_^</span><span class="tab_stop"><input type="text" id="ip_hidden_input" tabindex="-1"></span>

                          <div id="ip_autocomplete_display" class="tokenizer_input">
                            <input type="text" size="1" tabindex="" id="ip_autocomplete_input"/>
                          </div>
                        </div>
                        <div id="ip_autocomplete_populate" class="clearfix autocomplete typeahead_list" style="width: 343px; height: auto; overflow-y: hidden;display:none">
                          <div class="typeahead_message">Type the name of a friend, friend list, or email address</div>
                        </div>

                        <select name="individual_people_access_type_select" id="individual_people_access_type_select" style="width: 344px; vertical-align: middle; margin-top: 0.3em;">
                          <%= policy_selection_options nil, @resource -%>
                        </select>
                      </td>

                      <td style="padding-left: 0.7em; vertical-align: middle;">
                        <span style="font-weight: bold;"><%= link_to "Add", "", :onclick => "javascript: addIndividualPeople(); return(false);" -%></span>
                      </td>
                    </tr>
                  </table>
                </div>


                <script type="text/javascript">
                    var people_list = <%= @all_people_as_json -%>;
                    var prepopulate_with = [];

                    var individual_people_autocompleter = new Autocompleter.LocalAdvanced(
                            individual_people_autocompleter_id, 'ip_autocomplete_input', 'ip_autocomplete_display', 'ip_autocomplete_populate', people_list, prepopulate_with, {
                                frequency: 0.1,
                                updateElement: addAction,
                                search_field: "name",
                                hint_field: "email",
                                id_field: "id",
                                validation_type: "only_suggested"
                            });
                    var hidden_input = new HiddenInput('ip_hidden_input', individual_people_autocompleter);

                    autocompleters[individual_people_autocompleter_id] = individual_people_autocompleter;
                </script>
              </div>
            </div>

          </div>
        </div>
        <br/>

      </div>
  <% end %>
  </div>
</div>
<%="</div>" if !@resource.errors.empty? and !@policy.valid? %>

<script type="text/javascript">
  init_sharing();

  GET_INSTITUTIONS_LINK = '<%= request_institutions_projects_path -%>';
  GET_ALL_INSTITUTIONS_LINK = '<%= request_all_institutions_path -%>';

  CREATE_FAVOURITE_GROUP_LINK = '<%= create_favourite_group_path -%>';
  UPDATE_FAVOURITE_GROUP_LINK = '<%= update_favourite_group_path -%>';

  REVIEW_WORK_GROUP_LINK = '<%= review_work_group_path("type", "id", "access_type") -%>';

<% if show_advanced_permissions -%>
    <% @policy.permissions.each do |p| -%>
      <% unless p.marked_for_destruction? %>
          <% case p.contributor_type; when "FavouriteGroup", "Person", "Project", "Institution", "WorkGroup" -%>
            <% unless p.contributor_type == "FavouriteGroup" && [FavouriteGroup::WHITELIST_NAME, FavouriteGroup::BLACKLIST_NAME].include?(p.contributor.name) -%>
                if('<%= p.contributor_type -%>' in permissions_for_set)
                permissions_for_set['<%= p.contributor_type -%>']++;
                else {
                  permissions_for_set['<%= p.contributor_type -%>'] = 0;
                  permission_settings['<%= p.contributor_type -%>'] = new Array();
                }
              <% allow_removal=true -%>
              <% if p.contributor_type == "Person" -%>
                <%
                contributor_name = (p.contributor.first_name + " " + p.contributor.last_name)
                allow_removal = !prevent_manager_removal(@resource,p) if p.access_type==Policy::MANAGING
                -%>
              <% elsif p.contributor_type == "WorkGroup" -%>
                <% contributor_name = p.contributor.project.name + " @ " + p.contributor.institution.name -%>
              <% else -%>
                <% contributor_name = p.contributor.name -%>
              <% end -%>
                // add current values into the associative array of permissions:
                // first index is the category of contributor type of the permission, the second - consecutive
                // number of occurrences of permissions for such type of contributor
                permission_settings['<%= p.contributor_type -%>'][permissions_for_set['<%= p.contributor_type -%>']] =
                  ['<%= contributor_name -%>', <%= p.contributor_id -%>, <%= p.access_type -%>, <%= allow_removal -%> ];
            <% end -%>
          <% end -%>
      <% end -%>
    <% end -%>
<% end -%>
<% if !disable_advanced_view -%>
  updateCustomSharingSettings();
<% end %>
</script>
<commit_msg>remove code to set a default policy in the view<commit_after><%
   object ||= nil
   set_parameters_for_sharing_form object
   disable_advanced_view ||= nil
   disable_can_publish_check ||= false
   show_advanced_permissions = !@resource.respond_to?(:has_advanced_permissions?) || @resource.has_advanced_permissions?
   default_projects_access_type = @resource.is_asset? ? Policy::ACCESSIBLE : Policy::EDITING
   default_consortium_access_type = Policy::VISIBLE
%>
<%# initialization: required to keep javascript independent of the access type codes, to allow the use the constants instead -%>
<%= render :partial=>"assets/sharing_constants" %>


<%# this hidden input will submit all permission data with the form -%>
<%= hidden_field_tag "sharing[permissions][contributor_types]", "" -%>
<%= hidden_field_tag "sharing[permissions][values]", "" -%>

<%="<div class='fieldWithErrors'>" if !@resource.errors.empty? and !@policy.valid? %>
<div class="fold">

  <div class="foldTitle">
    <%= help_icon("Here you can specify who can <b>see</b>#{', <b>download</b>' if @resource.is_downloadable?} and <b>edit</b> this #{@resource_type}.") -%>
    Sharing
  </div>

  <div class="foldContent" >

    <div class="box_infotext">
      <p>
        Here you can specify who can <b>view</b> the summary of<% if @resource.is_downloadable? %>, <b>get</b> access to the content of,<% end %> and <b>edit</b> the <%= @resource_type -%>.
        <%= link_to_function "More info " + expand_image, visual_effect(:toggle_blind, "more_sharing_info", :duration => 0.3) -%>
      </p>
      <div id="more_sharing_info" class="box_simple" style="display: none;">        
          You may:
        <ul style="padding-left:1em;">
          <li>Keep the <%= @resource_type -%> private, and only visible to yourself.</li>
          <li>Share within the selected projects and with all other users that are a member of a <%= Seek::Config.project_name %> project.</li>
          <% if try_block{@resource.can_publish?} %>
            <li>Share with the all visitors (including anonymous visitors with no login)</li>
          <% end %>
          <% if !disable_advanced_view%>
            <li>Define more fine-grained sharing in the <em>Advanced sharing</em>: you can share within your Project/Institution only,<br/> with specific individuals, or set up custom favourite groups for people you regularly need to share with.</li>
          <% end %>
        </ul>
      </div>
    </div>
    <br/>
    <style>
      span.additional_permissions {
        display:block;
        margin-left: 4em;
        font-weight: bold;
        color: red;
      }
    </style>

    <div id='simple sharing' class="sharing_box_form">
        <!-- private -->
        <p><label for="sharing_scope_<%= Policy::PRIVATE -%>">
            <input type="hidden" id='access_type_select_<%= Policy::PRIVATE -%>' name="sharing[access_type_<%= Policy::PRIVATE -%>]" value="<%= Policy::NO_ACCESS -%>">
            <input <%= 'checked="checked"' if @sharing_mode == Policy::PRIVATE %> id="sharing_scope_<%= Policy::PRIVATE -%>" name="sharing[sharing_scope]"
                                                                                  value="<%= Policy::PRIVATE -%>" type="radio" />
            - Keep this <%= @resource_type -%> private (only visible to you)
          </label>
          <%= additional_advanced_permissions_included @resource, Policy::PRIVATE -%>
        </p>

        <p style="font-weight: bold; margin-top: 0.5em;">Or share it with..</p>

        <!-- within your project ... and with all sysmo project members ...-->
        <p>
          <label>
            <input type="radio" <%= 'checked="checked"' if @sharing_mode == Policy::ALL_SYSMO_USERS -%> id="sharing_scope_<%= Policy::ALL_SYSMO_USERS -%>" name="sharing[sharing_scope]" value="<%= Policy::ALL_SYSMO_USERS -%>" />
            - Members of projects associated with this <%= @resource_type -%>:
          </label>
             <select name="sharing[your_proj_access_type]" id="sharing_your_proj_access_type">
                 <%= policy_selection_options([Policy::VISIBLE,Policy::ACCESSIBLE,Policy::EDITING,Policy::MANAGING], @resource, your_project_access_type(@policy, @resource) || default_projects_access_type) -%>
             </select>
             <br/>
            <span style="margin-left:10em;">... and all other project members:</span>
             <%= render :partial => "assets/sharing_form_access_type_dropdown", :locals => { :access_type_selector_for_scope => Policy::ALL_SYSMO_USERS,
               :sharing_scope => Policy::ALL_SYSMO_USERS, :access_type => (@resource.respond_to?(:policy) && @resource.policy.try(:sharing_scope)==Policy::ALL_SYSMO_USERS ? @access_mode : default_consortium_access_type), :access_type_options=>[Policy::NO_ACCESS,Policy::VISIBLE,Policy::ACCESSIBLE,Policy::EDITING] } -%>
             <%= additional_advanced_permissions_included @resource, Policy::ALL_SYSMO_USERS -%>
        </p>

        <!-- public -->
        <p>
          <label for="sharing_scope_<%= Policy::EVERYONE -%>">
            <input type="radio" <%= 'checked="checked"' if @sharing_mode == Policy::EVERYONE -%> id="sharing_scope_<%= Policy::EVERYONE -%>" name="sharing[sharing_scope]"
                   value="<%= Policy::EVERYONE -%>" <%= 'disabled="true"' if !disable_can_publish_check && @resource.respond_to?(:can_publish?) && !@resource.can_publish? -%>/>
            - All visitors (including anonymous visitors with no login):
          </label>
           <%= render :partial => "assets/sharing_form_access_type_dropdown", :locals => { :access_type_selector_for_scope => Policy::EVERYONE,
            :sharing_scope => @sharing_mode, :access_type => @access_mode } -%>
           <%= additional_advanced_permissions_included @resource, Policy::EVERYONE -%>
        </p>

    </div>

    <% if !disable_advanced_view %>
      <%= link_to_function "Advanced permissions " + expand_image, :class => 'advanced_sharing_link', :style => "display:" + (show_advanced_permissions ? 'none;' : 'block;'), :id =>'advanced_sharing_expand_image' do |page|
          page.visual_effect :toggle_blind, "advanced sharing", :duration => 0.5
          page["advanced_sharing_expand_image"].toggle
          page["advanced_sharing_collapse_image"].toggle
      end
      -%>
      <%= link_to_function "Advanced permissions " + collapse_image, :class => 'advanced_sharing_link', :style => "display:" + (show_advanced_permissions ? 'block;' : 'none;'), :id =>'advanced_sharing_collapse_image' do |page|
          page.visual_effect :toggle_blind, "advanced sharing", :duration => 0.5
          page["advanced_sharing_expand_image"].toggle
          page["advanced_sharing_collapse_image"].toggle
      end
      -%>
      <br/>

      <div id="advanced sharing" class='sharing_box_form' style="display:<%= show_advanced_permissions ? 'block;' : 'none;' -%>">
        <p style="font-weight: bold;">Additional fine-grained sharing permissions</p>

        <div id="specific_sharing" style="display:block; margin-top: 1em;">
          <div class="box_editing" style="padding-left: 1em; font-size: 93%;">
            <p style="color: #666666;">
              So far you have selected to share this <%= @resource_type -%> with:
            </p>

            <p id="shared_with_list" class="box_editing_inner" style="line-height: 1.5;">
              <span class="none_text" id="shared_with_text">Loading...</span>
            </p>

            <p style="margin-top: 1em;">
              Build up the list of people and groups to share with.
              Select from the options below and click "Add" to apply
              your choices and add collaborators to your current selection:
            </p>

            <!-- favourite groups -->
            <div class="fold" style="width: 70%; margin: 0.6em 0;">

              <div class="foldTitle">
                <%= image_tag icon_filename_for_key("spinner"), :id => "f_group_deleting_spinner", :alt=>"loading...", :title=>"loading...", :style => "display: none; vertical-align: middle; float: right;" -%>
                <%= help_icon("Here you can choose your favourite groups to share this #{@resource_type} with.") -%>
                Favourite Groups
              </div>

              <div class="foldContent" style="display: none; background-color: #F2F2F2;">
                <p style="margin: 1em 0 0 0; padding: 0; line-height: 1; text-align: center;">
                  <% favourite_groups = FavouriteGroup.get_all_without_blacklists_and_whitelists(current_user.id) -%>
                  <% f_group_select_options = (favourite_groups.blank? ? "<option value=\"\">You don't have any favourite groups</option>" : options_for_select(favourite_groups)) -%>

                  <%= select_tag "favourite_group_select", f_group_select_options, :style => "width: 82%; vertical-align: middle; margin-right: 0.4em;", :disabled => (favourite_groups.blank?) -%>

                  <%= link_to "Add", "", :id => "add_f_group_link", :style => "font-weight: bold; vertical-align: middle;", :disabled => (favourite_groups.blank?),
                              :onclick => "javascript: if($('favourite_group_select').disabled) return(false); addContributor('FavouriteGroup', $('favourite_group_select').options[$('favourite_group_select').selectedIndex].text, parseInt($('favourite_group_select').options[$('favourite_group_select').selectedIndex].value), #{Policy::DETERMINED_BY_GROUP}); return(false);" -%>
                </p>
                <ul style="text-align: left; margin: 1em 0 0.5em 3.2em;">
                  <li id="edit_f_group_li" style="display: <%= favourite_groups.blank? ? "none" : "block" -%>; list-style-type: disc; padding: 0;"><%= favourite_group_popup_link_action_edit(@resource.class.name) -%></li>
                  <li id="delete_f_group_li" style="display: <%= favourite_groups.blank? ? "none" : "block" -%>; list-style-type: disc; padding: 0;">
                    <%= link_to "Delete selected favourite group", delete_favourite_group_path(0), :onclick => "deleteSelectedFavouriteGroup(); return(false);" -%>
                  </li>
                  <li id="create_f_group_li" style="list-style-type: disc; padding: 0.5em 0 0 0;"><%= favourite_group_popup_link_action_new(@resource.class.name) -%></li>

                </ul>
              </div>
            </div>


            <!-- projects / institutions -->
            <div class="fold" style="width: 70%; margin: 0.6em 0;">

              <div class="foldTitle">
                <%= help_icon("Here you can choose projects, institutions and workgroups to share this #{@resource_type} with.") -%>
                Projects and Institutions
              </div>

              <div class="foldContent" style="display: none; background-color: #F2F2F2; padding-bottom: 1.3em;">
                <p style="margin: 0.6em 0; padding: 0; line-height: 1; font-weight: bold; text-align: center;">
                  <% right_arrow_image = icon_filename_for_key("arrow_right") -%>

                  <span class="note_text" id="proj_select_step_1">Step 1</span>
                  <%= image_tag right_arrow_image, :style => "vertical-align: middle; padding: 0 0.8em;" -%>

                  <span class="note_text_disabled" id="proj_select_step_2">Step 2</span>
                  <%= image_tag right_arrow_image, :style => "vertical-align: middle; padding: 0 0.8em;" -%>

                  <span class="note_text_disabled" id="proj_select_step_3">Step 3</span>
                </p>

                <center>
                  <div style="width: 95%; text-align: left; margin-top: 2em;">
                    <input type="hidden" id="proj_select_step_index" value="1">

                    <!-- step 1 -->
                    <div id="proj_select_step_div_1" style="display: block; margin: 0; padding: 0;">
                      <%= image_tag icon_filename_for_key("spinner"), :id => "institutions_loading_spinner", :alt=>"loading...", :title=>"loading...", :style => "display: none; vertical-align: middle; float: right;" -%>
                      <span class="note_text" style="line-height: 1.5;">Step 1:</span> Select a project
                      <%= select("proj_project", "select",
                                 Project.find(:all).collect { |p| [p.name, p.id] },
                                 {:include_blank => 'All Projects @ Institution (from Step 2)'}, {:style => "width: 100%; vertical-align: middle; margin: 0.3em 0;"}) -%>
                    </div>

                    <!-- step 2 -->
                    <div id="proj_select_step_div_2" style="display: none; margin: 0; padding: 0;">
                      <span class="note_text" style="line-height: 1.5;">Step 2:</span> Select scope of the project
                      <%= select_tag("proj_institution_select", nil, {:style => "width: 100%; vertical-align: middle; margin: 0.3em 0;"}) -%>
                    </div>

                    <!-- step 3 -->
                    <div id="proj_select_step_div_3" style="display: none; margin: 0; padding: 0;">
                      <span class="note_text" style="line-height: 1.5;">Step 3:</span> Choose access rights, review and
                      submit

                      <select name="proj_access_type_select" id="proj_access_type_select" onchange="javascript: replaceReviewWorkGroupURL();" style="width: 100%; vertical-align: middle; margin: 0.3em 0;">
                        <%= policy_selection_options [Policy::NO_ACCESS, Policy::VISIBLE, Policy::ACCESSIBLE, Policy::EDITING, Policy::MANAGING], @resource -%>
                      </select>
                    </div>


                    <p style="margin: 0; padding: 0.3em 0 0 0; line-height: 1; font-weight: bold; text-align: right;">
                      <span id="proj_select_prev_link" style="display: none; float: left;">
                        <%= link_to "< Previous step", "", :onclick => "javascript: projectInstitutionStepAction(-1); return(false);", :style => "font-weight: bold;" -%>
                      </span>
                      <span id="proj_select_next_link" style="display: inline; float: right;">
                        <%= link_to "Next step >", "", :onclick => "javascript: projectInstitutionStepAction(1); return(false);", :style => "font-weight: bold;" -%>
                      </span>

                    <div id="proj_select_add_link" style="display: none; float: right;">
                      <ul style="margin-left: 1.2em; text-align: left;">
                        <li style="list-style-type: disc; padding: 0.3em 0;">
                          <%= link_to "Add immediately", "", :onclick => "javascript: addProjectInstitution(); return(false);", :style => "font-weight: bold; padding: 0;" -%>
                        </li>
                        <li style="list-style-type: disc; padding: 0;">
                          <div id="work_group_parent_span"><%= workgroup_member_review_popup_link(@resource.class.name) -%></div>
                        </li>
                      </ul>
                    </div>
                    </p>
                    <div class="clearer"></div>
                  </div>
                </center>
              </div>
            </div>

            <!-- individual people -->
            <div class="fold" style="width: 70%; margin: 0.6em 0;">

              <div class="foldTitle">
                <%= help_icon("Here you can specify individual people to share this #{@resource_type} with.") -%>
                Individual People
              </div>

              <div class="foldContent" style="display: none; background-color: #F2F2F2; padding-bottom: 1.3em;">
                <div id="facebook" class="clearfix">

                  <p style="text-align: justify;">
                    Please type names of people to share this <%= @resource_type -%> with into the box below -
                    suggestions will be displayed as you type.
                    Select access rights from drop-down menu; these will be applied to all chosen people.
                    Clicking "Add" will add selected people to the list.
                  </p>

                  <table>
                    <tr>
                      <td class="box_editing_inner">
                        <div tabindex="-1" id="ids" class="clearfix tokenizer" onclick="$('ip_autocomplete_input').focus();" style="width: 340px;">
                          <span class="tokenizer_stretcher">^_^</span><span class="tab_stop"><input type="text" id="ip_hidden_input" tabindex="-1"></span>

                          <div id="ip_autocomplete_display" class="tokenizer_input">
                            <input type="text" size="1" tabindex="" id="ip_autocomplete_input"/>
                          </div>
                        </div>
                        <div id="ip_autocomplete_populate" class="clearfix autocomplete typeahead_list" style="width: 343px; height: auto; overflow-y: hidden;display:none">
                          <div class="typeahead_message">Type the name of a friend, friend list, or email address</div>
                        </div>

                        <select name="individual_people_access_type_select" id="individual_people_access_type_select" style="width: 344px; vertical-align: middle; margin-top: 0.3em;">
                          <%= policy_selection_options nil, @resource -%>
                        </select>
                      </td>

                      <td style="padding-left: 0.7em; vertical-align: middle;">
                        <span style="font-weight: bold;"><%= link_to "Add", "", :onclick => "javascript: addIndividualPeople(); return(false);" -%></span>
                      </td>
                    </tr>
                  </table>
                </div>


                <script type="text/javascript">
                    var people_list = <%= @all_people_as_json -%>;
                    var prepopulate_with = [];

                    var individual_people_autocompleter = new Autocompleter.LocalAdvanced(
                            individual_people_autocompleter_id, 'ip_autocomplete_input', 'ip_autocomplete_display', 'ip_autocomplete_populate', people_list, prepopulate_with, {
                                frequency: 0.1,
                                updateElement: addAction,
                                search_field: "name",
                                hint_field: "email",
                                id_field: "id",
                                validation_type: "only_suggested"
                            });
                    var hidden_input = new HiddenInput('ip_hidden_input', individual_people_autocompleter);

                    autocompleters[individual_people_autocompleter_id] = individual_people_autocompleter;
                </script>
              </div>
            </div>

          </div>
        </div>
        <br/>

      </div>
  <% end %>
  </div>
</div>
<%="</div>" if !@resource.errors.empty? and !@policy.valid? %>

<script type="text/javascript">
  init_sharing();

  GET_INSTITUTIONS_LINK = '<%= request_institutions_projects_path -%>';
  GET_ALL_INSTITUTIONS_LINK = '<%= request_all_institutions_path -%>';

  CREATE_FAVOURITE_GROUP_LINK = '<%= create_favourite_group_path -%>';
  UPDATE_FAVOURITE_GROUP_LINK = '<%= update_favourite_group_path -%>';

  REVIEW_WORK_GROUP_LINK = '<%= review_work_group_path("type", "id", "access_type") -%>';

<% if show_advanced_permissions -%>
    <% @policy.permissions.each do |p| -%>
      <% unless p.marked_for_destruction? %>
          <% case p.contributor_type; when "FavouriteGroup", "Person", "Project", "Institution", "WorkGroup" -%>
            <% unless p.contributor_type == "FavouriteGroup" && [FavouriteGroup::WHITELIST_NAME, FavouriteGroup::BLACKLIST_NAME].include?(p.contributor.name) -%>
                if('<%= p.contributor_type -%>' in permissions_for_set)
                permissions_for_set['<%= p.contributor_type -%>']++;
                else {
                  permissions_for_set['<%= p.contributor_type -%>'] = 0;
                  permission_settings['<%= p.contributor_type -%>'] = new Array();
                }
              <% allow_removal=true -%>
              <% if p.contributor_type == "Person" -%>
                <%
                contributor_name = (p.contributor.first_name + " " + p.contributor.last_name)
                allow_removal = !prevent_manager_removal(@resource,p) if p.access_type==Policy::MANAGING
                -%>
              <% elsif p.contributor_type == "WorkGroup" -%>
                <% contributor_name = p.contributor.project.name + " @ " + p.contributor.institution.name -%>
              <% else -%>
                <% contributor_name = p.contributor.name -%>
              <% end -%>
                // add current values into the associative array of permissions:
                // first index is the category of contributor type of the permission, the second - consecutive
                // number of occurrences of permissions for such type of contributor
                permission_settings['<%= p.contributor_type -%>'][permissions_for_set['<%= p.contributor_type -%>']] =
                  ['<%= contributor_name -%>', <%= p.contributor_id -%>, <%= p.access_type -%>, <%= allow_removal -%> ];
            <% end -%>
          <% end -%>
      <% end -%>
    <% end -%>
<% end -%>
<% if !disable_advanced_view -%>
  updateCustomSharingSettings();
<% end %>
</script>

{'fraction_non_alphanumeric': 0.14901734104046244, 'fraction_numerical': 0.008, 'mean_word_length': 2.3241872261932213, 'pattern_counts': {'":': 0, '<': 639, '<?xml version=': 0, '>': 735, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '231320', 'n_tokens_mistral': 13406, 'n_tokens_neox': 12085, 'n_words': 2662}