commit
0b48a1f490
10 changed files with 422 additions and 17637 deletions
@ -0,0 +1,17 @@ |
|||||||
|
# Generated by Django 2.0.1 on 2018-01-30 12:48 |
||||||
|
|
||||||
|
from django.db import migrations |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('course', '0017_auto_20180130_0810'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterModelOptions( |
||||||
|
name='comment', |
||||||
|
options={'ordering': ('-created_at',)}, |
||||||
|
), |
||||||
|
] |
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,60 @@ |
|||||||
|
import $ from 'jquery'; |
||||||
|
|
||||||
|
$(document).ready(function () { |
||||||
|
// Обработчик отправки комментария. Нам не важно, комментарий к курсу или к уроку - URL берется из action формы
|
||||||
|
$('form.questions__form').on('submit', function (e) { |
||||||
|
e.preventDefault(); |
||||||
|
|
||||||
|
const submitButton = $(this).find('button.questions__action'); |
||||||
|
const replyToInput = $(this).find('input[name=reply_id]'); |
||||||
|
const replyToValue = replyToInput.val() ? parseInt(replyToInput.val()) : 0; |
||||||
|
const commentTextarea = $(this).find('textarea.questions__textarea'); |
||||||
|
commentTextarea.attr('disabled', 'disabled'); |
||||||
|
submitButton.attr('disabled', 'disabled'); |
||||||
|
|
||||||
|
$.ajax($(this).attr('action'), { |
||||||
|
method: 'post', |
||||||
|
data: { |
||||||
|
reply_id: replyToValue, |
||||||
|
comment: commentTextarea.val(), |
||||||
|
} |
||||||
|
}) |
||||||
|
.done(function (data) { |
||||||
|
console.log(data); |
||||||
|
if (data.success === true) { |
||||||
|
if (replyToValue > 0) { |
||||||
|
$(`#question__${replyToValue}`).after(data.comment); |
||||||
|
} else { |
||||||
|
$('.questions__list').append(data.comment); |
||||||
|
} |
||||||
|
|
||||||
|
commentTextarea.val(''); |
||||||
|
} |
||||||
|
}) |
||||||
|
.fail(function (xhr) { |
||||||
|
|
||||||
|
}) |
||||||
|
.always(function () { |
||||||
|
commentTextarea.removeAttr('disabled'); |
||||||
|
submitButton.removeAttr('disabled'); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
// Обработчик кнопки "Ответить"
|
||||||
|
$('.questions__list').on('click', 'button.question__reply-button', function () { |
||||||
|
const replyId = $(this).attr('data-reply-id'); |
||||||
|
const form = $('form.questions__form'); |
||||||
|
form.find('input[name=reply_id]').val(replyId); |
||||||
|
form.find('.questions__reply-anchor').attr('href', `#question__${replyId}`); |
||||||
|
form.find('.questions__reply-info').show(); |
||||||
|
}); |
||||||
|
|
||||||
|
// Обработчик отмены комментирования в ответ на комментарий
|
||||||
|
$('.questions__reply-cancel').on('click', function (e) { |
||||||
|
e.preventDefault(); |
||||||
|
|
||||||
|
const form = $('form.questions__form'); |
||||||
|
form.find('input[name=reply_id]').val(0); |
||||||
|
form.find('.questions__reply-info').hide(); |
||||||
|
}); |
||||||
|
}); |
||||||
Loading…
Reference in new issue