Sha256: d6133a82e30f1490ef8c390d4af6dbb0635913c0496ec3cbf36782d792fab314

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

//= require modular
//= require jquery_ujs
//= require_tree .

// sortable tables

$( document ).ready(function() {
  //commit=Filter&filter_name=test&page_offset=100&page_size=500&sort_asc=true&sort_column=
  const urlParams = new URLSearchParams(window.location.search);
  var params = {
    commit: urlParams.get('commit'),
  };

  if (urlParams.get('page_size')) {
    params['page_size'] = urlParams.get('page_size');
  }

  // adding filter(s)
  for (let param of urlParams) {
    if (param[0].startsWith('filter_')) {
      params[param[0]] = param[1];
    } 
  }

  var path = window.location.pathname+'?';
  
  $('th[sort-column]').each(function() {
    var currentColumnName = $(this).attr('sort-column');
    params['sort_column'] = currentColumnName;
    
    params['sort_asc'] = 'true';
    var sortIndicator = ""; 
    if (urlParams.get('sort_column') === currentColumnName) {
      //reverse sort order
      if (urlParams.get('sort_asc') === 'true') {
        params['sort_asc'] = 'false';
        sortIndicator = ' ▴';
      }
      else {
        params['sort_asc'] = 'true';
        sortIndicator = ' ▾';
      }
    } 

    var linkElement = $( "<a/>", {
      style: "padding:0;",
      html: $(this).html() + sortIndicator,
      "class": "btn btn-default",
      href: path + $.param(params)
    });
     
    $(this).html(linkElement);
  });
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kadmin-1.1.1 app/assets/javascripts/kadmin/application.js
kadmin-1.1.0 app/assets/javascripts/kadmin/application.js