<commit_before><div class="panel panel-default outer-panel panel-info">
  <!-- Default panel contents -->
  <div class="panel-heading"><h3 class="panel-title">Campaign Detail</h3></div>
  <div class="panel-body">
    <dl class="dl-horizontal">
      <dt>Name</dt>
      <dd><%= @campaign.name %></dd>
      <dt>Deadline</dt>
      <dd><%= @campaign.deadline %></dd>
      <dt>Ready for Donations</dt>
      <dd><input type=checkbox disabled <%= @campaign.ready_for_donations ? 'checked' : '' %> /></dd>
      <dt>Address</dt>
      <dd><address><%= h(@campaign.address).gsub(/\n/, '<br/>').html_safe %></address></dd>
      <dt>Can Edit Wish Lists</dt>
      <dd><input type=checkbox disabled <%= @campaign.can_edit_wishlists ? 'checked' : '' %> /></dd>
      <dt>Book Limit</dt>
      <dd><%= @campaign.book_limit %></dd>
    </dl>
  </div>

  <div class="panel panel-default table-condensed">
    <!-- Default panel contents -->
    <div class="panel-heading"><h3 class="panel-title">Wishlists</h3></div>
    <div class="panel-body">
    <% if @campaign.can_edit_wishlists %>
    <%= link_to '<i class="glyphicon glyphicon-plus"></i> New Wishlist'.html_safe, url_for([:new, get_namespace, @campaign.organization, @campaign, :wishlist]), :class => "btn btn-xs btn-primary" %>
    <% end %>
    <input placeholder="Filter..." type="text" oninput="onFilterChanged(this.value)" id="filterTerm" />
    <% if @campaign.can_edit_wishlists %>
    <%= link_to 'Bulk Edit', url_for([:edit_multiple, get_namespace, @campaign.organization, @campaign, :wishlists, :wishlists_ids => '']), :class => "btn btn-xs btn-warning", :onclick => 'bulkEdit()', :remote => true, :id => 'bulk-edit' %>
    <%= link_to 'Bulk Upload', url_for([:edit_upload, get_namespace, @campaign.organization, @campaign, :wishlists]), :class => "btn btn-xs btn-primary", :remote => true, :id => 'bulk-upload' if admin? %>
    <% end %>
    </div>
    <div id="myGrid" style="height: 450px;" class="ag-bootstrap"></div>
  </div>

</div>

<% content_for :foot do -%>
<%= javascript_include_tag 'ag-grid.min.js' %>

<script>
// Very hacky solution for attempting to fix a "timeout" issue on this page
// that I couldn't recreate
function heartbeat() {
   $.ajax('/');
}
window.setInterval("heartbeat()", 1000*60*5);

var url = '<%= url_for([:readers, get_namespace, @campaign.organization, @campaign]) %>';
var can_edit_wishlists = <%= @campaign.can_edit_wishlists.nil? || !@campaign.can_edit_wishlists ? 'false' : 'true' %>;

function onFilterChanged(value) {
    gridOptions.api.onFilterChanged();
}

function bulkEdit() {
  var ids = "";
  $.each(gridOptions.api.getSelectedRows(), function(idx, row) {
    if (ids.length > 0) { ids += "," }
    ids += row.id;
  });

  if (ids.length == 0) return false;
  var href = $('#bulk-edit').attr('href');
  $('#bulk-edit').attr('href', href.substring(0, href.lastIndexOf('?')) + "?wishlists_ids=" + ids);
}

// Datasource used by both PaginationController and VirtualPageRowModel
var ds = {

    // If you know up front how many rows are in the dataset, set it here. Otherwise leave blank.
    rowCount: <%= @campaign.wishlists.count %>,

    // Callback the grid calls that you implement to fetch rows from the server. See below for params.
    getRows: function(params){
      var term = $("#filterTerm").val();
      var sort = "";
      $.each(params.sortModel, function(idx, s) {
        if (sort.length > 0) { sort += ", "}
        sort += s.colId + " " + s.sort
      });
      $.ajax( url + '?offset=' + params.startRow + '&limit=' + (params.endRow-params.startRow) + "&sort=" + sort + "&term=" + term, {
        dataType: 'json',
        success: function(data, status, xhr) {
          params.successCallback(data)
        },
        error: params.failCallback
      });
    }
};

function asMoney(val) {
  return parseFloat(val.value, 10).toFixed(2);
}

function editButton(val) {
  if (!can_edit_wishlists) {
    return '';
  } else {
    return '<a class="btn btn-info btn-xs" href="' + url.replace("readers", 'wishlists/' + val.data.id + '/manage') + '">Pick Books</a> ' +
      '<a class="btn btn-warning btn-xs" href="' + url.replace("readers", 'wishlists/' + val.data.id + '/edit') + '">Edit</a> ' +
      '<a class="btn btn-danger btn-xs" href="' + url.replace("readers", 'wishlists/' + val.data.id ) + '" data-method="delete" data-confirm="This action cannot be undone. Are you sure?">Delete</a>';
  }
}

