$ ->

  if ($('#dashboard-page').length > 0)

    $("#myCanvasContainer").hide()  unless $("#myCanvas").tagcanvas(
      textColour: "gray"
      outlineColour: '#FF9714'
      textHeight: 30
      outlineThickness: 2
      maxSpeed: 0.03
      depth: 0.75
    )

    updateServiceContent = ->
      $.get settings.baseUrl+"/dashboard/viewServices", (html) ->
        $("#services-table").html(html)
        $(".spinner-container").spin("tiny")

    $("#services-table").on 'click', '[data-service-action]', ->
      $this = $(this)
      serviceId = $this.data("service-id")
      serviceGateGroupId = $this.data("gate-group-id")
      serviceAction = $this.data("service-action")

      postUrl = settings.baseUrl+"/service/#{serviceAction}/"
      postUrl += "#{serviceId}" if serviceId

      postData = {}

      $.ajax
        type: "POST"
        url: postUrl
        data: postData
        success: updateServiceContent
        error: (message) ->
          alert(message)

    updateServiceContent()
    setInterval(updateServiceContent, 5000)


