Commit 1f4c49ac authored by Skia's avatar Skia

Make a previsualization button in page edit

parent 771056d6
...@@ -6,6 +6,7 @@ ...@@ -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>
......
...@@ -2,6 +2,17 @@ ...@@ -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 @@ ...@@ -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 %}
......
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']))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment