{% import 'allura:templates/jinja_master/lib.html' as lib with context %}
<form method="{{method}}" action="{{action}}" enctype="multipart/form-data">
  <input type="hidden" name="add_forum.app_id" value="{{app and app.config._id}}">
  <div id="add_forum_form" style="display:none">
    <label class="grid-5">Name:</label>
    <div class="grid-14"><input type="text" name="add_forum.name" value="{{value and value['name']}}"></div>
    <label class="grid-5">Short Name:</label>
    <div class="grid-14"><input type="text" name="add_forum.shortname" value="{{value and value['shortname']}}"></div>
    <label class="grid-5">Parent Forum:</label>
    <div class="grid-14"><select name="add_forum.parent">
    <option value="">None</option>
    {% for f in app.forums %}<option value="{{f._id}}">{{h.really_unicode(f.name)}}</option>{% endfor %}
    </select></div>
    <label class="grid-5">Description:</label>
    <div class="grid-14"><textarea name="add_forum.description" style="height:50px;">{{value and value['description']}}</textarea></div>
    <label class="grid-5">Monitoring Email:</label>
    <div class="grid-14"><input type="text" name="add_forum.monitoring_email" value="{{value and value['monitoring_email']}}"></div>
    <label class="grid-5">Icon:</label>
    <div class="grid-14">{{lib.file_field('add_forum.icon', '')}}</div>
    <label class="grid-5">Developer Only:</label>
    <div class="grid-14"><input name="add_forum.members_only" type="checkbox"{% if value and value['members_only'] %} checked{% endif %}></div>
    <label class="grid-5">Allow anonymous posts:</label>
    <div class="grid-14"><input name="add_forum.anon_posts" type="checkbox"{% if value and value['anon_posts'] %} checked{% endif %}></div>
    <label class="grid-5">&nbsp;</label>
    <div class="grid-14">
      <input type="submit" name="create" value="Create Forum">
      <input type="button" id="add_forum_cancel" value="Cancel">
    </div>
  </div>
</form>
<script type="text/javascript">
    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload !== 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            };
        }
    }
  var has_form_errors = false;
  {% for field in widget.fields %}
    {% set ctx=widget.context_for(field) %}
    {% if ctx.errors and field.show_errors -%}
        has_form_errors = true;
        addLoadEvent(function() {
            $('#messages').notify("{{ctx.errors}}", {
                title: 'Error',
                status: 'error'
            });
        });
    {%- endif %}
  {% endfor %}
  if (has_form_errors) {
    addLoadEvent(function() {
      $("#add_forum_form").show();
    });
  }
</script>
