$('#resources-tbody').replaceWith('<%= escape_javascript(render("resources")) %>');
$('#paginator .pagination').html('<%= escape_javascript(paginate(@users, :remote => true).to_s) %>');
$('#page_entries_info').html('<%= escape_javascript(page_entries_info(@users).to_s) %>');


selected = $('#export_selected_selected_users').val().split(",");

$('.selected_users').each(function() {
  if (_.includes(selected, $(this).attr('value'))) {
    $(this).prop('checked', true);
  }
})

$('.destroy-button').each(function() {
  var search_by_name = $('#search_by_name').val();
  var search_by_cpf = $('#search_by_cpf').val();
  var search_email = $('#search_email').val();
  var search_login = $('#search_login').val();
  var search_status = $('#search_status').val();
  var params = '';

  if (search_by_name) {
    params += '&search[by_name]=' + search_by_name;
  }

  if (search_by_cpf) {
    params += '&search[by_cpf]=' + search_by_cpf;
  }

  if (search_email) {
    params += '&search[email]=' + search_email;
  }

  if (search_login) {
    params += '&search[login]=' + search_login;
  }

  if (search_status) {
    params += '&search[status]=' + search_status;
  }

  var _href = $(this).attr("href");

  $(this).attr("href", _href + params.replace('&', '?'));
});
