<commit_before><%
   select_truncate_length=120
   projects = Project.all
   info_text = "Here you can customize your subscriptions to projects. You will be informed by email of resources that have been created or updated within the projects that you have subscribed to, during the time period you specified. You will only be notified of items that you are authorized to view. By default, your subscription is for weekly notifications about activity in your own projects."
%>
<div class="fold">
  <div class="foldTitle">
    <%= help_icon(info_text) -%>
    Subscriptions
  </div>
  <div class="foldContent">
    <span class="none_text"> The following projects are subscribed by you, you may click it to view or edit the subscription: </span>
    <ul id="project_subscription_list">
      <% project_subscriptions = @person.project_subscriptions %>
      <span class="none_text" id="no_project_text" style="display: <%= project_subscriptions.empty? ? 'block' : 'none' %>">None</span>
      <% project_subscriptions.each do |ps| %>
          <li id="<%= ps.project_id %>_li">
            <%= link_to_function ps.project.title, "$('select_project_subscription').value = #{ps.project.id};show_project_subscription();$('select_project_subscription').value =0;return false;" %>
          </li>
      <% end %>
    </ul>
    <br/>
     <span class="none_text"> You can subscribe other projects: </span> <br/>
    <%= select_tag :select_project_subscription,
                   options_for_select([["Select Project ...", 0]]|projects.collect { |p| [truncate(h(p.title), :length=>select_truncate_length), p.id] }),
                   {:style=>"width:90%",
                    :onchange=>"show_project_subscription();return(false);"} -%>

    <br/>

    <% project_subscriptions_with_unsubscribed = projects.map do |proj|
        @person.project_subscriptions.detect { |ps| ps.project == proj } || ProjectSubscription.new(:project => proj, :person => @person).tap(&:mark_for_destruction)
    end %>
    <% f.fields_for :project_subscriptions, project_subscriptions_with_unsubscribed do |sub_form| %>
        <% project_subscription = sub_form.object %>
        <div id="subscription<%= project_subscription.project_id %>" style="display:none;">
          <fieldset>
            <%= sub_form.hidden_field :id unless sub_form.object.new_record? %>
            <legend> Project: <%= project_subscription.project.name %></legend>
            <%= sub_form.hidden_field :project_id %>
            <br/>

            Check to subscribe: <%= sub_form.check_box :_destroy, {:checked => !sub_form.object.marked_for_destruction?,:onclick=>"updateSubscribedProjectsList(this,#{project_subscription.project_id},'#{project_subscription.project.title}');"}, 0, 1 %>
            <br/>
            <p> Would you like to receive emails:
              <% Subscription::FREQUENCIES.each do |freq| %>
                  <%= sub_form.radio_button :frequency, freq %> <%= "#{freq.capitalize}" %>
              <% end %>

            </p>
          </fieldset>
        </div>
    <% end %>
  </div>
</div>

