Make a previsualization button in page edit

This commit is contained in:
Skia 2016-01-11 09:56:42 +01:00
parent 771056d6e4
commit 1f4c49ac49
3 changed files with 18 additions and 3 deletions

View File

@ -6,6 +6,7 @@
<title>{% block title %}Bienvenue sur le Sith de l'AE!{% endblock %}</title> <title>{% block title %}Bienvenue sur le Sith de l'AE!{% endblock %}</title>
<link rel="stylesheet" href="{% static 'core/style.css' %}"> <link rel="stylesheet" href="{% static 'core/style.css' %}">
<script src="{% static 'core/script.js' %}"></script> <script src="{% static 'core/script.js' %}"></script>
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
{% endblock %} {% endblock %}
</head> </head>

View File

@ -2,6 +2,17 @@
{% block head %} {% block head %}
{{ block.super }} {{ block.super }}
<script>
function make_preview() {
$.ajax({
url: "{% url 'core:api_markdown' %}",
method: "GET",
data: { text: $("#id_content").val() }
}).done(function (msg) {
$("#preview").html(msg);
});
}
</script>
{% endblock %} {% endblock %}
{% block page %} {% block page %}
@ -9,9 +20,11 @@
<form action="{% url 'core:page_edit' page_name=page.get_full_name %}" method="post"> <form action="{% url 'core:page_edit' page_name=page.get_full_name %}" method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
{# TODO: NOW THAT WE HAVE JAVASCRIPT, MAKE A PREVISUALISATION BUTTON USING api/markdown?text=guyguyguy #} <p><input type="button" value="Preview" onclick="javascript:make_preview();" /></p>
<p><input type="submit" value="Save!" /></p> <p><input type="submit" value="Save!" /></p>
</form> </form>
<div id="preview">
</div>
{% endblock %} {% endblock %}

View File

@ -1,4 +1,5 @@
from django.shortcuts import render from core.templatetags.renderer import markdown
from django.http import HttpResponse
def render_markdown(request): def render_markdown(request):
return render(request, 'core/api/markdown.html', context={'text': request.GET['text']}) return HttpResponse(markdown(request.GET['text']))