Commit caccbfed authored by Randall Leeds's avatar Randall Leeds

reset auth forms on app reset

Introduces 'resettable' directive which runs at super high priority
and listens for the '$reset' event on the scope upon which the
element is stored to its pristine condition via a full element
transclude.

closes #159
parent 9eb28426
class App
scope:
username: null
email: null
password: null
code: null
sheet:
collapsed: true
tab: 'login'
......@@ -15,8 +19,6 @@ class App
$compile, $element, $http, $location, $scope,
annotator, flash, threading
) ->
$scope.reset = => angular.extend $scope, @scope
{plugins, provider} = annotator
heatmap = annotator.plugins.Heatmap
heatmap.element.appendTo $element
......@@ -159,7 +161,7 @@ class App
$http.post 'logout', '',
withCredentials: true
.success (data) =>
$scope.reset()
$scope.$broadcast '$reset'
if data.model? then angular.extend($scope, data.model)
if data.flash? then flash q, msgs for q, msgs of data.flash
......@@ -185,6 +187,8 @@ class App
collapsed: !show
tab: 'login'
$scope.$on '$reset', => angular.extend $scope, @scope
# Fetch the initial model from the server
$http.get '',
withCredentials: true
......@@ -192,7 +196,7 @@ class App
if data.model? then angular.extend $scope, data.model
if data.flash? then flash q, msgs for q, msgs of data.flash
$scope.$evalAsync 'reset()'
$scope.$broadcast '$reset'
class Annotation
......
......@@ -71,6 +71,21 @@ recursive = ['$compile', '$timeout', ($compile, $timeout) ->
]
resettable = ->
compile: (tElement, tAttrs, transclude) ->
post: (scope, iElement, iAttrs) ->
reset = ->
transclude scope, (el) ->
iElement.replaceWith el
iElement = el
iElement[0].$reset = reset
reset()
scope.$on '$reset', reset
priority: 5000
restrict: 'A'
transclude: 'element'
tabReveal = ['$parse', ($parse) ->
compile: (tElement, tAttrs, transclude) ->
panes = []
......@@ -125,5 +140,6 @@ thread = ->
angular.module('h.directives', ['ngSanitize'])
.directive('annotation', annotation)
.directive('recursive', recursive)
.directive('resettable', resettable)
.directive('tabReveal', tabReveal)
.directive('thread', thread)
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