Commit d30d7b72 authored by Randall Leeds's avatar Randall Leeds

View model helper methods for the annotation

Reduce the template logic and remove a use of 'group:__world__'.
parent 17b05012
...@@ -52,19 +52,41 @@ AnnotationController = [ ...@@ -52,19 +52,41 @@ AnnotationController = [
model = $scope.annotationGet() model = $scope.annotationGet()
original = null original = null
###*
# @ngdoc method
# @name annotation.AnnotationController#isComment.
# @returns {boolean} True if the annotation is a comment.
###
this.isComment = ->
not (model.target.length or model.references)
###*
# @ngdoc method
# @name annotation.AnnotationController#isHighlight.
# @returns {boolean} True if the annotation is a highlight.
###
this.isHighlight = ->
not (model.text or model.deleted or model.tags.length)
###*
# @ngdoc method
# @name annotation.AnnotationController#isPrivate
# @returns {boolean} True if the annotation is private to the current user.
###
this.isPrivate = ->
model.user and angular.equals(model.permissions?.read or [], [model.user])
###* ###*
# @ngdoc method # @ngdoc method
# @name annotation.AnnotationController#authorize # @name annotation.AnnotationController#authorize
# @param {string} action The action to authorize. # @param {string} action The action to authorize.
# @param {string=} principal Defaults to the current user. # @returns {boolean} True if the action is authorized for the current user.
# @returns {boolean} True if the action is authorized for the principal. # @description Checks whether the current user can perform an action on
# @description Checks whether the given principal can perform an action # the annotation.
# on the annotation.
### ###
this.authorize = (action, principal) -> this.authorize = (action) ->
return false unless model? return false unless model?
return true if 'group:__world__' in (model.permissions?[action] or []) annotator.plugins.Permissions?.authorize action, model
annotator.plugins.Permissions?.authorize action, model, principal
###* ###*
# @ngdoc method # @ngdoc method
...@@ -188,7 +210,7 @@ AnnotationController = [ ...@@ -188,7 +210,7 @@ AnnotationController = [
# Update once logged in. # Update once logged in.
$scope.$watch (-> model.user), (user) => $scope.$watch (-> model.user), (user) =>
if highlight and not model.references if highlight and this.isHighlight()
if user if user
annotator.publish 'annotationCreated', model annotator.publish 'annotationCreated', model
else else
...@@ -197,9 +219,7 @@ AnnotationController = [ ...@@ -197,9 +219,7 @@ AnnotationController = [
this.render() this.render()
# Start editing brand new annotations immediately # Start editing brand new annotations immediately
unless model.id? unless model.id? or this.isHighlight() then this.edit()
if model.references or not highlight or not model.target.length
this.edit()
this this
] ]
......
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