Sha256: d6293282a888aa074968b4e1a744e16c4b2e2208873fd1499581c509baf5a6a9

Contents?: true

Size: 1.58 KB

Versions: 32

Compression:

Stored size: 1.58 KB

Contents

$(function(){
  $('body').on('click', '.settings-link', function() {
    $('.rails-db-settings').toggle();
    return false;
  });

  $('body').on('click', '.column-name input', function() {
    table_name = 'Table: ' + $('a[table_name]').attr('table_name');
    column_name = $(this).prop('name');
    if($(this).prop('checked') == false) {
      write_column_to_cookie(table_name, column_name);
    } else {
      remove_column_from_cookie(table_name, column_name);
    }
    switch_column_visibility(column_name);
    toggle_columns();
  });

});

function write_column_to_cookie(table_name, column_name) {
  column_names = get_column_names_from_cookie(table_name);
  $.cookie(table_name, column_names += ',' + column_name);
};

function remove_column_from_cookie(table_name, column_name) {
  column_names = get_column_names_from_cookie(table_name);
  $.cookie(table_name, column_names.replace(',' + column_name, ''));
};

function get_column_names_from_cookie(table_name) {
  cookie = $.cookie(table_name);
  if(cookie == undefined) {
    return '';
  } else {
    return cookie;
  }
};

function switch_column_visibility(column_name) {
  $('th.column_' + column_name).toggle();
  $('td.column_' + column_name).toggle();
};

function toggle_columns() {
  if($('.column-name input:checked').length == 0) {
    $('.column-name input[type=checkbox]').each(function() {
      column_name = $(this).prop('name');
      $(this).prop("checked", true);
      remove_column_from_cookie(table_name, column_name);
      switch_column_visibility(column_name);
    });
  }
};

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
rails_db-2.4.4 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.4.3 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.4.2 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.4.1 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.4.0 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.3.1 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.3.0 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.2.1 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.2.0 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.1.1 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.1.0 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.6 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.5 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.4 app/assets/javascripts/rails_db/show_hide_columns.js
xplore-0.0.1.alpha app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.3 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.2 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.1 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-2.0.0 app/assets/javascripts/rails_db/show_hide_columns.js
rails_db-1.6.0 app/assets/javascripts/rails_db/show_hide_columns.js