{% extends "wiki/article.html" %}
{% load wiki_tags i18n sekizai_tags %}
{% load url from future %}

{% block pagetitle %}{% trans "Edit" %}: {{ article.current_revision.title }}{% endblock %}

{% block wiki_contents_tab %}

{% addtoblock "js" %}
<script type="text/javascript">
  $(document).ready(
    function ($) {
      accessible_modal("#cheatsheetLink", "#cheatsheetModal .close-modal", "#cheatsheetModal", ".content-wrapper");
      accessible_modal("#previewButton", "#previewModal .close-modal", "#previewModal", ".content-wrapper");
      $("#previewModalBackToEditor").click(function (e) {
        $("#previewModal .close-modal").click();
        e.preventDefault();
      });
    }
  );
</script>
{% endaddtoblock %}

<form method="POST" class="form-horizontal" id="article_edit_form" name="article_edit_form" enctype="multipart/form-data">
  {% include "wiki/includes/editor.html" %}
  <div class="form-actions">
      <button type="submit" name="save" value="1" class="btn btn-large btn-primary" onclick="this.form.target=''; this.form.action='{% url 'wiki:edit' path=urlpath.path article_id=article.id %}'">
        <i class="icon-ok"></i>
        {% trans "Save changes" %}
      </button>
      <a class="btn btn-large" id="previewButton" href="#previewModal" rel="leanModal"
        onclick="
          document.article_edit_form.target='previewWindow';
          document.article_edit_form.action='{% url 'wiki:preview' path=urlpath.path article_id=article.id %}';
          document.article_edit_form.submit();">
        <i class="icon-eye-open"></i>
        {% trans "Preview" %}
      </a>

      <a href="{% url 'wiki:delete' path=urlpath.path article_id=article.id %}" class="pull-right btn btn-danger">
        <i class="icon-remove"></i>
        {% trans "Delete article" %}
      </a>

  </div>
  <section id="previewModal" class="modal" aria-hidden="true">
    <div class="inner-wrapper" role="dialog" aria-labelledby="preview-title">
      <button class="close-modal"><i class="icon-remove"></i> <span class="sr">{% trans 'Close' %}</span></button>

      <header>
        <h2 id="preview-title">{% trans "Wiki Preview" %}<span class="sr">, {% trans "window open" %}</span></h2>
        <hr/>
      </header>

    <div class="modal-body">
      <iframe name="previewWindow" frameborder="0"></iframe>
    </div>
    <div class="modal-footer">
      <button type="submit" name="save" value="1" class="btn btn-large btn-primary" onclick="this.form.target=''; this.form.action='{% url 'wiki:edit' path=urlpath.path article_id=article.id %}'">
        <i class="icon-ok"></i>
        {% trans "Save changes" %}
      </button>

      <a id="previewModalBackToEditor" href="#" class="btn btn-large">
        <i class="icon-circle-arrow-left"></i>
        {% trans "Back to editor" %}
      </a>
    </div>
  </section>
  {% include "wiki/includes/cheatsheet.html" %}
</form>

{% endblock %}
