Permalink
Browse files

added brick preview

  • Loading branch information...
inmarelibero committed Oct 28, 2012
1 parent e36885d commit 19770afc2af568ab9e23b0eae42735474b82b8ba
View
@@ -26,5 +26,6 @@ assetic:
- %kernel.root_dir%/Resources/js/jquery-1.8.2.js
- %kernel.root_dir%/Resources/bootstrap/js/bootstrap-transition.js
- %kernel.root_dir%/Resources/bootstrap/js/bootstrap-dropdown.js
+ - %kernel.root_dir%/Resources/bootstrap/js/bootstrap-tab.js
- @BricksSiteBundle/Resources/js/*/*.js
filters: ?yui_js
@@ -22,7 +22,17 @@ FORM: user creates/edits a brick
#bricks_userbundle_bricktype_description {
height: 100px;
}
+
+ #content-tab {
+ margin-bottom: 0px;
+ }
#bricks_userbundle_bricktype_content {
height: 600px;
+ border-top: 0px;
+ }
+ #content-preview {
+ padding: 4px 6px;
+ border: 1px solid #CCC;
+ border-top: 0px;
}
}
@@ -150,6 +150,24 @@ public function updateAction(Request $request, $id)
'form' => $editForm->createView(),
);
}
+
+ /**
+ * Return the markdown formattation of an input text
+ *
+ * \@TODO: refactor this function to some general utility class
+ *
+ * @Route("/_render-markdown", name="_user_brick_renderMarkdown")
+ * @Template()
+ * @method("POST")
+ *
+ * @param unknown_type $content
+ */
+ public function _renderMarkdownAction()
+ {
+ $content = $this->getRequest()->get('content');
+
+ return array('content' => $content);
+ }
/**
* Deletes a Brick entity.
@@ -0,0 +1 @@
+{{ content|markdown }}
@@ -31,7 +31,21 @@
<div class="control-group">
<label class="control-label" for="{{ form.content.vars.id }}">{{ form.content.vars.label }}</label>
<div class="controls">
- {{ form_widget(form.content) }}
+ <ul class="nav nav-tabs" id="content-tab">
+ <li class="active">
+ <a href="#content-code" data-toggle="tab">Code</a>
+ </li>
+ <li>
+ <a href="#content-preview" data-toggle="tab">Preview</a>
+ </li>
+ </ul>
+ <div class="tab-content">
+ <div class="tab-pane active" id="content-code">
+ {{ form_widget(form.content) }}
+ </div>
+ <div class="tab-pane" id="content-preview">
+ </div>
+ </div>
</div>
</div>
@@ -51,4 +65,40 @@
</div>
</div>
-{% endblock %}
+{% endblock %}
+
+{% block javascripts_footer %}
+ <script type="text/javascript">
+ jQuery(function($) {
+ $('a[data-toggle="tab"]').on('shown', function (e) {
+
+ // tab element pressed
+ var tabCaller = $(e.target);
+
+ // tab pane related
+ var paneTarget = $(tabCaller.attr('href'));
+
+ // if preview is requested
+ if (tabCaller.attr('href') == '#content-preview') {
+
+ /**
+ * perform ajax call to preview content
+ */
+ $.ajax({
+ url: "{{ path('_user_brick_renderMarkdown') }}",
+ data: {
+ 'content': $('#content-code textarea').val()
+ },
+ type: 'POST',
+ beforeSend: function(e) {
+ $('#content-preview').html('loading preview...');
+ },
+ complete: function(e) {
+ $('#content-preview').html(e.responseText);
+ }
+ })
+ }
+ })
+ });
+ </script>
+{% endblock %}

0 comments on commit 19770af

Please sign in to comment.