Commit b67e28de authored by Randall Leeds's avatar Randall Leeds Committed by Aron Carroll

Break out callbacks in auth controller

parent 6eaf2e6d
...@@ -8,22 +8,11 @@ class AuthController ...@@ -8,22 +8,11 @@ class AuthController
constructor: ( $scope, $timeout, session ) -> constructor: ( $scope, $timeout, session ) ->
timeout = null timeout = null
this.submit = (form) -> success = ->
return unless form.$valid
data = {}
method = '$' + form.$name
for own key of session
delete session[key]
angular.extend session, $scope.model
session[method](
(session) ->
$scope.model = null $scope.model = null
$scope.$broadcast 'success' $scope.$broadcast 'success'
, (response) ->
failure = (form, response) ->
{errors, reason} = response.data {errors, reason} = response.data
if reason if reason
...@@ -40,7 +29,18 @@ class AuthController ...@@ -40,7 +29,18 @@ class AuthController
form[field].responseErrorMessage = error form[field].responseErrorMessage = error
$scope.$broadcast 'error', form.$name $scope.$broadcast 'error', form.$name
)
this.submit = (form) ->
return unless form.$valid
data = {}
method = '$' + form.$name
for own key of session
delete session[key]
angular.extend session, $scope.model
session[method] success, angular.bind(this, failure, form)
$scope.$on '$destroy', -> $scope.$on '$destroy', ->
if timeout if timeout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment