@@ -9,6 +9,10 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
9
9
< div class ="py-2 px-4 mb-4 bg-white rounded-lg rounded-t-lg border border-gray-200 ">
10
10
< label for ="comment " class ="sr-only "> Your comment</ label >
11
11
< input type ="text " id ="replying_to_input " hidden >
12
+ < input type ="hidden "
13
+ id ="content_type "
14
+ name ="content_type "
15
+ value ="{{ content_type }} ">
12
16
< div id ="replying_to_root "> </ div >
13
17
< div id ="add_update_label "> </ div >
14
18
< textarea id ="comment "
@@ -82,7 +86,7 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
82
86
data-name ="{{ comment.id }} "> Edit</ a >
83
87
</ li >
84
88
< li >
85
- < a class ="block py-2 px-4 hover:bg-gray-100 del_comment_issue2 cursor-pointer "
89
+ < a class ="block py-2 px-4 hover:bg-gray-100 del_comment cursor-pointer "
86
90
data-name ="{{ comment.id }} "> Delete</ a >
87
91
</ li >
88
92
< li >
@@ -151,7 +155,7 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
151
155
data-name ="{{ child_comment.id }} "> Edit</ a >
152
156
</ li >
153
157
< li >
154
- < a class ="block py-2 px-4 hover:bg-gray-100 del_comment_issue2 cursor-pointer "
158
+ < a class ="block py-2 px-4 hover:bg-gray-100 del_comment cursor-pointer "
155
159
data-name ="{{ child_comment.id }} "> Delete</ a >
156
160
</ li >
157
161
< li >
@@ -162,12 +166,6 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
162
166
{% endif %}
163
167
</ footer >
164
168
< p class ="text-xl main_text "> {{ child_comment.text | safe }}</ p >
165
- <!-- <div class="flex items-center mt-4 space-x-4">
166
- <button type="button" class="flex items-center text-md text-gray-500 hover:underline ">
167
- <svg aria-hidden="true" class="mr-1 w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path></svg>
168
- {{ child_comment.children | length }} Replies
169
- </button>
170
- </div> -->
171
169
</ article >
172
170
{% endfor %}
173
171
</ div >
@@ -192,7 +190,6 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
192
190
} ) ;
193
191
}
194
192
195
-
196
193
function remove_reply ( ) {
197
194
document . getElementById ( "replying_to_cont" ) . remove ( ) ;
198
195
document . getElementById ( "replying_to_input" ) . value = "" ;
@@ -221,9 +218,10 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
221
218
comment_container . toggleAttribute ( 'hidden' ) ;
222
219
}
223
220
224
- function comment_on_issue ( e ) {
221
+ function comment_on_content ( e ) {
225
222
e . preventDefault ( ) ;
226
- let issue_pk = '{{ object.pk|safe }}' ;
223
+ let content_pk = '{{ object.pk|safe }}' ;
224
+ let content_type = '{{ content_type }}' ;
227
225
var csrftoken = $ ( "[name=csrfmiddlewaretoken]" ) . val ( ) ; // Get the CSRF token value
228
226
229
227
let replying_to_input = document . getElementById ( "replying_to_input" ) . value ;
@@ -233,25 +231,26 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
233
231
}
234
232
$ . ajax ( {
235
233
type : 'POST' ,
236
- url : '/issue /' + issue_pk + '/comment/' ,
234
+ url : '/content /' + content_pk + '/comment/' ,
237
235
data : {
238
236
"replying_to_input" :replying_to_input ,
239
- "comment" :comment
237
+ "comment" :comment ,
238
+ "content_type" : content_type
240
239
} ,
241
240
beforeSend : function ( xhr , settings ) {
242
241
xhr . setRequestHeader ( "X-CSRFToken" , csrftoken ) ; // Set the CSRF token in the request header
243
242
} ,
244
243
success : function ( data ) {
245
244
$ ( '#comment_root' ) . replaceWith ( data ) ;
246
- // initDropDown();
247
245
location . reload ( )
248
246
} ,
249
247
} ) ;
250
248
}
251
- $ ( '#post_comment_btn' ) . click ( ( e ) => comment_on_issue ( e ) )
249
+ $ ( '#post_comment_btn' ) . click ( ( e ) => comment_on_content ( e ) )
252
250
function update_comment ( e , comment_id ) {
253
251
e . preventDefault ( ) ;
254
- let issue_pk = '{{ object.pk|safe }}' ;
252
+ let content_pk = '{{ object.pk|safe }}' ;
253
+ let content_type = '{{ content_type }}' ;
255
254
var csrftoken = $ ( "[name=csrfmiddlewaretoken]" ) . val ( ) ; // Get the CSRF token value
256
255
257
256
let comment = document . getElementById ( "comment" ) . value ;
@@ -260,16 +259,16 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
260
259
}
261
260
$ . ajax ( {
262
261
type : 'POST' ,
263
- url : '/issue /' + issue_pk + '/comment/update/' + comment_id + '/' ,
262
+ url : '/content /' + content_pk + '/comment/update/' + comment_id + '/' ,
264
263
data : {
265
- "comment" :comment
264
+ "comment" :comment ,
265
+ "content_type" : content_type
266
266
} ,
267
267
beforeSend : function ( xhr , settings ) {
268
268
xhr . setRequestHeader ( "X-CSRFToken" , csrftoken ) ; // Set the CSRF token in the request header
269
269
} ,
270
270
success : function ( data ) {
271
271
$ ( '#comment_root' ) . replaceWith ( data ) ;
272
- // initDropDown();
273
272
location . reload ( )
274
273
} ,
275
274
} ) ;
@@ -281,15 +280,13 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
281
280
$ ( '#update_comment_btn' ) . text ( 'Post comment' ) ;
282
281
$ ( '#update_comment_btn' ) . attr ( 'id' , 'post_comment_btn' ) ;
283
282
$ ( '#update_comment_btn' ) . off ( 'click' ) ;
284
- $ ( '#post_comment_btn' ) . off ( 'click' ) . on ( 'click' , ( e ) => comment_on_issue ( e ) ) ;
283
+ $ ( '#post_comment_btn' ) . off ( 'click' ) . on ( 'click' , ( e ) => comment_on_content ( e ) ) ;
285
284
}
286
285
$ ( 'body' ) . on ( 'click' , '.edit_comment' , function ( e ) {
287
286
e . preventDefault ( ) ;
288
287
let comment_id = $ ( this ) . data ( 'name' ) ;
289
288
let comment_text = $ ( this ) . closest ( 'article' ) . find ( '.main_text' ) . text ( ) ;
290
- // Unbind the click event for the post_comment_btn
291
289
$ ( '#post_comment_btn' ) . off ( 'click' ) ;
292
- //user can update the form using #comments form
293
290
$ ( '#comment' ) . val ( comment_text ) ;
294
291
$ ( '#post_comment_btn' ) . text ( 'Update comment' ) ;
295
292
$ ( '#post_comment_btn' ) . attr ( 'id' , 'update_comment_btn' ) ;
@@ -298,59 +295,36 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
298
295
<p>Update your Comment<p>
299
296
<i onclick="remove_update_label()" class="fa-solid fa-xmark ml-3 text-3xl font-bold text-gray-600 hover:text-black"></i>
300
297
</div>` ;
301
- // Bind a new click event for the update_comment_btn
302
298
$ ( '#update_comment_btn' ) . off ( 'click' ) . on ( 'click' , ( e ) => update_comment ( e , comment_id ) ) ;
303
299
} ) ;
304
- $ ( 'body' ) . off ( 'click' , '.del_comment_issue2 ' ) . on ( 'click' , '.del_comment_issue2 ' , function ( e ) {
300
+ $ ( 'body' ) . off ( 'click' , '.del_comment ' ) . on ( 'click' , '.del_comment ' , function ( e ) {
305
301
e . preventDefault ( ) ;
306
302
307
- // Store a reference to the clicked element
308
303
var clickedElement = $ ( this ) ;
309
304
if ( confirm ( "Delete this comment?" ) == true ) {
310
305
var csrftoken = $ ( "[name=csrfmiddlewaretoken]" ) . val ( ) ;
311
306
312
307
$ . ajax ( {
313
308
type : 'POST' ,
314
- url : "/issue /comment/delete/" ,
309
+ url : "/content /comment/delete/" ,
315
310
data : {
316
311
"comment_pk" : clickedElement . attr ( 'data-name' ) ,
317
- "issue_pk" : '{{ object.pk|safe }}' ,
312
+ "content_pk" : '{{ object.pk|safe }}' ,
313
+ "content_type" : '{{ content_type }}'
318
314
} ,
319
315
beforeSend : function ( xhr , settings ) {
320
316
xhr . setRequestHeader ( "X-CSRFToken" , csrftoken ) ; // Set the CSRF token in the request header
321
317
} ,
322
318
success : function ( data ) {
323
- // Replace the content of #comment_root with the new data
324
319
$ ( '#comment_root' ) . replaceWith ( data ) ;
325
-
326
- // initDropDown();
327
320
location . reload ( )
328
321
} ,
329
322
} ) ;
330
323
}
331
324
} ) ;
332
- // refresh comments after x interval
333
- // function get_comments(){
334
- // let issue_pk = '{{ object.pk|safe }}';
335
-
336
- // $.ajax({
337
- // type: 'GET',
338
- // url: '/issue/' + issue_pk + '/comment/',
339
- // data: {},
340
- // success: function (data) {
341
- // $('#comment_root').html(data);
342
- // }
343
- // });
344
- // }
345
-
346
- // setInterval(get_comments, 10000);
347
325
348
326
$ ( document ) . ready ( function ( ) {
349
- // bind event handlers when the page loads.
350
327
initDropDown ( ) ;
351
328
} ) ;
352
-
353
-
354
-
355
329
</ script >
356
330
</ section >
0 commit comments