@@ -112,9 +112,10 @@ $(document).on('turbo-migration:load', function () {
112112 </div> \
113113 <div class="comment-content">' + commentText + '</div> \
114114 <textarea class="comment-editor">' + commentText + '</textarea> \
115- <div class="comment-actions' + ( comment . editable ? '' : ' d-none' ) + '"> \
116- <button class="action-edit btn btn-sm btn-warning">' + I18n . t ( 'shared.edit' ) + '</button> \
117- <button class="action-delete btn btn-sm btn-danger">' + I18n . t ( 'shared.destroy' ) + '</button> \
115+ <div class="comment-actions' + ( comment . editable || comment . reportable ? '' : ' d-none' ) + '"> \
116+ <button class="action-edit btn btn-sm btn-warning' + ( comment . editable ? '' : ' d-none' ) + '">' + I18n . t ( 'shared.edit' ) + '</button> \
117+ <button class="action-delete btn btn-sm btn-danger' + ( comment . editable ? '' : ' d-none' ) + '">' + I18n . t ( 'shared.destroy' ) + '</button> \
118+ <button class="action-report btn btn-light btn-sm' + ( comment . reportable ? '' : ' d-none' ) + '">' + I18n . t ( 'shared.report' ) + '</button> \
118119 </div> \
119120 </div>' ;
120121 } ) ;
@@ -166,6 +167,17 @@ $(document).on('turbo-migration:load', function () {
166167 } )
167168 }
168169
170+ function reportComment ( commentId , callback ) {
171+ const jqxhr = $ . ajax ( {
172+ type : 'POST' ,
173+ url : Routes . report_comment_path ( commentId )
174+ } ) ;
175+ jqxhr . done ( function ( ) {
176+ callback ( ) ;
177+ } ) ;
178+ jqxhr . fail ( ajaxError ) ;
179+ }
180+
169181 function deleteComment ( commentId , editor , file_id , callback ) {
170182 const jqxhr = $ . ajax ( {
171183 type : 'DELETE' ,
@@ -313,6 +325,17 @@ $(document).on('turbo-migration:load', function () {
313325 const container = otherComments . find ( '.container' ) ;
314326 container . html ( htmlContent ) ;
315327
328+ const reportButtons = container . find ( '.action-report' ) ;
329+ reportButtons . on ( 'click' , function ( event ) {
330+ const button = $ ( event . target ) ;
331+ const parent = $ ( button ) . parent ( ) . parent ( ) ;
332+ const commentId = parent . data ( 'comment-id' ) ;
333+
334+ reportComment ( commentId , function ( ) {
335+ parent . html ( '<div class="comment-reported">' + I18n . t ( 'comments.reported' ) + '</div>' ) ;
336+ } ) ;
337+ } ) ;
338+
316339 const deleteButtons = container . find ( '.action-delete' ) ;
317340 deleteButtons . on ( 'click' , function ( event ) {
318341 const button = $ ( event . target ) ;
0 commit comments