{% extends "submit/draft_status.html" %}
{% load submit_tags %}
{% block title %}Adjust Meta-Data{% endblock %}

{% block morecss %}
{{ block.super }}
table.metadata-table #id_title, table.metadata-table #id_abstract, table.metadata-table #id_comments { width: 500px; }
table.metadata-table tr.warning th, table.metadata-table tr.warning td { background-color: #ffeebb; }
table.ietf-table tr { vertical-align: top; }
table.ietf-table tr.error { background-color: #ffeebb; border-top: 1px dashed red; border-bottom: 1px dashed red;}
table.ietf-table span.field-error { display: block; color: red; }
{% endblock %}

{% block pagehead %}
{{ block.super }}

<script type="text/javascript" src="/js/draft-submit.js"></script>
<script type="text/javascript">
(function ($) {

    $.fn.AuthorList = function() {
        return this.each(function () {
            var table = $(this);
            var makeEditable = function() {
                table.find('tbody tr').each(function(index, value) {
                    var tr = $(this);
                    tr.find('td').each(function() {
                        var td = $(this);
                        var text = td.find('.fieldValue');
                        var name = td.attr('name');
                        if (tr.hasClass('non_editable')) {
                            td.prepend('<input style="display: none;" type="text" name="' + name + '_' + index + '" value="' + text.text() + '" />');
                        } else {
                            td.prepend('<input type="text" name="' + name + '_' + index + '" value="' + text.text() + '" />');
                            text.html('');
                        }
                    });
                });
            };

            var addNewEntry = function() {
                table.append(table.find('tbody tr').last().clone());
                var new_tr = table.find('tbody tr').last();
                new_tr.toggleClass('evenrow').toggleClass('oddrow');
                new_tr.removeClass('error').find('.field-error').remove();
                new_tr.find('input').each(function() {
                    var name = $(this).attr('name');
                    var splitted = name.split('_');
                    splitted.reverse();
                    name = name.replace(splitted[0], (parseInt(splitted[0]) + 1).toString(10));
                    $(this).attr('name', name);
                    $(this).val('');
                });
            };

            var bindTriggers = function() {
                $('.new_author').click(addNewEntry);
            };

            var initialize = function() {
                makeEditable();
                bindTriggers();
            };

            initialize();
        });
    };

    $(document).ready(function () {
        $('table.author_list').AuthorList();
    });

})(jQuery);
</script>
{% endblock %}

{% block submit_content %}
<h2>Adjust External Meta-Data</h2>

<div id="idnits_results" style="visibility:hidden;">
  <div class="hd">
    <span style="display: none;" id="twopages_title">First two pages</span>
  </div>
  <div class="bd">
    <div id="stream_dialog_body" style="padding: 0em 5em; height: 400px; overflow: auto;">
      <pre class="twopages" style="display: none;">{{ detail.first_two_pages }}</pre>
    </div>
  </div>
</div>

<table class="metadata-table">
<tr><th>Document</th><td>{{ detail.filename }} <a class="twopages_trigger" href="#">[View first two pages]</a>
{% show_submission_files detail %}
</td></tr>
<tr><th>Submission date</th><td>{{ detail.submission_date }}</td></tr>
<tr{% if validation.warnings.group %} class="warning"{% endif %}><th>WG</th><td>{{ validation.wg|default:"Individual Submission" }}
{% if validation.warnings.group %}
<div class="warn_message">The secretariat will be notified that the working group is not active</div>
{% endif %}
</td></tr>
<tr><th>File size</th><td>{{ detail.filesize|filesizeformat }}</td></tr>
</table>

<h3>Adjust data</h3>
{% if form.errors %}
<div class="metadata-errors">
Please fix the following errors.
</div>
{% endif %}
<form method="post" action="">
<table class="metadata-table">
<tr{% if form.errors.title %} class="warning"{% endif %}><th>Title</th><td>{{ form.title }}{{ form.errors.title }}</td></tr>
<tr{% if form.errors.version %} class="warning"{% endif %}><th>Version</th><td>{{ form.version }}{{ form.errors.version }}</td></tr>
<tr{% if form.errors.creation_date %} class="warning"{% endif %}><th>Creation date</th><td>{{ form.creation_date }}{{ form.errors.creation_date }}</td></tr>
<tr{% if form.errors.abstract %} class="warning"{% endif %}><th>Abstract</th><td>{{ form.abstract }}{{ form.errors.abstract }}</td></tr>
<tr{% if form.errors.pages %} class="warning"{% endif %}><th>Pages</th><td>{{ form.pages }}{{ form.errors.pages }}</td></tr>
<tr><th>Submitter</th>
<td>
If you are one of the authors, then please click a button by your name to automatically fill in the submitter's information as requested below. Otherwise, Please manually enter your information.<br />
{{ form.get_author_buttons|safe }}
</td></tr>
{% if settings.USE_DB_REDESIGN_PROXY_CLASSES %}
<tr{% if form.errors.name %} class="warning"{% endif %}><th class="author">Name</th><td>{{ form.name }}{{ form.errors.name }}</td></tr>
{% else %}
<tr{% if form.errors.first_name %} class="warning"{% endif %}><th class="author">First name</th><td>{{ form.first_name }}{{ form.errors.first_name }}</td></tr>
<tr{% if form.errors.last_name %} class="warning"{% endif %}><th class="author">Last name</th><td>{{ form.last_name }}{{ form.errors.last_name }}</td></tr>
{% endif %}
<tr{% if form.errors.email %} class="warning"{% endif %}><th class="author">Email address</th><td>{{ form.email }}{{ form.errors.email }}</td></tr>
<tr{% if form.errors.comments %} class="warning"{% endif %}><th>Comments to the secretariat</th><td>{{ form.comments }}{{ form.errors.comments }}</td></tr>
</table>

<h3>Authors</h3>
<table class="author_list ietf-table" style="width: 100%;">
  <thead>
    <tr>
      {% if settings.USE_DB_REDESIGN_PROXY_CLASSES %}
      <th>Name</th>
      {% else %}
      <th>First name</th>
      <th>Last name</th>
      {% endif %}
      <th>Email address</th>
    </tr>
  </thead>
  <tbody>
{% for author in form.get_authors %}
  <tr class="editable {% cycle oddrow,evenrow %}{% if author.errors %} error{% endif %}">
    {% if settings.USE_DB_REDESIGN_PROXY_CLASSES %}
    <td name="name"><span class="fieldValue">{{ author.get_full_name|default:"" }}</span><span class="field-error">{{ author.errors.name }}</span></td>
    {% else %}
    <td name="first_name"><span class="fieldValue">{{ author.first_name|default:"" }}</span><span class="field-error">{{ author.errors.first_name }}</span></td>
    <td name="last_name"><span class="fieldValue">{{ author.last_name|default:"" }}</span><span class="field-error">{{ author.errors.last_name }}</span></td>
    {% endif %}
    <td name="email"><span class="fieldValue">{{ author.email.1|default:"" }}</span><span class="field-error">{{ author.errors.email }}</span></td>
  </tr>
{% endfor %}
  </tbody>
</table>
<div style="text-align: right; margin-bottom: 1em;">
<input type="button" value="Add another author" class="new_author" />
</div>
<input type="submit" value="Submit for manual posting" />
</form>

<p>
The IETF is an organized activity of the <a href="http://www.isoc.org">Internet Society</a>
<br>Please send problem reports to <a href="mailto:ietf-action@ietf.org">ietf-action@ietf.org</a>.
</p>
{% endblock %}
