can now remove just 1 sub book - TODO-25 -- DONE

This commit is contained in:
2021-01-07 18:58:07 +11:00
parent 9560381a87
commit 860a85e3ae
3 changed files with 61 additions and 20 deletions

View File

@@ -22,13 +22,21 @@
<script>
function ConfirmRemoveParentAndSubsFromSeries(pid,bid)
function ConfirmRemoveParentAndSubsFromSeries(pid,bid,rem)
{
$('#dbox-title').html('Confirm: Removing Parent Book from Series')
if( rem.length > 1 )
all='<span style="background:red" class="text-white"><em>ALL</em></span>'
else
all='this '
div=`
<div class="row col-lg-12">
<p class="lead">You have chosen to remove this (parent) book from a series.
What should we do with the sub-books for <span style="background:red" class="text-white"><em>ALL</em></span> series?</p>
What should we do with the sub-books for
`
div += all
div += `
series?</p>
</div class="row">
<div class="row col-lg-12">
<button id="RPS" class="btn btn-primary col-lg-2">Remove all children</button>
@@ -42,24 +50,43 @@ function ConfirmRemoveParentAndSubsFromSeries(pid,bid)
$('#RPS').attr( 'onClick', "$('#dbox').modal('hide') ; $.post( '/rem_parent_books_from_series/" +pid + "' ) ; window.location='/book/"+ bid + "'" )
}
function ConfirmRemoveThisSubs_ParentAndSubsFromSeries(pid,bid)
function ConfirmRemoveThisSubs_ParentAndSubsFromSeries(pid,bid,rem)
{
$('#dbox-title').html('Confirm: Removing Sub Book from Series')
div=`
<div class="row col-lg-12">
<p>You have chosen to remove this (sub) book from a series.
What should we do with the parent and all its sub-books for <span style="background:red" class="text-white"><em>ALL</em></span>series?</p>
<p class="lead">You have chosen to remove this (sub) book from a series.
What should we do with the sub-books <span id="RPS-text"></span>
</p>
</div class="row">
<div class="row col-lg-12">
<button id="RPS" class="btn btn-primary col-lg-2">Remove parent and all children too</button>
<button onClick="$('#dbox').modal('hide')" class="btn btn-outline-danger offset-lg-8 col-lg-2">
<button id="RPS" class="btn btn-primary col"></button>
<button id="RPS-one" onClick="alert('not yet')" class="btn btn-outline-primary col"></button>
<button onClick="$('#dbox').modal('hide')" class="btn btn-outline-danger col">
Cancel Series change</button>
</div class="row">
`
console.log(rem.length)
if( rem.length > 1 )
{
all='for <span style="background:red" class="text-white"><em>ALL</em></span> series'
b_RPS="Remove parent and all children too " + all
b_RPS_one="Remove just this (sub) book " + all
}
else
{
all='for this series '
b_RPS="Remove parent and all children too"
b_RPS_one="Remove just this (sub) book"
}
$('#dbox-content').html(div)
$('#dbox').modal('show')
// have to do this AFTER modal show otherwise it doesnt exist... (grrr)
$('#RPS-text').html(all)
$('#RPS').html(b_RPS)
$('#RPS').attr( 'onClick', "$('#dbox').modal('hide') ; $.post( '/rem_parent_books_from_series/" +pid + "' ) ; window.location='/book/"+ bid + "'" )
$('#RPS-one').html(b_RPS_one)
$('#RPS-one').attr( 'onClick', "$('#dbox').modal('hide') ; $.post( '/rem_parent_books_from_series/" +bid + "' ) ; window.location='/book/"+ bid + "'" )
}
function SeriesButPlus(num) {
@@ -117,10 +144,19 @@ function RemoveBookFromSeries(sid) {
$('#'+sid).remove()
var num = parseInt( sid.match(/\d+/g), 10 );
// remove the bsl data (its appended outside of div to avoid bootstrap issues
$('[name=bsl-book_id-'+num+']').remove()
$('[name=bsl-series_id-'+num+']').remove()
$('[name=bsl-book_num-'+num+']').remove()
// move real DB data or delete 'new' bsl data (its appended outside of div to avoid bootstrap issues)
if( $('input:hidden[name=bsl-series_id-'+num+']').length )
{
$('[name=bsl-book_id-'+num+']').attr('name', 'removed-book_id-'+num)
$('[name=bsl-series_id-'+num+']').attr('name', 'removed-series_id-'+num)
$('[name=bsl-book_num-'+num+']').attr('name', 'removed-book_num-'+num)
}
else
{
$('[name=bsl-book_id-'+num+']').remove()
$('[name=bsl-series_id-'+num+']').remove()
$('[name=bsl-book_num-'+num+']').remove()
}
if( sid == 'series-div-1' ) {
console.log("remove Book: and it was the only series, so hide series-div-1 and put 'plus / empty' div back" )
@@ -377,11 +413,14 @@ function AddAuthorToBook(num) {
<script>
$(document).ready( function() {
$("#sub_book_content").load("/subbooks_for_book/{{books.id}}")
console.log( {{CheckSeriesChange.removing_series|safe}} )
{% if CheckSeriesChange is defined and CheckSeriesChange != None %}
{% if CheckSeriesChange.type == 'parent' %}
ConfirmRemoveParentAndSubsFromSeries( {{CheckSeriesChange.pid}}, {{CheckSeriesChange.bid}} )
ConfirmRemoveParentAndSubsFromSeries( {{CheckSeriesChange.pid}}, {{CheckSeriesChange.bid}},
{{CheckSeriesChange.removing_series|safe}} )
{% else %}
ConfirmRemoveThisSubs_ParentAndSubsFromSeries( {{CheckSeriesChange.pid}}, {{CheckSeriesChange.bid}} )
ConfirmRemoveThisSubs_ParentAndSubsFromSeries( {{CheckSeriesChange.pid}}, {{CheckSeriesChange.bid}},
{{CheckSeriesChange.removing_series|safe}} )
{% endif %}
{% endif %}
} )