SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit ba94d1fe authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Move comments to automarkup; ajax process call now reusable js fn

parent 0ea9ca7c
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,8 @@
{% load staticfiles %}
{% block footer_script %}
<script type="text/javascript" src="{% static 'scipost/comment-preview.js' %}"></script>
<script src="{% static 'scipost/fetch-markup-preview.js' %}"></script>
<script src="{% static 'scipost/comment-preview.js' %}"></script>
{% endblock %}
<form enctype="multipart/form-data" {% if url %}action="{{ url }}" {% endif %}method="post">
......@@ -12,10 +13,11 @@
<div class="col-md-9">
{{ form.comment_text|bootstrap:'12,12' }}
<p>
In your comment, you can use $\LaTeX$ \$...\$ for in-text equations or \ [ ... \ ] for on-line equations.
</p>
<p class="good_commenter">Be professional. Only serious and meaningful comments will be vetted through.</p>
<p class="good_commenter">
You can use plain text, Markdown or reStructuredText; see our
<a href="{% url 'markup:help' %}" target="_blank">markup help</a> pages.
<br>
Be professional. Only serious and meaningful comments will be vetted through.</p>
</div>
<div class="col-md-3 radio-list">
<label>Specify categorization(s):</label>
......@@ -49,19 +51,25 @@
<h3 class="anonymous-no"><span class="text-danger">Your Comment will be <span class="text-underline">signed</span>.</span> Thank you very much!</h3>
</div>
{% endif %}
<input type="submit" name="submit" value="Submit your Comment for vetting" class="btn btn-primary" id="submit-id-submit">
{% if form.anonymous %}
<p class="mt-2" id="goodCommenter"><i>By clicking on Submit, you agree with the <a target="_blank" href="{% url 'scipost:terms_and_conditions' %}">Terms and Conditions</a>.</i></p>
{% else %}
<p class="mt-2" id="goodCommenter"><i>By clicking on Submit, you agree with the <a target="_blank" href="{% url 'scipost:terms_and_conditions' %}">Terms and Conditions</a>, in particular that <span class="text-danger">your identity will be attached to the Comment</span>.</i></p>
{% endif %}
<div id="submitButton">
<input type="submit" value="Submit your Comment for vetting" class="btn btn-primary">
{% if form.anonymous %}
<p class="mt-2" id="goodCommenter"><i>By clicking on Submit, you agree with the <a target="_blank" href="{% url 'scipost:terms_and_conditions' %}">Terms and Conditions</a>.</i></p>
{% else %}
<p class="mt-2" id="goodCommenter"><i>By clicking on Submit, you agree with the <a target="_blank" href="{% url 'scipost:terms_and_conditions' %}">Terms and Conditions</a>, in particular that <span class="text-danger">your identity will be attached to the Comment</span>.</i></p>
{% endif %}
</div>
</div>
</div>
</form>
<div class="row">
<div class="col-md-9">
<h3>Preview of your comment:</h3>
<p id="preview-comment_text"></p>
<button class="btn btn-warning" id="runPreviewButton">Run/refresh preview and check your Comment before submitting it:</button>
<div class="card m-2">
<div class="card-header">
Preview of your comment
</div>
<div class="card-content">
<div id="preview-comment_text"></div>
</div>
</div>
<br>
......@@ -2,6 +2,7 @@
{% load filename %}
{% load file_extentions %}
{% load user_groups %}
{% load automarkup %}
{% is_edcol_admin request.user as is_edcol_admin %}
{% is_editorial_college request.user as is_editorial_college %}
......@@ -16,8 +17,9 @@
{% endif %}
<p class="my-3 pb-2">
{{ comment.comment_text|linebreaksbr }}
{{ comment.comment_text|automarkup:'plain' }}
</p>
{% if comment.file_attachment %}
<h3>Attachment:</h3>
<p>
......
......@@ -50,7 +50,7 @@
<h2 class="highlight">
Preview of your ticket
</h2>
<p><em id="languageElement" class="text-muted mb-2"></em></p>
<p><em id="language-description" class="text-muted mb-2"></em></p>
<div class="card">
<div class="card-header" id="preview-title"></div>
<div class="card-content">
......@@ -58,11 +58,12 @@
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block footer_script %}
<script src="{% static 'scipost/fetch-markup-preview.js' %}"></script>
<script src="{% static 'scipost/ticket-preview.js' %}"></script>
{% endblock footer_script %}
$(function(){
var comment_text_input = $("#id_comment_text");
$(document).ready(function() {
comment_text_input.on('keyup', function(){
var new_text = $(this).val()
$("#preview-comment_text").text(new_text)
if( typeof MathJax.Hub !== 'undefined' ) {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
}).trigger('keyup');
$('#submitButton').hide();
$("#id_comment_text").on('keyup', function(){
$('#runPreviewButton').show();
$('#preview-comment_text').css('background', '#feebce');
$('#submitButton').hide();
});
$('#runPreviewButton').on('click', function(){
fetchMarkupPreview('comment_text');
$('#runPreviewButton').hide();
$('#preview-comment_text').css('background', '#ffffff');
$('#submitButton').show();
}).trigger('change');
$('input[name$="anonymous"]').on('change', function() {
$('.anonymous-alert').show()
$('.anonymous-alert').show()
.children('h3').hide()
if ($(this).prop('checked')) {
if ($(this).prop('checked')) {
$('.anonymous-yes').show();
} else {
} else {
$('.anonymous-no').show();
}
}
}).trigger('change');
});
function fetchMarkupPreview(label) {
$.ajax({
type: "POST",
url: "/markup/process/",
data: {
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(),
markup_text: $('#id_' + label).val(),
},
dataType: 'json',
success: function(data) {
$('#language-' + label).text("Language (auto-detected): " + data.language);
if (data.errors) {
$('#preview-' + label).css('background', '#feebce');
$('#submitButton').hide();
$('#runPreviewButton').show();
alert("An error has occurred while processing the text:\n\n" + data.errors);
}
$('#preview-' + label).html(data.processed);
let preview = document.getElementById('preview-' + label);
MathJax.Hub.Queue(["Typeset",MathJax.Hub, preview]);
},
error: function(data) {
alert("An error has occurred while processing the text:\n\n." + data);
}
});
}
......@@ -16,31 +16,7 @@ $('#id_description').on('keyup', function(){
$('#runPreviewButton').on('click', function(){
$('#preview-title').text($('#id_title').val());
$.ajax({
type: "POST",
url: "/markup/process/",
data: {
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(),
markup_text: $('#id_description').val(),
},
dataType: 'json',
success: function(data) {
$('#languageElement').text("Language (auto-detected): " + data.language);
if (data.errors) {
$('#preview-title').css('background', '#eedbbe');
$('#preview-description').css('background', '#feebce');
$('#submitButton').hide();
$('#runPreviewButton').show();
alert("An error has occurred while processing the text:\n\n" + data.errors);
}
$('#preview-description').html(data.processed);
let preview = document.getElementById('preview-description');
MathJax.Hub.Queue(["Typeset",MathJax.Hub, preview]);
},
error: function(data) {
alert("An error has occurred while processing the text:\n\n." + data);
}
});
fetchMarkupPreview('description');
$('#runPreviewButton').hide();
$('#preview-title').css('background', '#f1f1f1');
$('#preview-description').css('background', '#ffffff');
......
......@@ -100,7 +100,7 @@
{% if submission.author_comments %}
<h3>Author comments upon resubmission</h3>
<div class="blockquote">
{{ submission.author_comments|linebreaks }}
{{ submission.author_comments|linebreaksbr }}
</div>
{% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment