Source: volume/comments.js

// Generated by CoffeeScript 1.12.7

/**
 * Volume comments
 * @module
 */
'use strict';
app.directive('volumeComments', [
  'constantService', 'messageService', 'modelService', function(constants, messages, models) {
    return {
      restrict: 'E',
      templateUrl: 'volume/comments.html',
      scope: false,
      link: function($scope) {
        var pullComments, refresh;
        $scope.canPost = models.Login.isAuthorized();
        refresh = function() {
          return $scope.comments = $scope.volume.comments;
        };
        refresh();
        pullComments = function() {
          return $scope.volume.get(['comments']).then(function(res) {
            return $scope.comments = res.comments;
          }, function(res) {
            return messages.addError({
              body: constants.message('comments.update.error'),
              report: res
            });
          });
        };
        $scope.commentClass = function(comment) {
          var cls;
          cls = {};
          if (comment.parents) {
            cls['depth-' + Math.min(comment.parents.length, 5)] = true;
          }
          return cls;
        };
        $scope.replyTo = void 0;
        $scope.setReply = function(comment) {
          return $scope.replyTo = comment;
        };
        $scope.$on('commentReplyForm-init', function(event, form) {
          form.successFn = pullComments;
          form.cancelFn = $scope.setReply;
          form.target = $scope.replyTo;
          return event.stopPropagation();
        });
        return $scope.jumpLink = function(comment) {
          return comment.container.route({
            asset: comment.id,
            select: comment.segment.format()
          });
        };
      }
    };
  }
]);

//# sourceMappingURL=comments.js.map