_ = require 'lodash'
Tasks = require 'vision/collections/tasks'


angular.module('vision').component 'visionTaskListAdd',
  template: do require './index.jade'
  controllerAs: 'vm'
  bindings:
    group: '<'
  controller: ($scope, $vision) ->
    'ngInject'; $vision.attach(module, $scope); vm = @

    @keydown = (e) -> do @add if e.keyCode is 13

    @add = ->
      return null if _.isEmpty @text
      task =
        title: @text
      Tasks.insert task, (err, res) ->
        unless err
          @text = ''


    return
