Source: site/tagAdd.js

// Generated by CoffeeScript 1.12.7

/**
 * Form to add tags
 * @module
 */
'use strict';
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

app.directive('tagAdd', [
  '$sce', 'constantService', 'modelService', 'messageService', function($sce, constants, models, messages) {
    return {
      restrict: 'E',
      templateUrl: 'site/tagAdd.html',
      link: function($scope, $element, $attrs) {
        var form, select;
        form = $scope.tagAddForm;
        $scope.keyword = 'keyword' in $attrs;
        select = function(tag) {
          return function() {
            return $scope.vote(tag, true).then(function() {
              return '';
            });
          };
        };
        form.search = function(input) {
          if (!form.$valid) {
            return input;
          }
          return models.Tag.search(input).then(function(data) {
            var l, tag;
            l = (function() {
              var i, len, results;
              results = [];
              for (i = 0, len = data.length; i < len; i++) {
                tag = data[i];
                results.push({
                  text: tag,
                  select: select(tag)
                });
              }
              return results;
            })();
            if (indexOf.call(data, input) < 0) {
              l.push({
                text: 'Create tag: ' + input,
                select: select(input),
                "default": true
              });
            }
            return l;
          }, function(res) {
            messages.addError({
              body: constants.message('tags.auto.error', {
                sce: $sce.HTML
              }),
              report: res
            });
            return [
              {
                text: input,
                select: select(input)
              }
            ];
          });
        };
        form.submit = function(input) {
          return $scope.vote(input, true).then(function() {
            return '';
          });
        };
      }
    };
  }
]);

//# sourceMappingURL=tagAdd.js.map