{% extends "base.html" %}

{% block title %}{% if post %}Edit{% else %}Add{% endif %} Post - {% firstof post.title "Untitled" %}{% endblock %}

{% block header_content %}{% if post %}Edit{% else %}Add{% endif %} Post - {% firstof post.title "Untitled" %}{% endblock %}

{% block main %}
<form action="" method="POST" enctype="multipart/form-data" role="form" id="blogForm" class="col-sm-12">
  {% include "_form_messages.html" with form=form %}
  {% csrf_token %}
  <div class="form-vertical">
    {% if post %}
    <p><a href="{{ post.get_absolute_url }}" target="_new">
        View this post <span class="glyphicon glyphicon-chevron-right"></span></a></p>
    {% endif %}
    {% for field in form %}
    <div id="{{ field.name }}" class="form-group">
      <label for="id_{{ field.name }}">{{ field.label }}</label>
      {{ field }}
      {% if field.help_text %}<div class="muted help-text">{{ field.help_text|safe }}</div>{% endif %}
    </div>
    {% endfor %}
  </div>
  <input class="btn btn-success btn-large" type="submit" name="submit_post" value="Save changes" />
  {% if posts %}
  <div class="page-header">
    <h2>Other posts</h2>
  </div>
  {% include "blog/_partial-list.html" with current_post=post %}
  {% endif %}
  <div class="modal fade" id="image-modal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <a class="close" data-dismiss="modal">×</a>
          <h3>Select an Image to Insert</h3>
        </div>
        <div class="modal-body">
          <iframe style="height: 415px;width: 100%; border: none; margin: 0; padding: 0;"></iframe>
        </div>
        <div class="modal-footer">
          <a href="javascript:;" onclick="addImage();$(this).hide();return false;" class="btn">Add New Image</a>
          <a href="#" data-dismiss="modal" class="btn">Close</a>
        </div>
      </div>
      <div class="modal" id="preview-modal">
        <div class="modal-header">
          <a class="close" data-dismiss="modal">×</a>
          <h3>Preview</h3>
        </div>
        <div class="modal-body"></div>
        <div class="modal-footer">
          <a href="#" data-dismiss="modal" class="btn">Close</a>
        </div>
      </div>
    </div>
  </div>
</form>
<script type="text/javascript" src="{{ STATIC_URL }}blog_admin.js"></script>
<script type="text/javascript">
  var tagsAutocomplete = [{% for tag in tags %}"{{ tag }}"{% if not forloop.last %},{% endif %}{% endfor %}];
  uR.ready(initBlag);
</script>
{% endblock %}
