2016-11-16 10:47:05 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.directive "addCommentEntry", () ->
|
|
|
|
restrict: "E"
|
|
|
|
templateUrl: "addCommentEntryTemplate"
|
|
|
|
scope:
|
|
|
|
onStartNew: "&"
|
|
|
|
onSubmit: "&"
|
|
|
|
onCancel: "&"
|
2016-11-16 11:13:39 -05:00
|
|
|
onIndicatorClick: "&"
|
2016-11-16 10:47:05 -05:00
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
scope.state =
|
|
|
|
isAdding: false
|
|
|
|
content: ""
|
|
|
|
|
|
|
|
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()
|
|
|
|
ev.target.blur()
|
|
|
|
scope.submitNewComment()
|
|
|
|
|
|
|
|
scope.submitNewComment = () ->
|
|
|
|
scope.onSubmit { content: scope.state.content }
|
|
|
|
scope.state.isAdding = false
|
|
|
|
scope.state.content = ""
|