Files
books/templates/book.html

150 lines
5.4 KiB
HTML

{% extends "base.html" %}
{% block main_content %}
<h3><center>View/Edit Book</center></h1>
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
<div class="container-fluid"><div class="row"><form class="form col-lg-10">
{% for key in keys %}
<div class="form-row">
<label for="{{key}}" class="col-lg-2 col-form-label">{{key}}:</label>
{% if key == "genre" %}
<div class="form-row col-lg-10">
{% for genre in genre_list %}
{% set gname=genre.name %}
<div class="form-control col" style="margin-left:5px;margin-right:-5px;">
<input id="{{gname}}" name="{{gname}}" type="checkbox"
{% for book_g in books.genre %}
{% if book_g['name'] == gname %}
checked
{% endif %}
{% endfor %}
></input>
<label style="display:inline" for="{{gname}}" class="col-form-label">{{gname}}</label>
</div>
{% endfor %}
</div>
{% elif key == "publisher" %}
<div class="form-row col input-group" style="margin-left:0px; margin-right:0px;">
<div class="input-group-prepend">
<button class="btn btn-outline-primary" type="button">
<a style="color:inherit" href="{{url_for(key, id=books[key][0].id)}}"><i class="far fa-edit"></i></a>
</button>
</div>
<select class="form-control" id="publisher">
{% for pub in publisher_list %}
{% set pname=pub.name %}
<option id="{{pub.id}}" value="{{pub.id}}"
{% if books.publisher[0].name == pname %}
selected
{% endif %}
>{{pname}}</option>
{% endfor %}
</select>
</div class="row">
{% elif key == "author" %}
<div class="form-row col" style="margin-left:0px;margin-right:0px">
{% set cnt = namespace(idx=0) %}
{% for objects in books[key] %}
<div class="col input-group" style="padding-left:0px;padding-right:0px">
{% if cnt.idx > 0 %}
<div class="input-group-prepend">
<button class="btn btn-outline-danger" type="button">
<a style="color:inherit" href="{{url_for(key, id=-1)}}"><i class="fas fa-minus"></i></a>
</button>
</div>
{% endif %}
<div class="input-group-prepend">
<button class="btn btn-outline-primary" type="button">
<a style="color:inherit" href="{{url_for(key, id=books[key][cnt.idx].id)}}"><i class="far fa-edit"></i></a>
</button>
</div>
<select class="form-control" id="author[{{cnt.idx}}]">
{% for auth in author_list %}
{% set aname=auth.surname+", "+auth.firstnames %}
<option id="{{auth.id}}" value="{{auth.id}}"
{% if books.author[cnt.idx].id == auth.id %}
selected
{% endif %}
>{{aname}}</option>
{% endfor %}
</select>
</div class="col">
{% set cnt.idx = cnt.idx+1 %}
{% endfor %}
<div class="input-group-append">
<button class="btn btn-outline-success" type="button">
<a style="color:inherit" href="{{url_for(key, id=-1)}}"><i class="fas fa-plus"></i></a>
</button>
</div>
</div class="form-row">
{% else %}
<div class="col">
{% set rows=4 %}
{% if key == "notes" %}
{% set rows=2 %}
{% endif %}
{{book_form[key](class="form-control", value=books[key], rows=rows )}}
</div class="col">
{% endif %}
</div class="form-row">
{% endfor %}
{% if books.series|length %}
<div class="form-row">
<label for="series" class="col-lg-2 col-form-label">Series:</label>
<table>
{% for s in books.series %}
<tr><td>
{% if SeriesBookNum( s.id, books.id ) %}
<label class="form-control-plaintext">Book {{ SeriesBookNum( s.id, books.id ) }} of {{s.num_books}} in <a href="/series/{{s.id}}">{{s.title}}</a></label>
{% else %}
<label class="form-control-plaintext">Contains books in <a href='/series/{{s.id}}'>{{s.title}}</a></label>
{% endif %}
</td></tr>
{% endfor %}
</table>
</div>
{% endif %}
{% if books.child_ref|length %}
<div class="form-row">
<label class="col-lg-2 col-form-label">Sub Books:</label>
<div class="col" id="sub_book_content">
</div>
</div>
{% endif %}
{% if books.parent_ref|length %}
<div class="form-row">
<label class="col-lg-2 col-form-label">Parent Book:</label>
<div class="col">
<label class="form-control-plaintext"><a href="/book/{{b.parent[0].id}}">{{b.parent[0].title}}</a></label>
</div>
</div>
{% endif %}
</form>
{% if books.loan|length %}
<div class="col">
<div class="card border-primary" style="max-width: 18rem;">
<div class="card-header bg-primary text-white">Loaned to</div>
<div class="card-body text-primary">
<h5 class="card-title">{{books.loan[0].firstnames}} {{books.loan[0].surname}}</h5>
<p class="card-text">
When: {{books.loan[0].date_lent}}<br>
Contact: {{books.loan[0].contact_details}}
</div>
</div>
</div>
</div>
{% endif %}
</div class="row">
</div class="container">
{% endblock main_content %}
{% if books.child_ref|length %}
{% block script_content %}
<script>
$(document).ready( function() {
$("#sub_book_content").load("/subbooks_for_book/{{books.id}}")
} )
</script>
{% endblock script_content %}
{% endif %}