Commit 7ed580b2 authored by gergely-ujvari's avatar gergely-ujvari

Merge pull request #1058 from hypothesis/angular-upgrade-1

Angular upgrade v1.2.13
parents 076e87d6 bfbb58c3
...@@ -9,29 +9,26 @@ annotation = ['$filter', 'annotator', ($filter, annotator) -> ...@@ -9,29 +9,26 @@ annotation = ['$filter', 'annotator', ($filter, annotator) ->
scope.save(e) scope.save(e)
# Watch for changes # Watch for changes
scope.$watch 'model.$modelValue.id', (id) -> scope.$watch 'model', (model) ->
scope.thread = annotator.threading.idTable[id] scope.thread = annotator.threading.idTable[model.id]
scope.auth = {} scope.auth = {}
scope.auth.delete = scope.auth.delete =
if scope.model.$modelValue? and annotator.plugins?.Permissions? if model? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'delete', scope.model.$modelValue annotator.plugins.Permissions.authorize 'delete', model
else else
true true
scope.auth.update = scope.auth.update =
if scope.model.$modelValue? and annotator.plugins?.Permissions? if scope.model? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'update', scope.model.$modelValue annotator.plugins.Permissions.authorize 'update', model
else else
true true
# Publish the controller
scope.model = controller
controller: 'AnnotationController' controller: 'AnnotationController'
priority: 100 # Must run before ngModel
require: '?ngModel' require: '?ngModel'
restrict: 'C' restrict: 'C'
scope: scope:
model: '=ngModel'
mode: '@' mode: '@'
replies: '@' replies: '@'
templateUrl: 'annotation.html' templateUrl: 'annotation.html'
......
...@@ -540,20 +540,20 @@ class Annotation ...@@ -540,20 +540,20 @@ class Annotation
$scope.cancel = ($event) -> $scope.cancel = ($event) ->
$event?.stopPropagation() $event?.stopPropagation()
$scope.editing = false $scope.editing = false
drafts.remove $scope.model.$modelValue drafts.remove $scope.model
annotator.enableAnnotating drafts.isEmpty() annotator.enableAnnotating drafts.isEmpty()
switch $scope.action switch $scope.action
when 'create' when 'create'
annotator.deleteAnnotation $scope.model.$modelValue annotator.deleteAnnotation $scope.model
else else
$scope.model.$modelValue.text = $scope.origText $scope.model.text = $scope.origText
$scope.model.$modelValue.tags = $scope.origTags $scope.model.tags = $scope.origTags
$scope.action = 'create' $scope.action = 'create'
$scope.save = ($event) -> $scope.save = ($event) ->
$event?.stopPropagation() $event?.stopPropagation()
annotation = $scope.model.$modelValue annotation = $scope.model
# Forbid saving comments without a body (text or tags) # Forbid saving comments without a body (text or tags)
if annotator.isComment(annotation) and not annotation.text and if annotator.isComment(annotation) and not annotation.text and
...@@ -610,14 +610,13 @@ class Annotation ...@@ -610,14 +610,13 @@ class Annotation
$event?.stopPropagation() $event?.stopPropagation()
$scope.action = 'edit' $scope.action = 'edit'
$scope.editing = true $scope.editing = true
$scope.origText = $scope.model.$modelValue.text $scope.origText = $scope.model.text
$scope.origTags = $scope.model.$modelValue.tags $scope.origTags = $scope.model.tags
drafts.add $scope.model.$modelValue, -> $scope.cancel() drafts.add $scope.model, -> $scope.cancel()
annotator.disableAnnotating() annotator.disableAnnotating()
$scope.delete = ($event) -> $scope.delete = ($event) ->
$event?.stopPropagation() $event?.stopPropagation()
annotation = $scope.model.$modelValue
replies = $scope.thread.children?.length or 0 replies = $scope.thread.children?.length or 0
# We can delete the annotation if it hasn't got any replies or it is # We can delete the annotation if it hasn't got any replies or it is
...@@ -632,27 +631,26 @@ class Annotation ...@@ -632,27 +631,26 @@ class Annotation
annotator.plugins.Permissions.authorize 'delete', reply annotator.plugins.Permissions.authorize 'delete', reply
annotator.deleteAnnotation reply annotator.deleteAnnotation reply
annotator.deleteAnnotation annotation annotator.deleteAnnotation $scope.model
else else
$scope.action = 'delete' $scope.action = 'delete'
$scope.editing = true $scope.editing = true
$scope.origText = $scope.model.$modelValue.text $scope.origText = $scope.model.text
$scope.origTags = $scope.model.$modelValue.tags $scope.origTags = $scope.model.tags
$scope.model.$modelValue.text = '' $scope.model.text = ''
$scope.model.$modelValue.tags = '' $scope.model.tags = ''
$scope.$watch 'editing', -> $scope.$emit 'toggleEditing' $scope.$watch 'editing', -> $scope.$emit 'toggleEditing'
$scope.$watch 'model.$modelValue.id', (id) -> $scope.$watch 'model.id', (id) ->
if id? if id?
annotation = $scope.model.$modelValue $scope.thread = $scope.model.thread
$scope.thread = annotation.thread
# Check if this is a brand new annotation # Check if this is a brand new annotation
if annotation? and drafts.contains annotation if drafts.contains $scope.model
$scope.editing = true $scope.editing = true
$scope.$watch 'model.$modelValue.target', (targets) -> $scope.$watch 'model.target', (targets) ->
return unless targets return unless targets
for target in targets for target in targets
if target.diffHTML? if target.diffHTML?
...@@ -674,19 +672,19 @@ class Annotation ...@@ -674,19 +672,19 @@ class Annotation
# is not a pre-determined route map. One possibility would be to # is not a pre-determined route map. One possibility would be to
# unify everything so that it's relative to the app URL. # unify everything so that it's relative to the app URL.
prefix = $scope.$parent.baseUrl.replace /\/\w+\/$/, '' prefix = $scope.$parent.baseUrl.replace /\/\w+\/$/, ''
$scope.shared_link = prefix + '/a/' + $scope.model.$modelValue.id $scope.shared_link = prefix + '/a/' + $scope.model.id
$scope.shared = false $scope.shared = false
return
$scope.$watchCollection 'model.$modelValue.thread.children', (newValue=[]) -> $scope.$watchCollection 'model.thread.children', (newValue=[]) ->
annotation = $scope.model.$modelValue return unless $scope.model
return unless annotation
replies = (r.message for r in newValue) replies = (r.message for r in newValue)
replies = replies.sort(annotator.sortAnnotations).reverse() replies = replies.sort(annotator.sortAnnotations).reverse()
annotation.reply_list = replies $scope.model.reply_list = replies
$scope.toggle = -> $scope.toggle = ->
$element.find('.share-dialog').slideToggle() $element.find('.share-dialog').slideToggle()
return
$scope.share = ($event) -> $scope.share = ($event) ->
$event.stopPropagation() $event.stopPropagation()
...@@ -696,10 +694,10 @@ class Annotation ...@@ -696,10 +694,10 @@ class Annotation
$scope.rebuildHighlightText = -> $scope.rebuildHighlightText = ->
if annotator.text_regexp? if annotator.text_regexp?
$scope.model.$modelValue.highlightText = $scope.model.$modelValue.text $scope.model.highlightText = $scope.model.text
for regexp in annotator.text_regexp for regexp in annotator.text_regexp
$scope.model.$modelValue.highlightText = $scope.model.highlightText =
$scope.model.$modelValue.highlightText.replace regexp, annotator.highlighter $scope.model.highlightText.replace regexp, annotator.highlighter
class Editor class Editor
......
...@@ -6,19 +6,19 @@ authentication = -> ...@@ -6,19 +6,19 @@ authentication = ->
code: null code: null
link: (scope, elem, attr, ctrl) -> link: (scope, elem, attr, ctrl) ->
angular.extend scope, base angular.copy base, scope.model
controller: [ controller: [
'$scope', 'authentication', '$scope', 'authentication',
($scope, authentication) -> ($scope, authentication) ->
$scope.$on '$reset', => angular.extend $scope.model, base $scope.$on '$reset', => angular.copy base, $scope.model
$scope.submit = (form) -> $scope.submit = (form) ->
angular.extend authentication, $scope.model
return unless form.$valid return unless form.$valid
authentication["$#{form.$name}"] -> authentication["$#{form.$name}"] ->
$scope.$emit 'success', form.$name $scope.$emit 'success', form.$name
] ]
scope: restrict: 'ACE'
model: '=authentication'
markdown = ['$filter', '$timeout', ($filter, $timeout) -> markdown = ['$filter', '$timeout', ($filter, $timeout) ->
...@@ -84,11 +84,16 @@ privacy = -> ...@@ -84,11 +84,16 @@ privacy = ->
permissions permissions
scope.model = controller controller.$render = ->
scope.level = controller.$viewValue
scope.levels = levels scope.levels = levels
scope.setLevel = (level) ->
controller.$setViewValue level
controller.$render()
require: '?ngModel' require: '?ngModel'
restrict: 'E' restrict: 'E'
scope: true scope: {}
templateUrl: 'privacy.html' templateUrl: 'privacy.html'
...@@ -282,6 +287,7 @@ repeatAnim = -> ...@@ -282,6 +287,7 @@ repeatAnim = ->
itemElm itemElm
.css({ 'margin-left': itemElm.width() }) .css({ 'margin-left': itemElm.width() })
.animate({ 'margin-left': '0px' }, 1500) .animate({ 'margin-left': '0px' }, 1500)
return
# Directive to edit/display a tag list. # Directive to edit/display a tag list.
tags = ['$window', ($window) -> tags = ['$window', ($window) ->
...@@ -330,16 +336,13 @@ tags = ['$window', ($window) -> ...@@ -330,16 +336,13 @@ tags = ['$window', ($window) ->
] ]
notification = ['$filter', ($filter) -> notification = ['$filter', ($filter) ->
link: (scope, elem, attrs, controller) ->
return unless controller?
# Publish the controller
scope.model = controller
controller: 'NotificationController' controller: 'NotificationController'
priority: 100 # Must run before ngModel
require: '?ngModel' require: '?ngModel'
restrict: 'C' restrict: 'C'
scope: {} scope:
model: '=ngModel'
click: '&onClick'
close: '&onClose'
templateUrl: 'notification.html' templateUrl: 'notification.html'
] ]
......
...@@ -530,6 +530,7 @@ class Hypothesis extends Annotator ...@@ -530,6 +530,7 @@ class Hypothesis extends Annotator
discardDrafts: -> discardDrafts: ->
return @element.injector().get('drafts').discard() return @element.injector().get('drafts').discard()
class AuthenticationProvider class AuthenticationProvider
constructor: -> constructor: ->
@actions = @actions =
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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