Commit 52673232 authored by Randall Leeds's avatar Randall Leeds

Fix all the ngModel usage for Angular 1.2

In Angular v1.2 what has actually changed about isolate scopes is that
only the directive declaring isolation gets the isolate scope. Its
template will inherit this scope, but other directives on the element
will not. That's the reason ngModel now works with `$parent`.

Everywhere we were binding the controller to the scope it's easier to
use the isolate binding with `=ngModel`.
parent 9e45109d
......@@ -9,29 +9,26 @@ annotation = ['$filter', 'annotator', ($filter, annotator) ->
scope.save(e)
# Watch for changes
scope.$watch 'model.$modelValue.id', (id) ->
scope.thread = annotator.threading.idTable[id]
scope.$watch 'model', (model) ->
scope.thread = annotator.threading.idTable[model.id]
scope.auth = {}
scope.auth.delete =
if scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'delete', scope.model.$modelValue
if model? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'delete', model
else
true
scope.auth.update =
if scope.model.$modelValue? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'update', scope.model.$modelValue
if scope.model? and annotator.plugins?.Permissions?
annotator.plugins.Permissions.authorize 'update', model
else
true
# Publish the controller
scope.model = controller
controller: 'AnnotationController'
priority: 100 # Must run before ngModel
require: '?ngModel'
restrict: 'C'
scope:
model: '=ngModel'
mode: '@'
replies: '@'
templateUrl: 'annotation.html'
......
......@@ -540,20 +540,20 @@ class Annotation
$scope.cancel = ($event) ->
$event?.stopPropagation()
$scope.editing = false
drafts.remove $scope.model.$modelValue
drafts.remove $scope.model
annotator.enableAnnotating drafts.isEmpty()
switch $scope.action
when 'create'
annotator.deleteAnnotation $scope.model.$modelValue
annotator.deleteAnnotation $scope.model
else
$scope.model.$modelValue.text = $scope.origText
$scope.model.$modelValue.tags = $scope.origTags
$scope.model.text = $scope.origText
$scope.model.tags = $scope.origTags
$scope.action = 'create'
$scope.save = ($event) ->
$event?.stopPropagation()
annotation = $scope.model.$modelValue
annotation = $scope.model
# Forbid saving comments without a body (text or tags)
if annotator.isComment(annotation) and not annotation.text and
......@@ -610,14 +610,13 @@ class Annotation
$event?.stopPropagation()
$scope.action = 'edit'
$scope.editing = true
$scope.origText = $scope.model.$modelValue.text
$scope.origTags = $scope.model.$modelValue.tags
drafts.add $scope.model.$modelValue, -> $scope.cancel()
$scope.origText = $scope.model.text
$scope.origTags = $scope.model.tags
drafts.add $scope.model, -> $scope.cancel()
annotator.disableAnnotating()
$scope.delete = ($event) ->
$event?.stopPropagation()
annotation = $scope.model.$modelValue
replies = $scope.thread.children?.length or 0
# We can delete the annotation if it hasn't got any replies or it is
......@@ -632,27 +631,26 @@ class Annotation
annotator.plugins.Permissions.authorize 'delete', reply
annotator.deleteAnnotation reply
annotator.deleteAnnotation annotation
annotator.deleteAnnotation $scope.model
else
$scope.action = 'delete'
$scope.editing = true
$scope.origText = $scope.model.$modelValue.text
$scope.origTags = $scope.model.$modelValue.tags
$scope.model.$modelValue.text = ''
$scope.model.$modelValue.tags = ''
$scope.origText = $scope.model.text
$scope.origTags = $scope.model.tags
$scope.model.text = ''
$scope.model.tags = ''
$scope.$watch 'editing', -> $scope.$emit 'toggleEditing'
$scope.$watch 'model.$modelValue.id', (id) ->
$scope.$watch 'model.id', (id) ->
if id?
annotation = $scope.model.$modelValue
$scope.thread = annotation.thread
$scope.thread = $scope.model.thread
# Check if this is a brand new annotation
if annotation? and drafts.contains annotation
if drafts.contains $scope.model
$scope.editing = true
$scope.$watch 'model.$modelValue.target', (targets) ->
$scope.$watch 'model.target', (targets) ->
return unless targets
for target in targets
if target.diffHTML?
......@@ -674,16 +672,14 @@ class Annotation
# is not a pre-determined route map. One possibility would be to
# unify everything so that it's relative to the app URL.
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.$watchCollection 'model.$modelValue.thread.children', (newValue=[]) ->
annotation = $scope.model.$modelValue
return unless annotation
$scope.$watchCollection 'model.thread.children', (newValue=[]) ->
return unless $scope.model
replies = (r.message for r in newValue)
replies = replies.sort(annotator.sortAnnotations).reverse()
annotation.reply_list = replies
$scope.model.reply_list = replies
$scope.toggle = ->
$element.find('.share-dialog').slideToggle()
......@@ -696,10 +692,10 @@ class Annotation
$scope.rebuildHighlightText = ->
if annotator.text_regexp?
$scope.model.$modelValue.highlightText = $scope.model.$modelValue.text
$scope.model.highlightText = $scope.model.text
for regexp in annotator.text_regexp
$scope.model.$modelValue.highlightText =
$scope.model.$modelValue.highlightText.replace regexp, annotator.highlighter
$scope.model.highlightText =
$scope.model.highlightText.replace regexp, annotator.highlighter
class Editor
......
......@@ -77,11 +77,16 @@ privacy = ->
permissions
scope.model = controller
controller.$render = ->
scope.level = controller.$viewValue
scope.levels = levels
scope.setLevel = (level) ->
controller.$setViewValue level
controller.$render()
require: '?ngModel'
restrict: 'E'
scope: true
scope: {}
templateUrl: 'privacy.html'
......@@ -323,16 +328,13 @@ tags = ['$window', ($window) ->
]
notification = ['$filter', ($filter) ->
link: (scope, elem, attrs, controller) ->
return unless controller?
# Publish the controller
scope.model = controller
controller: 'NotificationController'
priority: 100 # Must run before ngModel
require: '?ngModel'
restrict: 'C'
scope: {}
scope:
model: '=ngModel'
click: '&onClick'
close: '&onClose'
templateUrl: 'notification.html'
]
......
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