2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
|
|
|
let content = ''
|
|
|
|
App.directive('addCommentEntry', () => ({
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: 'addCommentEntryTemplate',
|
|
|
|
scope: {
|
|
|
|
onStartNew: '&',
|
|
|
|
onSubmit: '&',
|
|
|
|
onCancel: '&'
|
|
|
|
},
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
scope.state = {
|
|
|
|
isAdding: false,
|
|
|
|
content: content
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.$on('comment:start_adding', () => scope.startNewComment())
|
|
|
|
scope.$on('$destroy', function() {
|
|
|
|
content = scope.state.content
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.startNewComment = function() {
|
|
|
|
scope.state.isAdding = true
|
|
|
|
scope.onStartNew()
|
|
|
|
setTimeout(() => scope.$broadcast('comment:new:open'))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.cancelNewComment = function() {
|
|
|
|
scope.state.isAdding = false
|
|
|
|
scope.state.content = ''
|
|
|
|
scope.onCancel()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.handleCommentKeyPress = function(ev) {
|
|
|
|
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
|
|
|
|
ev.preventDefault()
|
|
|
|
if (scope.state.content.length > 0) {
|
|
|
|
scope.submitNewComment()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.submitNewComment = function(event) {
|
|
|
|
scope.onSubmit({ content: scope.state.content })
|
|
|
|
content = scope.state.content
|
|
|
|
scope.state.isAdding = false
|
|
|
|
scope.state.content = ''
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
}))
|