overleaf/services/web/public/coffee/ide/review-panel/directives/commentEntry.coffee

60 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2016-11-16 10:12:58 -05:00
define [
"base"
], (App) ->
2017-01-12 06:25:36 -05:00
App.directive "commentEntry", ($timeout) ->
2016-11-16 10:12:58 -05:00
restrict: "E"
templateUrl: "commentEntryTemplate"
scope:
entry: "="
2016-12-16 11:42:41 -05:00
threads: "="
permissions: "="
2016-11-16 10:12:58 -05:00
onResolve: "&"
onReply: "&"
onIndicatorClick: "&"
onSaveEdit: "&"
onDelete: "&"
2016-11-16 10:12:58 -05:00
link: (scope, element, attrs) ->
2017-01-12 06:25:36 -05:00
scope.state =
animating: false
2016-11-16 10:12:58 -05:00
scope.handleCommentReplyKeyPress = (ev) ->
if ev.keyCode == 13 and !ev.shiftKey and !ev.ctrlKey and !ev.metaKey
ev.preventDefault()
2017-01-16 12:14:06 -05:00
if scope.entry.replyContent.length > 0
2017-01-16 12:06:57 -05:00
ev.target.blur()
scope.onReply()
2017-01-12 06:25:36 -05:00
scope.animateAndCallOnResolve = () ->
scope.state.animating = true
element.find(".rp-entry").css("top", 0)
$timeout((() -> scope.onResolve()), 350)
return true
scope.startEditing = (comment) ->
comment.editing = true
setTimeout () ->
scope.$emit "review-panel:layout"
scope.saveEdit = (comment) ->
comment.editing = false
scope.onSaveEdit({comment:comment})
scope.confirmDelete = (comment) ->
comment.deleting = true
setTimeout () ->
scope.$emit "review-panel:layout"
scope.cancelDelete = (comment) ->
comment.deleting = false
setTimeout () ->
scope.$emit "review-panel:layout"
scope.doDelete = (comment) ->
comment.deleting = false
scope.onDelete({comment: comment})
scope.saveEditOnEnter = (ev, comment) ->
if ev.keyCode == 13 and !ev.shiftKey and !ev.ctrlKey and !ev.metaKey
ev.preventDefault()
scope.saveEdit(comment)