2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
export default App.directive('commentEntry', $timeout => ({
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: 'commentEntryTemplate',
|
|
|
|
scope: {
|
|
|
|
entry: '=',
|
|
|
|
threads: '=',
|
|
|
|
permissions: '=',
|
|
|
|
onResolve: '&',
|
|
|
|
onReply: '&',
|
|
|
|
onIndicatorClick: '&',
|
|
|
|
onSaveEdit: '&',
|
|
|
|
onDelete: '&',
|
|
|
|
onBodyClick: '&'
|
|
|
|
},
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
scope.state = { animating: false }
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
element.on('click', function(e) {
|
|
|
|
if (
|
|
|
|
$(e.target).is(
|
|
|
|
'.rp-entry, .rp-comment-loaded, .rp-comment-content, .rp-comment-reply, .rp-entry-metadata'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return scope.onBodyClick()
|
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.handleCommentReplyKeyPress = function(ev) {
|
|
|
|
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
|
|
|
|
ev.preventDefault()
|
|
|
|
if (scope.entry.replyContent.length > 0) {
|
|
|
|
ev.target.blur()
|
|
|
|
return scope.onReply()
|
|
|
|
}
|
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.animateAndCallOnResolve = function() {
|
|
|
|
scope.state.animating = true
|
|
|
|
element.find('.rp-entry').css('top', 0)
|
|
|
|
$timeout(() => scope.onResolve(), 350)
|
|
|
|
return true
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.startEditing = function(comment) {
|
|
|
|
comment.editing = true
|
|
|
|
return setTimeout(() => scope.$emit('review-panel:layout'))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.saveEdit = function(comment) {
|
|
|
|
comment.editing = false
|
|
|
|
return scope.onSaveEdit({ comment })
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.confirmDelete = function(comment) {
|
|
|
|
comment.deleting = true
|
|
|
|
return setTimeout(() => scope.$emit('review-panel:layout'))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.cancelDelete = function(comment) {
|
|
|
|
comment.deleting = false
|
|
|
|
return setTimeout(() => scope.$emit('review-panel:layout'))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.doDelete = function(comment) {
|
|
|
|
comment.deleting = false
|
|
|
|
return scope.onDelete({ comment })
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
|
|
|
return (scope.saveEditOnEnter = function(ev, comment) {
|
|
|
|
if (ev.keyCode === 13 && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
|
|
|
|
ev.preventDefault()
|
|
|
|
return scope.saveEdit(comment)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}))
|