// @ngInject
export default function submitButton($q) {
  return {
    restrict: 'A',
    scope: {
      submit: '&submitButton'
    },
    link: function(scope, element) {
      element.bind('click', function() {
        scope.$apply(click);
      });
      function click() {
        element.addClass('disabled').addClass('button-spinner');
        $q.when(scope.submit()).finally(function() {
          element.removeClass('disabled').removeClass('button-spinner');
        });
      }
    }
  };
}

// @ngInject
export default function submitButton($q) {
  return {
    restrict: 'A',
    scope: {
      submit: '&submitButton'
    },
    link: function(scope, element) {
      element.bind('click', function() {
        element.addClass('disabled').addClass('button-spinner');
        $q.when(scope.submit()).finally(function() {
          element.removeClass('disabled').removeClass('button-spinner');
        });
      });
    }
  };
}

Fix Action Already In Progress exception in submit button directive
Fix Action Already In Progress exception in submit button directive [SENTRY-3013]
