Sha256: 52d36ed086fecdd7156d6443669903f59943824ec78f0921a66a2deafb0e4e8c

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

/* global $ */
"use strict";

/* Admin table */

function snapifyTable() {
  
  var snaptable = $("#snaptable");

  var tableButtons = snaptable.find(".table_buttons"),
      editButton = tableButtons.find("a[class='edit']"),
      deleteButton = tableButtons.find("a[class='delete']"),
      showButton = tableButtons.find("a[class='show']"),
      path = window.location.pathname + "/";

  // add ajax to the pagination
  snaptable.on("click", ".pagination a", function() {
    $.getScript(this.href);
    return false;
  });

  // line clickable
  snaptable.on("click", "tbody tr", function(e) {
    var id = $(this).data("url") ;
    if ( typeof id !== "undefined" && !$(this).hasClass("selected") ) {
      $("tr.selected").removeClass("selected");
      $(this).addClass("selected");
      deleteButton.add(editButton).add(showButton).addClass("on");
      editButton.attr("href", path + id + "/edit");
      deleteButton.attr("href", path + id);
      showButton.attr("href", path + id);
    }
  });

  // Double click
  if(editButton.length) {
    snaptable.on("dblclick", "tbody tr", function() {
      var id = $(this).data("url");
      if ( typeof id !== "undefined" ) {
        window.location = path + id + "/edit";
      }
    });
  }

}

$(document).on("ready page:load", function() {

  snapifyTable();

});

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snaptable-1.1.3 app/assets/javascripts/snaptable/table.js
snaptable-1.1.2 app/assets/javascripts/snaptable/table.js
snaptable-1.1.1 app/assets/javascripts/snaptable/table.js
snaptable-1.1.0 app/assets/javascripts/snaptable/table.js
snaptable-1.0.0 app/assets/javascripts/snaptable/table.js
snaptable-0.9.3 app/assets/javascripts/snaptable/table.js