2016-11-16 10:47:05 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.directive "addCommentEntry", () ->
|
|
|
|
restrict: "E"
|
|
|
|
templateUrl: "addCommentEntryTemplate"
|
|
|
|
scope:
|
|
|
|
onStartNew: "&"
|
|
|
|
onSubmit: "&"
|
2017-03-20 09:56:36 -04:00
|
|
|
onCancel: "&"
|
2016-11-16 10:47:05 -05:00
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
scope.state =
|
|
|
|
isAdding: false
|
|
|
|
content: ""
|
|
|
|
|
2017-03-20 07:18:29 -04:00
|
|
|
scope.$on "comment:start_adding", () ->
|
|
|
|
scope.startNewComment()
|
|
|
|
|
2016-11-16 10:47:05 -05:00
|
|
|
scope.startNewComment = () ->
|
|
|
|
scope.state.isAdding = true
|
|
|
|
scope.onStartNew()
|
2017-01-16 09:17:56 -05:00
|
|
|
setTimeout () ->
|
|
|
|
scope.$broadcast "comment:new:open"
|
2016-11-16 10:47:05 -05:00
|
|
|
|
|
|
|
scope.cancelNewComment = () ->
|
|
|
|
scope.state.isAdding = false
|
|
|
|
scope.onCancel()
|
|
|
|
|
|
|
|
scope.handleCommentKeyPress = (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.state.content.length > 0
|
|
|
|
scope.submitNewComment()
|
2016-11-16 10:47:05 -05:00
|
|
|
|
2017-03-08 06:38:28 -05:00
|
|
|
scope.submitNewComment = (event) ->
|
|
|
|
# If this is from a blur event from clicking on cancel, ignore it.
|
|
|
|
if event? and event.type == "blur" and $(event.relatedTarget).hasClass("rp-entry-button-cancel")
|
|
|
|
return true
|
2016-11-16 10:47:05 -05:00
|
|
|
scope.onSubmit { content: scope.state.content }
|
|
|
|
scope.state.isAdding = false
|
2017-02-14 07:41:04 -05:00
|
|
|
scope.state.content = ""
|