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