window.RefreshAlertPreviewTable =
  refreshAlertsTable: (gateId) ->
    @fetchAlerts(gateId).done (html) =>
      @replaceAlertTable(html)

  replaceAlertTable: (html) ->
    $html = $("<div>").html(html)
    for selector in [ ".gate-description", ".alerts" ]
      @$alertsContainer.find(selector).replaceWith($html.find(selector))

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

    options.data = { gateId: gateId } if gateId

    $.ajax(options)
