{% extends "base.html" %}

{% block body %}
  <form action="{{ request.path }}" method="post" class="compose">
    <div style="margin-bottom:5px"><input name="title" type="text" class="title" value="{{ entry.title if entry else "" }}"/></div>
    <div style="margin-bottom:5px"><textarea name="body_source" rows="30" cols="40" class="body_source">{{ entry.body_source if entry else "" }}</textarea></div>
    <div>
      <input type="submit" value="{{ _("Save changes") if entry else _("Publish post") }}" class="submit"/>
      &nbsp;<a href="{{ "/entry/" + entry.slug if entry else "/" }}">{{ _("Cancel") }}</a>
    </div>
    {% if entry %}
      <input type="hidden" name="key" value="{{ str(entry.key()) }}"/>
    {% end %}
    {% module xsrf_form_html() %}
  </form>
{% end %}

{% block bottom %}
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
  <script type="text/javascript">
  //<![CDATA[

    $(function() {
      $("input[name=title]").select();
      $("form.compose").submit(function() {
          var required = ["title", "body_source"];
          var form = $(this).get(0);
          for (var i = 0; i < required.length; i++) {
              if (!form[required[i]].value) {
                  $(form[required[i]]).select();
                  return false;
              }
          }
          return true;
      });
    });

  //]]>
  </script>
{% end %}
