   metric_url_representation = (metric) ->
     return metric.split('_').join('-')
 
+  # Callback function for querying the metadata records
   displayRecordResults = (result) ->
-
     which_record = $("#search-input").data("record")
     if result.length > 0
       for metadata in result

    else
      $("#search-results").hide()

  $(".search.report.row").hide()

  $(".report.repository-select").on 'change', (event) =>
    repository = $(".report.repository-select").val()
    window.location = "repository?show=#{repository}"

  $(".dropdown-toggle").dropdown()

  $("a.report.search").on 'click', (event) =>
    record = $(event.target).data('record')
    $(".search.report.row").show()
    $("#search-input").data('record', record)
    $("#search-results").hide()

  $("#search-input").on 'input', (event) =>
    $("#search-results tbody").empty()
    $("#search-results").show()

    query = $("#search-input").val()
    query = if /\S/.test(query) then query else '*'
    repository = gon.repository.name

    data =
      q: query
      repository: repository

    $.getJSON("/metadata/search", data, displayRecordResults)

#=require bootstrap-rowlink.min
$ ->

  # Metric abbreviation are used in the result table
  createMetricAbbreviation = (metric) ->
    abbreviation = ''
    for word in metric.split('_')
      abbreviation += word[0].toUpperCase()
    return abbreviation

  # Create one result row for the result table
  createTableRow = (metadata, i) ->
    record = metadata.id
    url = createReportLink(record, i)
    tdId = "<td><a href=\"#{url}\">#{metadata.record.id}</a></td>"
