   appendTo: (@$container) ->
 
   createTask: (host) ->
-    new ContainerView(@$container, host)
+    new LightsTaskView(@$container, host)
 
   getTask: (host) ->
     @tasks[host] ||= @createTask(host)

    @capistranoTask = "jobs:restart"

  createTask: (host) ->
    task = super(host)
    task.addCustomClass("task-job-server")
    task

  parse: (parser) ->
    parser.eachMessage (log) =>
      if match = log.output.match(/sv-multi sending graceful_quit to (\d+) services/)
        @getTask(log.host).update
          numLights: match[1]
      else if match = log.output.match(/ok: run: [\-\w\d]+: \(pid \d+\)/)
        task = @getTask(log.host)
        task.update
          numDone: task.numDone + 1
    null


class ContainerView
  TEMPLATE = $.trim """
    <div class="task-lights">
      <span class="task-lights-text">

      else
        'neutral'
      $('<span>').addClass("task-lights-box box-#{status}").appendTo(boxes)
    boxes

  update: (attrs) ->
    $.extend(this, attrs)
    @$element.find('.task-lights-boxes').empty().append(@genBoxes())
    this

  fail: ->
    @$element.addClass('task-failed')

class JobServerRestartTaskView extends LightsTaskView
  constructor: (container, host) ->
    super container, host
    @$element.addClass("task-job-server")
    @statuses = []

  genBoxes: ->
    boxes = document.createDocumentFragment();
    for status in @statuses
      box = $('<span>').addClass("task-lights-box box-#{status[0]}")
      box.attr('title',status[1])
      box.appendTo(boxes)
    for i in [0...(@numLights-@statuses.length)]
      $('<span>').addClass("task-lights-box box-neutral").appendTo(boxes)
    boxes

  addStatus: (status, note) ->
    @statuses.push([status, note])




restartWidget = new ContainersRestartWidget()
