_resources_list.js 2.78 KB
jQuery(document).ready(function($) {

  if (!$('#resources').length) {
      return;
  }

  var pageL = 8;

  var myTable = $('#resources').DataTable({
      "pageLength":  pageL,
      "searchable": false,
      "paging": true,
      "info": false,
      "order": [[2, 'desc']],
      "dom": '<"top"<"clear"><"clear">>rt<"bottom"<"clear">p<"clear">>'

  });


  // use value of search field to filter
  var $quicksearch = $('#quicksearch').keyup(function() {
      console.log($quicksearch.val());
      $('#resources').DataTable().column(0).search($quicksearch.val()).draw();
  });




  // filter with selects and checkboxes
  var $checkboxes = $('.category-filter input');
  var filterValue;

  $checkboxes.change(function() {
      // map input values to an array
      var inclusives = [];
      // inclusive filters from checkboxes
      $checkboxes.each(function(i, elem) {
          // if checkbox, use value if checked
          if (elem.checked) {
              inclusives.push(elem.value);
          }
      });

      // combine inclusive filters
      filterValue = inclusives.length ? inclusives.join('|') : '';
      console.log(filterValue);
      $('#resources').DataTable().column(1).search(filterValue,true,false).draw();
  });

  // filter with selects and checkboxes
  var $typecheckboxes = $('.category-type input');
  var typeFilterValue;

  $typecheckboxes.change(function() {
      // map input values to an array
      var inclusives = [];
      // inclusive filters from checkboxes
      $typecheckboxes.each(function(i, elem) {
          // if checkbox, use value if checked
          if (elem.checked) {
              inclusives.push(elem.value);
          }
      });

      // combine inclusive filters
      typeFilterValue = inclusives.length ? inclusives.join('|') : '';
      $('#resources').DataTable().column(0).search(typeFilterValue,true,false).draw();
  });


  $('.sort-button-group').on('click', 'button', function() {
      var sortValue = $(this).attr('data-sort-value');
      var direction = $(this).attr('data-sort-direction');
      var isAscending = (direction == 'asc');
      var newDirection = (isAscending) ? 'desc' : 'asc';
      console.log(sortValue);
      console.log(isAscending);
      $(this).attr('data-sort-direction', newDirection);
      var span = $(this).find('.glyphicon');
      span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down');
      myTable.order([sortValue, newDirection]).draw();
  });



  $(document).on("click", "#filter-more", function(e) {
      e.preventDefault();
      $('.filter-group').toggleClass('open');
      var span = $(this).find('.glyphicon');
      span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down');


  });


  $(document).on("click", ".flag", function(e) {
    $("#nf-field-16").val($(this).data('title'));
  });
 


});