Skip to content
Browse files

Bug Fix 755019 . Updated JS for preview fiew, allowing for previews t…

…o be posted to a new window. Also includes a feeble first attempt at modifying the python required to accomplish this task. Python currently providing a 'Permission Denied' error

Adding CSRF token to the post to new window.  Formatting preview page to look as normal pages do.

Moving kumascript error block, adding additional content filters for teh TOC

Removing non-functioning TOC from the preview page

Adding ability to preview templates with ace editor

Making solution more jQuery-ish
  • Loading branch information...
1 parent f25894d commit 140592529bd4e849ade9c3bb24874d67b0573c2c @darkwing darkwing committed May 18, 2012
Showing with 76 additions and 32 deletions.
  1. +41 −6 apps/wiki/templates/wiki/preview.html
  2. +2 −1 apps/wiki/views.py
  3. +33 −25 media/js/wiki.js
View
47 apps/wiki/templates/wiki/preview.html
@@ -1,7 +1,42 @@
+
{# vim: set ts=2 et sts=2 sw=2: #}
-{% if kumascript_errors %}
- {% include 'wiki/includes/kumascript_errors.html' %}
-{% endif %}
-<div id="doc-content">
- {{ content|safe }}
-</div>
+
+{% extends "wiki/base.html" %}
+{% from "wiki/includes/sidebar_modules.html" import document_tabs, document_notifications %}
+{% block title %}{{ title|safe }}{% endblock %}
+{% set classes = 'document' %}
+{% block bodyclass %}document{% endblock %}
+
+{% block content %}
+<section id="content">
+ <div class="wrap">
+
+ <div id="content-main" class="full">
+
+ {% if kumascript_errors %}
+ {% include 'wiki/includes/kumascript_errors.html' %}
+ {% endif %}
+
+ <div class="warning review-technical">
+ <p>{{ _('This is a preview of an unsaved document.') }}</p>
+ </div>
+
+ <article class="article" role="main">
+ <header id="article-head">
+ <div class="title">
+ <h1 class="page-title">{{ title|safe }}</h1>
+ </div>
+ </header>
+
+ <div id="wikiArticle" class="page-content boxed">
+ {{ content|safe }}
+ </div>
+
+ </article>
+ </div>
+ </div>
+</section>
+{% endblock %}
+
+{% block breadcrumbs %}
+{% endblock %}
View
3 apps/wiki/views.py
@@ -915,7 +915,8 @@ def preview_revision(request):
wiki_content, kumascript_errors = _perform_kumascript_post(
wiki_content)
# TODO: Get doc ID from JSON.
- data = {'content': wiki_content, 'kumascript_errors': kumascript_errors}
+ data = {'content': wiki_content, 'title': request.POST.get('title', ''),
+ 'kumascript_errors': kumascript_errors}
#data.update(SHOWFOR_DATA)
return jingo.render(request, 'wiki/preview.html', data)
View
58 media/js/wiki.js
@@ -705,34 +705,42 @@
* Initialize the article preview functionality.
*/
function initArticlePreview() {
- $('#btn-preview').click(function(e) {
- var $btn = $(this),
- data = $.trim(CKEDITOR.instances['id_content'].getData());
+ $("#btn-preview").click(function(e) {
+ e.preventDefault();
+
+ // Ensure that content is available and exists
+ var title = " ",
+ $titleNode = $("#id_title"),
+ data;
- // Only submit if the form has data....
+ if(CKEDITOR.instances['id_content']) {
+ data = $.trim(CKEDITOR.instances['id_content'].getData());
+ }
+ else if(ace_editor && ace_editor) {
+ data = $.trim(ace_editor.getSession().getValue());
+ }
+ else {
+ return;
+ }
+ if($titleNode.length) {
+ title = $titleNode.val();
+ }
+
+ // Since we have content, we can launch!
if(data) {
- $btn.attr('disabled', 'disabled');
- $.ajax({
- url: $(this).attr('data-preview-url'),
- type: 'POST',
- data: $('#id_content').val(data).serialize(),
- dataType: 'html',
- success: function(html) {
- var $preview = $('#preview');
- $preview.html(html)
- .find('select.enable-if-js').removeAttr('disabled');
- document.location.hash = 'preview';
- $btn.removeAttr('disabled');
- },
- error: function() {
- var msg = gettext('There was an error generating the preview.');
- $('#preview').html(msg);
- $btn.removeAttr('disabled');
- }
- });
+ // Create and inject form for preview submission
+ var $form = $("<form action='" + $(this).attr("data-preview-url") + "' target='_blank' method='POST' />").appendTo(document.body);
+ $("<input type='hidden' name='content' />").val(data).appendTo($form);
+ $("<input type='hidden' name='title' />").val(title).appendTo($form);
+
+ // Add the CSRF ?
+ $("#csrfmiddlewaretoken").clone().appendTo($form);
+
+ // Submit the form, and then get rid of it
+ $form.get(0).submit();
+ $form.remove();
}
-
- e.preventDefault();
+
return false;
});
}

0 comments on commit 1405925

Please sign in to comment.
Something went wrong with that request. Please try again.