119 lines
3.6 KiB
HTML
119 lines
3.6 KiB
HTML
<script>
|
|
function ActivateBFLRemSelButton()
|
|
{
|
|
$('#bfl-remsel-btn').removeClass('disabled')
|
|
$('#bfl-remsel-btn').attr('disabled',false)
|
|
}
|
|
|
|
function DeactivateBFLRemSelButton()
|
|
{
|
|
$('#bfl-remsel-btn').addClass('disabled')
|
|
$('#bfl-remsel-btn').attr('disabled',true)
|
|
}
|
|
|
|
function RemoveSelFromLoan()
|
|
{
|
|
var params=$("#book_table :input").serializeArray()
|
|
$.post( "/rem_books_from_loan/" + {{loan_id}}, params, function(data) {
|
|
DeactivateBFLRemSelButton()
|
|
$('#bfl-existing').load('/books_for_loan/' + {{loan_id}}, { 'InDBox' : 1 } )
|
|
} )
|
|
}
|
|
|
|
function ShowLoanDBox()
|
|
{
|
|
$('#dbox-title').html('Add / Remove Books to / from Loan')
|
|
div=`
|
|
<div id="bfl-existing" class="col-lg-10 px-0"></div>
|
|
<div class="col">
|
|
<button id="bfl-remsel-btn" class="btn btn-danger disabled" disabled onClick="RemoveSelFromLoan()">Remove Selected</button>
|
|
</div>
|
|
<div id="bfl-search" class="input-group">
|
|
<input class="form-control" type="text" id="bfl-search-term" placeholder="title of book(s) to add">
|
|
<div class="input-group-append">
|
|
<button type="button" class="btn btn-primary" onClick="FindNewBFL()">Search</button>
|
|
</div>
|
|
</div>
|
|
<br>
|
|
<div id="bfl-new" class="col-lg-10 px-0 py-4"></div>
|
|
<div class="col py-4">
|
|
<button id="bfl-addsel-btn" class="btn btn-success disabled" disabled style="display:none" onClick="AddSelToLoan()">Add Selected</button>
|
|
</div>
|
|
`
|
|
$('#dbox-content').html(div)
|
|
$('#dbox').modal('show')
|
|
$.post( "/books_for_loan/" + {{loan_id}}, function(data) {$('#bfl-existing').html(data) } );
|
|
}
|
|
|
|
function FindNewBFL()
|
|
{
|
|
$.post( "/search",{ 'term': $('#bfl-search-term').val(), 'InDBox': 1 }, function(data) { $('#bfl-new').html(data) ; $('#bfl-addsel-btn').show() } );
|
|
}
|
|
|
|
function ActivateBFLAddSelButton()
|
|
{
|
|
$('#bfl-addsel-btn').removeClass('disabled')
|
|
$('#bfl-addsel-btn').attr('disabled',false)
|
|
}
|
|
|
|
function DeactivateBFLAddSelButton()
|
|
{
|
|
$('#bfl-addsel-btn').addClass('disabled')
|
|
$('#bfl-addsel-btn').attr('disabled',true)
|
|
$('#bfl-addsel-btn').attr('style','display:none')
|
|
}
|
|
|
|
function AddSelToLoan()
|
|
{
|
|
var params=$("#addsel_table :input").serializeArray()
|
|
$.post( "/add_books_to_loan/" + {{loan_id}}, params, function(data) {
|
|
DeactivateBFLAddSelButton()
|
|
DeactivateBFLRemSelButton()
|
|
$('#bfl-search-term').val('')
|
|
$('#bfl-new').html('')
|
|
$('#bfl-existing').load('/books_for_loan/' + {{loan_id}}, { 'InDBox' : 1 } )
|
|
} )
|
|
}
|
|
</script>
|
|
|
|
{% if not InDBox %}
|
|
<h3>Loaned Books</h3>
|
|
{% endif %}
|
|
|
|
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
|
<thead>
|
|
<tr class="thead-light">
|
|
<th>Title</th>
|
|
<th>Author(s)</th>
|
|
<th>Covertype</th>
|
|
{% if InDBox %}
|
|
<th>Remove?</th>
|
|
{% endif %}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for book in books %}
|
|
<tr>
|
|
{% if book.sub_book_num is defined %}
|
|
<td data-sort="{{book.parent_id}}.{{book.sub_book_num}}"><a href="/book/{{book.id}}"> {{book.title}}</a></td>
|
|
{% else %}
|
|
<td data-sort="{{book.id}}"><a href="/book/{{book.id}}">{{book.title}}</a></td>
|
|
{% endif %}
|
|
<td>
|
|
{% for auth in book.author %}
|
|
{{ auth['surname'] }}, {{auth['firstnames']}}
|
|
{% endfor %}
|
|
</td>
|
|
<td>{{ GetCovertypeById(book.covertype) }}</td>
|
|
{% if InDBox %}
|
|
<td><input name="bfl-rem-{{book.id}}" type="checkbox" onClick="ActivateBFLRemSelButton()"></td>
|
|
{% endif %}
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
|
|
{% if not InDBox %}
|
|
<button type="button" class="btn btn-primary" onClick="ShowLoanDBox()">Add/Remove Books in Loan</button>
|
|
{% endif %}
|