var gridOptions = {
    columnDefs: [
        {headerName: 'Teacher', field: 'teacher', checkboxSelection: true, sort: 'asc', sortAt: 0},
        {headerName: 'Name', field: 'reader_name', sort: 'asc', sortAt: 1},
        {headerName: 'Age', field: 'reader_age', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'Gender', field: 'reader_gender', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'Grade', field: 'grade', width: 75, cellClass: 'mhl-ag-grid-cell'},
        //{headerName: 'GRL', field: 'grl', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'ID', field: 'external_id', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'Book Count', field: 'book_count', width: 100, cellClass: 'text-right mhl-ag-grid-cell', headerClass: 'mhl-ag-grid-header-right'}
        <% if admin? %>
        ,
        {headerName: 'Wish List Total ($)', field: 'wishlist_total', cellClass: 'text-right mhl-ag-grid-cell', headerClass: 'mhl-ag-grid-header-right', cellFormatter: asMoney},
        {headerName: 'Donation Total ($)', field: 'donation_total', cellClass: 'text-right mhl-ag-grid-cell', headerClass: 'mhl-ag-grid-header-right', cellFormatter: asMoney}
        <% end %>
        ,
        {headerName: '&nbsp;', field: 'actions', cellRenderer: editButton }

    ],

    // the default col def, gets applied to every col
    defaultColDef: {
        // make every column use 'text' filter by default
        suppressFilter: true,
        headerClass: 'mhl-ag-grid-header-left',
        cellClass: 'mhl-ag-grid-cell'
    },
    rowModelType: 'pagination',
    datasource: ds,
    rowSelection: 'multiple',
    enableColResize: true,
    enableServerSideSorting: true,
    enableServerSideFilter: true,
    paginationPageSize: 100,
    suppressRowClickSelection: true
};

