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

  // scroll up to avoid having the form input
  // hidden under the navbar
  if (location.hash == "#body") {
    scrollBy(0, -100);
  }

  // Showdown extension to render links to JIRA TAG project
  var jira_tag = {
      type: 'lang',
      regex: /(TAG-\d+)/g,
      replace: '[$1](https://jira.esss.lu.se/browse/$1)'
  };
  // Register the extension
  showdown.extension('jira_tag', jira_tag);

  var converter = new showdown.Converter({
    extensions: ['jira_tag'],
    simplifiedAutoLink: true
  });

  // Live rendering of markdown comment to HTML
  $("#body").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));
  });

Benjamin Bertrand's avatar
Benjamin Bertrand committed
  var items_table =  $("#items_table").DataTable({
    "ajax": {
      "url": $SCRIPT_ROOT + "/inventory/_retrieve_items"
Benjamin Bertrand's avatar
Benjamin Bertrand committed
    },
    "processing": true,
    "serverSide": true,
    "searchDelay": 500,
    "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
Benjamin Bertrand's avatar
Benjamin Bertrand committed
      },
        "targets": [6, 7, 8, 9],
        "orderable": false
      },
        "targets": [1, 10],
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>';
        }