window.RefreshViolationPreviewTable =
  refreshViolationsTable: (gateId) ->
    @fetchViolations(gateId).done (html) =>
      @replaceViolationTable(html)

  replaceViolationTable: (html) ->
    $html = $("<div>").html(html)
    for selector in [ ".gate-description", ".violations" ]
      @$violationsContainer.find(selector).replaceWith($html.find(selector))

  fetchViolations: (gateId) ->
    options =
      type: "GET"
      url: settings.baseUrl+"/gatesStatus/viewViolationsTable"

    options.data = { gateId: gateId } if gateId

    $.ajax(options)
