1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
{% extends 'website/templates/base.html' %}
{% load static %}
{% load widget_tweaks %}
{% load permission_tags %}
{% block title %}
{{ question.category }} - {{ question.title }} - FOSSEE Forums
{% endblock %}
{% block content %}
<span class="saving hideme">saving . . .</span>
<span class="saved hideme">saved</span>
<div class="row">
<div class="question-wrapper col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="question {% if user|can_edit:question %}editable{% endif %}" >
<!-- VOTE CELL -->
<div class="votecell" style="padding-top: 0.0cm;">
<div class="vote">
{% ifequal thisUserUpvote 0 %}
<img src="{% static 'website/images/up1-off.png' %}" class="vote-up" title="This question shows research effort; it is useful and clear"/>
{% else %}
<img src="{% static 'website/images/up1-on.png' %}" class="vote-up selected" title="This question shows research effort; it is useful and clear"/>
{% endifequal %}
<span class="vote-count-post" id="show_vote_count">
{{ net_count }}
</span>
{% ifequal thisUserDownvote 0 %}
<img src="{% static 'website/images/down1-off.png' %}" class="vote-down" title="This question does not show any research effort; it is not useful and unclear"/>
{% else %}
<img src="{% static 'website/images/down1-on.png' %}" class="vote-down selected" title="This question does not show any research effort; it is not useful and unclear"/>
{% endifequal %}
</div>
</div>
<div class="title {% if user|can_edit:question %}title-editable{% endif %}">
{{ question.title }}
</div>
<div id="title-edit" class="hideme">
<h5>Title</h5>
<input class="form-control" type="text">
<h5>Question</h5>
</div>
<div id="questionNicPanel"></div>
<div id="{% if user|can_edit:question %}questionInstance{% endif %}" class="body" style="margin-left : 60px">
{{ question.body|safe }}
</div>
<br>
<span class="category">
<small>
<a href="{% url 'website:filter' question.category %}">
{{ question.category }}
</a>
</small>
</span>
<a id="question-details-edit" data-toggle="modal" data-target="#detailsModal" href="#" class="hideme">
<span class="glyphicon glyphicon-edit"></span>
</a>
<span class="modify">
{% if user|can_edit:question %}
<a class="edit btn btn-xs btn-info" href="#">Edit</a>
<a class="save btn btn-xs btn-success" data-qid="{{ question.id }}" href="#">Save</a>
{% endif %}
</span>
<span class="meta">
<small>
<i>
{{ question.date_created|date:"d-m-y" }}, {{ question.date_created|time }}
</i>
</small>
<span class="user">
{{ question.user }}
</span>
</span>
</div> <!-- /.question -->
</div>
</div> <!-- /.row -->
<h4><u>Answers:</u></h4>
<div id="answerPanelWrapper" style="display:none;">
<div id="answerNicPanel" style="display:none;"></div>
</div>
<div id="commentPanelWrapper" style="display:none;">
<div id="commentNicPanel" style="display:none;"></div>
</div>
{% for answer,ans_vote in main_list %}
<div class="row">
<div class="answer-wrapper col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="votecell" style="padding-top: 9px;">
<div class="ans-vote" >
{% ifequal ans_vote.0 0 %}
<img src="{% static 'website/images/up1-off.png' %}" class="ans-vote-up" id="up{{ answer.id }}" title="This question shows research effort; it is useful and clear"/>
{% else %}
<img src="{% static 'website/images/up1-on.png' %}" class="ans-vote-up selected" id="up{{ answer.id }}" title="This question shows research effort; it is useful and clear"/>
{% endifequal %}
<span class="vote-count-post" id="span{{ answer.id }}" >
{{ ans_vote.2 }}
</span>
{% ifequal ans_vote.1 0 %}
<img type="image" src="{% static 'website/images/down1-off.png' %}" class="ans-vote-down" id="down{{ answer.id }}" title="This question does not show any research effort; it is not useful and unclear" />
{% else %}
<img src="{% static 'website/images/down1-on.png' %}" class="ans-vote-down selected" id="down{{ answer.id }}" title="This question does not show any research effort; it is not useful and unclear"/>
{% endifequal %}
</div>
</div>
<div class="answer {% if user|can_edit:answer %}editable{% endif %}" id="answer{{answer.id}}" style="margin-left: 63px;">
<div class="body" id="body{{ answer.id }}" style="padding-bottom: 12px">
{{ answer.body|safe }}
</div>
<span class="meta">
<small>
<i>
{{ answer.date_created|date:"d-m-y" }}, {{ answer.date_created|time }}
</i>
</small>
<span class="user" style="background-color: #FFFFFF;padding: 2px 7px">
{{ answer.user }}
</span>
</span>
{% if user|can_edit:answer %}
<span class="modify" style="display:block">
<a class="edit btn btn-xs btn-info vs" href="#body{{ answer.id}}" data-target="body{{ answer.id }}">Edit</a>
<a class="save btn btn-xs btn-success vs" data-target="body{{ answer.id }}" data-aid="{{ answer.id }}" href="#">Save</a>
</span>
{% endif %}
</div> <!-- /.answer -->
<div class="row">
<div class="comments pull-right col-lg-11 col-md-11 col-sm-11 col-xs-11">
<!-- displaying comments -->
{% for comment in answer.answercomment_set.all %}
<div class="comment comment{{ comment.id }}">
<div class="body" id="cbody{{ comment.id }}">
{{ comment.body|safe }}
</div>
<span class="meta_co" style="position: absolute;right: 0px; bottom: 0px;">
<small>
<i>
{{ comment.date_created|date:"d-m-y" }}, {{ comment.date_created|time }}
</i>
</small>
<span class="user_co" style="padding: 2px 7px">
{{ comment.user }}
</span>
</span>
{% if user|can_edit:comment %}
<div class="modify-wrapper">
<span class="modify" style="display:block">
<a class="edit btn btn-xs btn-info vs" href="#cbody{{ comment.id }}" data-target="cbody{{ comment.id }}">Edit</a>
<a class="save btn btn-xs btn-success vs" data-target="cbody{{ comment.id }}" data-cid="{{ comment.id }}" href="#">Save</a>
</span>
</div>
{% endif %}
</div> <!-- /.comment -->
{% endfor %}
<!-- form to add comment -->
{% if user.is_authenticated %}
<form id="form{{ answer.id }}" method="post" action="/answer-comment/"> {% csrf_token %}
<input type="hidden" name="answer_id" value="{{ answer.id }}">
<textarea name="body" class="new-comment form-control" id="comment{{ answer.id }}" rows="2"></textarea>
</form>
<a class="add-comment" style="background: #46B8DA none repeat scroll 0% 0%;color: #FFF;border-radius: 3px;padding: 5px 12px;" href="#" data-target="comment{{ answer.id }}">
<small>add comment</small>
</a>
<a class="post-comment" href="#" data-target="comment{{ answer.id }}" data-aid="{{ answer.id }}" data-form="form{{ answer.id }}">
<small>post comment</small>
</a>
<a class="cancel-comment" href="#" data-target="comment{{ answer.id }}">
<small>cancel comment</small>
</a>
{% else %}
<br>
<a class="btn btn-xs btn-success vs" href="/accounts/login">
Login to add comment
</a>
{% endif %}
</div> <!-- comments -->
</div> <!-- /.row -->
<br> <hr>
</div> <!-- /.answer-wrapper -->
</div> <!-- /.row -->
{% endfor %}
{% if user.is_authenticated %}
<form action="{% url 'website:question_answer' question.id %}" method="POST"> {% csrf_token %}
{% with WIDGET_ERROR_CLASS='field_error' %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
{{ form.body.errors }}
<div class="form-group">
{% render_field form.question value=question.id %}
<label for="id_body"><h4><u>Your Answer:</u></h4></label>
{% render_field form.body class+='form-control' %}
</div>
</div>
</div>
{% endwith %}
<input class="btn btn-sm btn-info" type="submit" value="Submit Answer">
</form>
{% else %}
<h4>
<a class="btn btn-xs btn-success" href="{% url 'user_login'%}"><b>Log-in</b></a> to answer to this question.
</h4>
{% endif %}
<!-- Modal -->
<div class="modal fade" id="detailsModal" tabindex="-1" role="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Edit Question Details</h4>
</div>
<div class="modal-body">
<h5>The Current question is under:</h5>
{{ question.category }}
<hr>
<div class="pull-right">
<a id="question-details-ok" class="btn btn-sm btn-success hideme" data-qid={{ question.id }} href="#">Ok</a>
<a class="btn btn-sm btn-default" data-dismiss="modal" href="#">Close</a>
</div>
<div class="clearfix"></div>
</div> <!-- /.modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- AJAX SCRIPT -->
{% endblock %}
{% block javascript %}
<script src="{% static 'website/js/nicEdit.js' %}" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({
iconsPath: "{% static 'website/js/nicEditorIcons.gif' %}",
buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','html','image', 'link']
}).panelInstance('id_body');
});
</script>
<script type="text/javascript">
/* For random color */
$(".user_co").each(function() {
var hue = 'rgb(' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ')';
$(this).css("background-color", hue);
});
$(document).ready(function() {
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
/* VOTE FOR QUESTION */
$('div.vote img.vote-up').click(function() {
var id = {{ question.pk }};
var vote_type = 'up';
/* USER HAS ALREADY VOTED */
if ($(this).hasClass('selected')) {
var vote_action = 'recall-vote'
$.post('/vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img.vote-up').removeAttr('src')
.attr('src', '{% static 'website/images/up1-off.png' %}')
.removeClass('selected');
$('div.vote span.vote-count-post').html(response);
$('img.vote-down').css('pointer-events','all');
});
}
/* USER WISHES TO VOTE */
else {
var vote_action = 'vote'
$.post('/vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img.vote-up').removeAttr('src')
.attr('src', '{% static 'website/images/up1-on.png' %}')
.addClass('selected');
$('div.vote span.vote-count-post').html(response);
$('img.vote-down').css('pointer-events','none');
});
}
});
/* DOWNVOTE */
$('div.vote img.vote-down').click(function() {
var id = {{ question.pk }};
var vote_type = 'down';
/* USER HAS ALREADY DOWN-VOTED */
if ($(this).hasClass('selected')) {
var vote_action = 'recall-vote'
$.post('/vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img.vote-down').removeAttr('src')
.attr('src', '{% static 'website/images/down1-off.png' %}')
.removeClass('selected');
$('div.vote span.vote-count-post').html(response);
$('img.vote-up').css('pointer-events','all');
});
}
/* USER WISHES TO VOTE */
else {
var vote_action = 'vote'
$.post('/vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img.vote-down').removeAttr('src')
.attr('src', '{% static 'website/images/down1-on.png' %}')
.addClass('selected');
$('div.vote span.vote-count-post').html(response);
$('img.vote-up').css('pointer-events','none');
});
}
});
/* VOTE FOR ANSWERS */
/* UP VOTE */
$('div.ans-vote img.ans-vote-up').click(function(event) {
var up_id = event.target.id;
var vote_type = 'up';
var id = up_id.replace('up','');
if ($('img#'+up_id).hasClass('selected')) {
var vote_action = 'recall-vote'
$.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img#'+up_id).removeAttr('src')
.attr('src', '{% static 'website/images/up1-off.png' %}')
.removeClass('selected');
$('span#span'+id).html(response);
$('img#down'+id).css('pointer-events','all');
});
}
/* USER WISHES TO VOTE */
else {
var vote_action = 'vote'
$.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img#'+up_id).removeAttr('src')
.attr('src', '{% static 'website/images/up1-on.png' %}')
.addClass('selected');
$('span#span'+id).html(response);
$('img#down'+id).css('pointer-events','none');
});
}
}); /* END OF UP VOTE FOR ANSWERS */
/* DOWNVOTE */
$('div.ans-vote img.ans-vote-down').click(function(event) {
var down_id = event.target.id;
var vote_type = 'down';
var id = down_id.replace('down','');
/* USER HAS ALREADY DOWN-VOTED */
if ($('img#'+down_id).hasClass('selected')) {
var vote_action = 'recall-vote'
$.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img#'+down_id).removeAttr('src')
.attr('src', '{% static 'website/images/down1-off.png' %}')
.removeClass('selected');
$('div.ans-vote span#span'+id).html(response);
$('img#up'+id).css('pointer-events','all')
});
}
/* USER WISHES TO VOTE */
else {
var vote_action = 'vote'
$.post('/ans_vote_post/', {id:id, type:vote_type, action:vote_action}, function(response) {
$('img#'+down_id).removeAttr('src')
.attr('src', '{% static 'website/images/down1-on.png' %}')
.addClass('selected');
$('div.ans-vote span#span'+id).html(response);
$('img#up'+id).css('pointer-events','none')
});
}
});
});
</script>
<script src="{% static 'website/js/thread-user.js' %}"></script>
<script src="{% static 'website/js/custom.js' %}"></script>
{% endblock %}
|