Skip to content
Snippets Groups Projects
items.js 1.39 KiB
Newer Older
Benjamin Bertrand's avatar
Benjamin Bertrand committed
$(document).ready(function() {

  var converter = new showdown.Converter({
    simplifiedAutoLink: true
  });

  // Live rendering of markdown comment to HTML
  $("#text").keyup(function(event) {
    var comment = $(this).val();
    $("#commentLivePreview").html(converter.makeHtml(comment));
  });

  // render existing comments to HTML
  $(".item-comment").each(function() {
    var raw = $(this).html();
    $(this).html(converter.makeHtml(raw));
  });

  $("#clear").click(function() {
    // clear all select fields
    $("select").val('');
  });

Benjamin Bertrand's avatar
Benjamin Bertrand committed
  var items_table =  $("#items_table").DataTable({
    "ajax": function(data, callback, settings) {
      $.getJSON(
        $SCRIPT_ROOT + "/inventory/_retrieve_items",
Benjamin Bertrand's avatar
Benjamin Bertrand committed
        function(json) {
          callback(json);
        });
    },
    "order": [[3, 'desc']],
Benjamin Bertrand's avatar
Benjamin Bertrand committed
    "pagingType": "full_numbers",
    "pageLength": 20,
    "lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "All"]],
    "columnDefs": [
      {
        "targets": [0],
        "visible": false,
        "searchable": false
        "targets": [1, 9],
Benjamin Bertrand's avatar
Benjamin Bertrand committed
        "render": function(data, type, row) {
          // render funtion to create link to Item view page
          if ( data === null ) {
            return data;
          }
          var url = $SCRIPT_ROOT + "/inventory/items/view/" + data;
Benjamin Bertrand's avatar
Benjamin Bertrand committed
          return '<a href="'+ url + '">' + data + '</a>';
        }