// wait for the document to be loaded, otherwise
// ag-Grid will not find the div in the document.
document.addEventListener("DOMContentLoaded", function() {
    var eGridDiv = document.querySelector('#myGrid');<commit_msg>Removes Delete and Age columns from list of students on volunteer view.<commit_after><div class="panel panel-default outer-panel panel-info">
  <!-- Default panel contents -->
  <div class="panel-heading"><h3 class="panel-title">Campaign Detail</h3></div>
  <div class="panel-body">
    <dl class="dl-horizontal">
      <dt>Name</dt>
      <dd><%= @campaign.name %></dd>
      <dt>Deadline</dt>
      <dd><%= @campaign.deadline %></dd>
      <dt>Ready for Donations</dt>
      <dd><input type=checkbox disabled <%= @campaign.ready_for_donations ? 'checked' : '' %> /></dd>
      <dt>Address</dt>
      <dd><address><%= h(@campaign.address).gsub(/\n/, '<br/>').html_safe %></address></dd>
      <dt>Can Edit Wish Lists</dt>
      <dd><input type=checkbox disabled <%= @campaign.can_edit_wishlists ? 'checked' : '' %> /></dd>
      <dt>Book Limit</dt>
      <dd><%= @campaign.book_limit %></dd>
    </dl>
  </div>

  <div class="panel panel-default table-condensed">
    <!-- Default panel contents -->
    <div class="panel-heading"><h3 class="panel-title">Wishlists</h3></div>
    <div class="panel-body">
    <% if @campaign.can_edit_wishlists %>
    <%= link_to '<i class="glyphicon glyphicon-plus"></i> New Wishlist'.html_safe, url_for([:new, get_namespace, @campaign.organization, @campaign, :wishlist]), :class => "btn btn-xs btn-primary" %>
    <% end %>
    <input placeholder="Filter..." type="text" oninput="onFilterChanged(this.value)" id="filterTerm" />
    <% if @campaign.can_edit_wishlists %>
    <%= link_to 'Bulk Edit', url_for([:edit_multiple, get_namespace, @campaign.organization, @campaign, :wishlists, :wishlists_ids => '']), :class => "btn btn-xs btn-warning", :onclick => 'bulkEdit()', :remote => true, :id => 'bulk-edit' %>
    <%= link_to 'Bulk Upload', url_for([:edit_upload, get_namespace, @campaign.organization, @campaign, :wishlists]), :class => "btn btn-xs btn-primary", :remote => true, :id => 'bulk-upload' if admin? %>
    <% end %>
    </div>
    <div id="myGrid" style="height: 450px;" class="ag-bootstrap"></div>
  </div>

</div>

<% content_for :foot do -%>
<%= javascript_include_tag 'ag-grid.min.js' %>

<script>
// Very hacky solution for attempting to fix a "timeout" issue on this page
// that I couldn't recreate
function heartbeat() {
   $.ajax('/');
}
window.setInterval("heartbeat()", 1000*60*5);

var url = '<%= url_for([:readers, get_namespace, @campaign.organization, @campaign]) %>';
var can_edit_wishlists = <%= @campaign.can_edit_wishlists.nil? || !@campaign.can_edit_wishlists ? 'false' : 'true' %>;
var is_admin = <%= admin? %>;

function onFilterChanged(value) {
    gridOptions.api.onFilterChanged();
}

function bulkEdit() {
  var ids = "";
  $.each(gridOptions.api.getSelectedRows(), function(idx, row) {
    if (ids.length > 0) { ids += "," }
    ids += row.id;
  });

  if (ids.length == 0) return false;
  var href = $('#bulk-edit').attr('href');
  $('#bulk-edit').attr('href', href.substring(0, href.lastIndexOf('?')) + "?wishlists_ids=" + ids);
}

// Datasource used by both PaginationController and VirtualPageRowModel
var ds = {

    // If you know up front how many rows are in the dataset, set it here. Otherwise leave blank.
    rowCount: <%= @campaign.wishlists.count %>,

    // Callback the grid calls that you implement to fetch rows from the server. See below for params.
    getRows: function(params){
      var term = $("#filterTerm").val();
      var sort = "";
      $.each(params.sortModel, function(idx, s) {
        if (sort.length > 0) { sort += ", "}
        sort += s.colId + " " + s.sort
      });
      $.ajax( url + '?offset=' + params.startRow + '&limit=' + (params.endRow-params.startRow) + "&sort=" + sort + "&term=" + term, {
        dataType: 'json',
        success: function(data, status, xhr) {
          params.successCallback(data)
        },
        error: params.failCallback
      });
    }
};

function asMoney(val) {
  return parseFloat(val.value, 10).toFixed(2);
}

function editButton(val) {
  if (!can_edit_wishlists) {
    return '';
  } else {
    var del = is_admin ? '<a class="btn btn-danger btn-xs" href="' + url.replace("readers", 'wishlists/' + val.data.id ) + '" data-method="delete" data-confirm="This action cannot be undone. Are you sure?">Delete</a>' : '';
    return '<a class="btn btn-info btn-xs" href="' + url.replace("readers", 'wishlists/' + val.data.id + '/manage') + '">Pick Books</a> ' +
      '<a class="btn btn-warning btn-xs" href="' + url.replace("readers", 'wishlists/' + val.data.id + '/edit') + '">Edit</a> ' + del;
      ;
  }
}

var gridOptions = {
    columnDefs: [
        {headerName: 'Teacher', field: 'teacher', checkboxSelection: true, sort: 'asc', sortAt: 0},
        {headerName: 'Name', field: 'reader_name', sort: 'asc', sortAt: 1},
        <% if admin? %>
        {headerName: 'Age', field: 'reader_age', width: 75, cellClass: 'mhl-ag-grid-cell'},
        <% end -%>
        {headerName: 'Gender', field: 'reader_gender', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'Grade', field: 'grade', width: 75, cellClass: 'mhl-ag-grid-cell'},
        //{headerName: 'GRL', field: 'grl', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'ID', field: 'external_id', width: 75, cellClass: 'mhl-ag-grid-cell'},
        {headerName: 'Book Count', field: 'book_count', width: 100, cellClass: 'text-right mhl-ag-grid-cell', headerClass: 'mhl-ag-grid-header-right'}
        <% if admin? %>
        ,
        {headerName: 'Wish List Total ($)', field: 'wishlist_total', cellClass: 'text-right mhl-ag-grid-cell', headerClass: 'mhl-ag-grid-header-right', cellFormatter: asMoney},
        {headerName: 'Donation Total ($)', field: 'donation_total', cellClass: 'text-right mhl-ag-grid-cell', headerClass: 'mhl-ag-grid-header-right', cellFormatter: asMoney}
        <% end -%>
        ,
        {headerName: '&nbsp;', field: 'actions', cellRenderer: editButton }

    ],

    // the default col def, gets applied to every col
    defaultColDef: {
        // make every column use 'text' filter by default
        suppressFilter: true,
        headerClass: 'mhl-ag-grid-header-left',
        cellClass: 'mhl-ag-grid-cell'
    },
    rowModelType: 'pagination',
    datasource: ds,
    rowSelection: 'multiple',
    enableColResize: true,
    enableServerSideSorting: true,
    enableServerSideFilter: true,
    paginationPageSize: 100,
    suppressRowClickSelection: true
};

// wait for the document to be loaded, otherwise
// ag-Grid will not find the div in the document.
document.addEventListener("DOMContentLoaded", function() {
    var eGridDiv = document.querySelector('#myGrid');
{'fraction_non_alphanumeric': 0.18695221400807865, 'fraction_numerical': 0.0059446688514594925, 'mean_word_length': 3.517039586919105, 'pattern_counts': {'":': 0, '<': 168, '<?xml version=': 0, '>': 190, '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': '2221844', 'n_tokens_mistral': 4548, 'n_tokens_neox': 4308, 'n_words': 1038}