Push partial templates to the editor
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 11 Dec 2013 12:29:06 +0000 (13:29 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 23:14:16 +0000 (00:14 +0100)
apps/wiki/templates/wiki/bootstrap.html
apps/wiki/views.py

index 5d59d78..159a4f4 100644 (file)
                 );
             {% endif %}
 
-            var data = {% autoescape off%}{{serialized_document_data}}{%endautoescape%};
+            {% autoescape off%}
+            var data = {{serialized_document_data}},
+                templates = {{serialized_templates}}
+            {%endautoescape%}
 
             var editor_init = function(Editor) {            
                 Editor.setBootstrappedData('data', data);
+                Editor.setBootstrappedData('documentToolbar', templates);
                 Editor.start(config);
             };
         </script>
index 2bb168f..b88d2df 100644 (file)
@@ -16,7 +16,7 @@ from django.views.decorators.http import require_POST, require_GET
 from django.shortcuts import get_object_or_404, render
 from django.utils import simplejson
 
-from catalogue.models import Book, Chunk
+from catalogue.models import Book, Chunk, Template
 import nice_diff
 from wiki import forms
 from wiki.helpers import (JSONResponse, JSONFormInvalid, JSONServerError,
@@ -89,6 +89,9 @@ def editor(request, slug, chunk=None, template_name='wiki/bootstrap.html'):
             'history': get_history(chunk),
             'version': chunk.revision()
         }),
+        'serialized_templates': simplejson.dumps([
+            {'id': t.id, 'name': t.name, 'content': t.content} for t in Template.objects.filter(is_partial=True)
+        ]),
         'forms': {
             "text_save": save_form,
             "text_revert": forms.DocumentTextRevertForm(prefix="textrevert")