{% extends 'base.html' %}

{% block main %}
{% from "_formhelpers.html" import render_field %}

<head>
<script>
function outputUpdate(sameness) {
    document.querySelector('#selected-sameness').value = sameness;
}
function outputUpdate2(diversity) {
    document.querySelector('#selected-diversity').value = diversity;
}
function outputUpdate3(gender) {
    document.querySelector('#selected-gender').value = gender;
}
</script>
</head>
<div class="container">

  <a href="{{ url_for('show_book_by_id', id=book.id )}}">back</a>

  <form method="POST" action="{{ url_for('edit_book_by_id', id=book.id )}}" enctype=multipart/form-data>
    {{ form.csrf_token }}

    <div class="form-group"><h1 class="header">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</h1></div>

<div style="float:right; padding-right: 300px;">
 <img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="280px" onerror="if (this.src != '/uploads/cover/{{ book.cover }}') this.src = '/static/img/default_cover.gif';"></div>

        <br>
    <div data-toggle="fieldset" id="phone-fieldset">
         {{ form.author.label }}*:  <button type="button" data-toggle="fieldset-add-row"
                                          data-target="#phone-fieldset">+</button>
        <table>
            <tr>
                <th></th>
                <th></th>
            </tr>
            {% for author in form.author %}
                <tr data-toggle="fieldset-entry">
                    <td>{{ author.author_name (size=50, class="form-control") }}</td>
                    <td><button type="button" data-toggle="fieldset-remove-row" id="phone-{{loop.index0}}-remove">-</button></td>
                </tr>
            {% endfor %}
        </table><br>
<br>
  Category:* <br> {{ form.category(size=50, class="form-control") }} <br><br>
  Year published: <br> {{ form.year_published(size=8, class="form-control") }} <br><br>

How different is this item to the rest of the collection?
Or is it more of the same? <br>
{{ form.sameness(min=0, max=100, oninput="outputUpdate(value)") }} &nbsp;
<span style="color: #d3d3d3;"><output for="sameness" id="selected-sameness">{{ form.sameness.data }} </output> % different</span>

<br><hr align="left" style="width:40%;"><br>

Check the bibliography. How diverse are the references in this book? <br>
{{ form.diversity(min=0, max=100, oninput="outputUpdate2(value)") }} &nbsp;
<span style="color: #d3d3d3;"><output for="diversity" id="selected-diversity">{{ form.diversity.data }} </output> % diverse</span>

<br><hr align="left" style="width:40%;"><br>

Check the writing. Who is speaking? Is the voice more often male or female? <br>
{{ form.gender(min=1, max=100, oninput="outputUpdate3(value)") }} &nbsp;
<span style="color: #d3d3d3;"><output for="diversity" id="selected-gender">{{ form.gender.data }} </output> % female</span>

<br><hr align="left" style="width:40%;"><br>
Who are you? {{ render_field(form.who)}}
<br><hr align="left" style="width:40%;"><br>

<div class="form-group" style="padding-bottom: 10px;">
  Current file: {{ book.file }} &nbsp;&nbsp;&nbsp;&nbsp; Upload new file: {{form.file}}
</div>
<div class="form-group" style="padding-bottom: 10px;">
   
</div>
<div class="form-group" style="padding-bottom: 10px;">

  If uploading, write a new message: <br>{{form.message(size=135, class="form-control") }} 

</div>
    <br>
    <button type="submit" class="btn btn-primary">Update</button>
</form>

</div>
{% endblock %}
