]> git.ipfire.org Git - people/shoehn/ipfire.org.git/commitdiff
Fix preview function in planet texts.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Aug 2012 09:19:15 +0000 (11:19 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Aug 2012 09:19:15 +0000 (11:19 +0200)
www/static/js/site.js
www/templates/admin-planet-compose.html
www/webapp/handlers_admin.py

index 79e77bf8bb39e71b5a73eeb1c8f8e5427bcf2f8c..6dc07c6f870e6c85d2e84f736f948ae611cc1538 100644 (file)
@@ -36,3 +36,17 @@ if (/.*download-splash.*/i.test(window.location.href)) {
                }
        });
 }
+
+function getCookie(name) {
+       var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
+       return r ? r[1] : undefined;
+}
+
+jQuery.postJSON = function(url, args, callback) {
+       args._xsrf = getCookie("_xsrf");
+       $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST",
+               success: function(response) {
+                       callback(eval("(" + response + ")"));
+               }
+       });
+};
index 0a8ef63f93126800ea6c803f2cb11916f6982ba4..54125041136477b967bfd49dcaa9c27980a3817d 100644 (file)
        </div>
 
        <div id="preview"></div>
-{% end block %}
 
-{% block javascript %}
        <script type="text/javascript">
                preview = function() {
-                       $.get("/api/planet/render", { text : $("#markdown").val() },
+                       $.postJSON("/api/planet/render", { text : $("#markdown").val() },
                                function(data) {
-                                       $("#preview").html(data);
+                                       $("#preview").html(data.html);
                                }
                        );
                }
index eeddffdddf36be68782fe81e7e1cd85cb0a358a2..dda7b9804f655de06ecf53decad623d172b80e03 100644 (file)
@@ -60,11 +60,14 @@ class AdminIndexHandler(AdminBaseHandler):
 
 class AdminApiPlanetRenderMarkupHandler(AdminBaseHandler):
        @tornado.web.authenticated
-       def get(self):
+       def post(self):
                text = self.get_argument("text", "")
 
                # Render markup
-               self.write(self.planet.render(text))
+               output = {
+                       "html" : self.planet.render(text),
+               }
+               self.write(output)
                self.finish()