<script type="text/javascript">

    var project_subscription = "subscription";

    function swap_subscription(old_div_id, new_div_id) {
        var old_div = $(old_div_id);
        if (old_div && old_div.style.display == "block") {
            old_div.style.display = "none";
        }
        var new_div = $(new_div_id);
        if (new_div && new_div.style.display == "none") {
            new_div.style.display = "block";
        }
    }

    function show_project_subscription() {
        var new_project_subscription = "subscription" + $F('select_project_subscription');
        swap_subscription(project_subscription, new_project_subscription);
        project_subscription = new_project_subscription;
    }

    function updateSubscribedProjectsList(element, project_id, project_title) {
        var child_id = project_id + '_li';
        var child = $(child_id);
        if (element.checked) {
            if (!child) {
                child = document.createElement('LI');<commit_msg>only send project subscription fields the user has examined, otherwise many extra fields are sent with the request<commit_after><%
   select_truncate_length=120
   projects = Project.all
   info_text = "Here you can customize your subscriptions to projects. You will be informed by email of resources that have been created or updated within the projects that you have subscribed to, during the time period you specified. You will only be notified of items that you are authorized to view. By default, your subscription is for weekly notifications about activity in your own projects."
%>
<div class="fold">
  <div class="foldTitle">
    <%= help_icon(info_text) -%>
    Subscriptions
  </div>
  <div class="foldContent">
    <span class="none_text"> The following projects are subscribed by you, you may click it to view or edit the subscription: </span>
    <ul id="project_subscription_list">
      <% project_subscriptions = @person.project_subscriptions %>
      <span class="none_text" id="no_project_text" style="display: <%= project_subscriptions.empty? ? 'block' : 'none' %>">None</span>
      <% project_subscriptions.each do |ps| %>
          <li id="<%= ps.project_id %>_li">
            <%= link_to_function ps.project.title, "$('select_project_subscription').value = #{ps.project.id};show_project_subscription();$('select_project_subscription').value =0;return false;" %>
          </li>
      <% end %>
    </ul>
    <br/>
     <span class="none_text"> You can subscribe other projects: </span> <br/>
    <%= select_tag :select_project_subscription,
                   options_for_select([["Select Project ...", 0]]|projects.collect { |p| [truncate(h(p.title), :length=>select_truncate_length), p.id] }),
                   {:style=>"width:90%",
                    :onchange=>"show_project_subscription();return(false);"} -%>

    <br/>

    <% project_subscriptions_with_unsubscribed = projects.map do |proj|
        @person.project_subscriptions.detect { |ps| ps.project == proj } || ProjectSubscription.new(:project => proj, :person => @person).tap(&:mark_for_destruction)
    end %>
    <% f.fields_for :project_subscriptions, project_subscriptions_with_unsubscribed do |sub_form| %>
        <% project_subscription = sub_form.object %>
        <div id="subscription<%= project_subscription.project_id %>" style="display:none;">
          <fieldset>
            <%= sub_form.hidden_field :id unless sub_form.object.new_record? %>
            <legend> Project: <%= project_subscription.project.name %></legend>
            <%= sub_form.hidden_field :project_id %>
            <br/>

            Check to subscribe: <%= sub_form.check_box :_destroy, {:checked => !sub_form.object.marked_for_destruction?,:onclick=>"updateSubscribedProjectsList(this,#{project_subscription.project_id},'#{project_subscription.project.title}');"}, 0, 1 %>
            <br/>
            <p> Would you like to receive emails:
              <% Subscription::FREQUENCIES.each do |freq| %>
                  <%= sub_form.radio_button :frequency, freq %> <%= "#{freq.capitalize}" %>
              <% end %>

            </p>
          </fieldset>
        </div>
    <% end %>
  </div>
</div>

<script type="text/javascript">

    <% project_subscriptions_with_unsubscribed.map(&:id).each do |sub_id| %>
      $$('#subscription<%= sub_id %> input').invoke('disable');
    <% end %>

    var project_subscription = "subscription";

    function swap_subscription(old_div_id, new_div_id) {
        var old_div = $(old_div_id);
        if (old_div && old_div.style.display == "block") {
            old_div.style.display = "none";
        }
        var new_div = $(new_div_id);
        if (new_div && new_div.style.display == "none") {
            new_div.style.display = "block";
            new_div.select('input').invoke('enable');
        }
    }

    function show_project_subscription() {
        var new_project_subscription = "subscription" + $F('select_project_subscription');
        swap_subscription(project_subscription, new_project_subscription);
        project_subscription = new_project_subscription;
    }

    function updateSubscribedProjectsList(element, project_id, project_title) {
        var child_id = project_id + '_li';
        var child = $(child_id);
        if (element.checked) {
            if (!child) {
                child = document.createElement('LI');
{'fraction_non_alphanumeric': 0.135400639128891, 'fraction_numerical': 0.0021304296366433896, 'mean_word_length': 3.164613109906358, 'pattern_counts': {'":': 0, '<': 110, '<?xml version=': 0, '>': 124, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7045581', 'n_tokens_mistral': 2541, 'n_tokens_neox': 2434, 'n_words': 558}