overleaf/services/web/frontend/js/ide/review-panel/directives/addCommentEntry.js
Alasdair Smith bc1b73d74e Merge pull request #2515 from overleaf/as-transform-absolute-paths
Transform absolute paths in frontend to relative

GitOrigin-RevId: c1914c0fd09d68984ba6c85a1f00aa3e6858d944
2020-04-07 03:18:45 +00:00

51 lines
1.3 KiB
JavaScript

define(['../../../base'], App => {
let content = ''
App.directive('addCommentEntry', () => ({
restrict: 'E',
templateUrl: 'addCommentEntryTemplate',
scope: {
onStartNew: '&',
onSubmit: '&',
onCancel: '&'
},
link(scope, element, attrs) {
scope.state = {
isAdding: false,
content: content
}
scope.$on('comment:start_adding', () => scope.startNewComment())
scope.$on('$destroy', function() {
content = scope.state.content
})
scope.startNewComment = function() {
scope.state.isAdding = true
scope.onStartNew()
setTimeout(() => scope.$broadcast('comment:new:open'))
}
scope.cancelNewComment = function() {
scope.state.isAdding = false
scope.state.content = ''
scope.onCancel()
}
scope.handleCommentKeyPress = function(ev) {
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
ev.preventDefault()
if (scope.state.content.length > 0) {
scope.submitNewComment()
}
}
}
scope.submitNewComment = function(event) {
scope.onSubmit({ content: scope.state.content })
content = scope.state.content
scope.state.isAdding = false
scope.state.content = ''
}
}
}))
})