Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
22344a39
Commit
22344a39
authored
5 years ago
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements for delete book
parent
8dde6ba6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
107 additions
and
59 deletions
+107
-59
editbooks.py
cps/editbooks.py
+47
-14
main.js
cps/static/js/main.js
+54
-0
table.js
cps/static/js/table.js
+1
-38
book_edit.html
cps/templates/book_edit.html
+2
-4
book_table.html
cps/templates/book_table.html
+1
-1
modal_dialogs.html
cps/templates/modal_dialogs.html
+2
-2
No files found.
cps/editbooks.py
View file @
22344a39
...
...
@@ -170,21 +170,43 @@ def modify_identifiers(input_identifiers, db_identifiers, db_session):
changed
=
True
return
changed
@
editbook
.
route
(
"/ajax/delete/<int:book_id>"
)
@
login_required
def
delete_book_from_details
(
book_id
):
return
delete_book
(
book_id
,
""
,
True
)
@
editbook
.
route
(
"/delete/<int:book_id>
/
"
,
defaults
=
{
'book_format'
:
""
})
@
editbook
.
route
(
"/delete/<int:book_id>/<string:book_format>
/
"
)
@
editbook
.
route
(
"/delete/<int:book_id>"
,
defaults
=
{
'book_format'
:
""
})
@
editbook
.
route
(
"/delete/<int:book_id>/<string:book_format>"
)
@
login_required
def
delete_book
(
book_id
,
book_format
):
def
delete_book_ajax
(
book_id
,
book_format
):
return
delete_book
(
book_id
,
book_format
,
False
)
def
delete_book
(
book_id
,
book_format
,
jsonResponse
):
warning
=
{}
if
current_user
.
role_delete_books
():
book
=
calibre_db
.
get_book
(
book_id
)
if
book
:
try
:
result
,
error
=
helper
.
delete_book
(
book
,
config
.
config_calibre_dir
,
book_format
=
book_format
.
upper
())
if
not
result
:
flash
(
error
,
category
=
"error"
)
return
redirect
(
url_for
(
'editbook.edit_book'
,
book_id
=
book_id
))
if
jsonResponse
:
return
Response
(
json
.
dumps
({
"location"
:
url_for
(
"editbook.edit_book"
),
"type"
:
"alert"
,
"format"
:
""
,
"error"
:
error
}),
mimetype
=
'application/json'
)
else
:
flash
(
error
,
category
=
"error"
)
return
redirect
(
url_for
(
'editbook.edit_book'
,
book_id
=
book_id
))
if
error
:
flash
(
error
,
category
=
"warning"
)
if
jsonResponse
:
warning
=
{
"location"
:
url_for
(
"editbook.edit_book"
),
"type"
:
"warning"
,
"format"
:
""
,
"error"
:
error
}
else
:
flash
(
error
,
category
=
"warning"
)
if
not
book_format
:
# delete book from Shelfs, Downloads, Read list
ub
.
session
.
query
(
ub
.
BookShelf
)
.
filter
(
ub
.
BookShelf
.
book_id
==
book_id
)
.
delete
()
...
...
@@ -240,11 +262,25 @@ def delete_book(book_id, book_format):
# book not found
log
.
error
(
'Book with id "
%
s" could not be deleted: not found'
,
book_id
)
if
book_format
:
flash
(
_
(
'Book Format Successfully Deleted'
),
category
=
"success"
)
return
redirect
(
url_for
(
'editbook.edit_book'
,
book_id
=
book_id
))
if
jsonResponse
:
return
Response
(
json
.
dumps
([
warning
,
{
"location"
:
url_for
(
"editbook.edit_book"
,
book_id
=
book_id
),
"type"
:
"success"
,
"format"
:
book_format
,
"message"
:
_
(
'Book Format Successfully Deleted'
)}]),
mimetype
=
'application/json'
)
else
:
flash
(
_
(
'Book Format Successfully Deleted'
),
category
=
"success"
)
return
redirect
(
url_for
(
'editbook.edit_book'
,
book_id
=
book_id
))
else
:
flash
(
_
(
'Book Successfully Deleted'
),
category
=
"success"
)
return
redirect
(
url_for
(
'web.index'
))
if
jsonResponse
:
return
Response
(
json
.
dumps
([
warning
,
{
"location"
:
url_for
(
'web.index'
),
"type"
:
"success"
,
"format"
:
book_format
,
"message"
:
_
(
'Book Successfully Deleted'
)}]),
mimetype
=
'application/json'
)
else
:
flash
(
_
(
'Book Successfully Deleted'
),
category
=
"success"
)
return
redirect
(
url_for
(
'web.index'
))
def
render_edit_book
(
book_id
):
...
...
@@ -947,10 +983,7 @@ def get_sorted_entry(field, bookid):
return
json
.
dumps
({
'author_sort'
:
book
.
author_sort
})
return
""
@
editbook
.
route
(
"/ajax/deletebooks"
)
@
login_required
def
delete_list_book
():
return
""
@
editbook
.
route
(
"/ajax/mergebooks"
,
methods
=
[
'POST'
])
@
login_required
...
...
This diff is collapsed.
Click to expand it.
cps/static/js/main.js
View file @
22344a39
...
...
@@ -58,6 +58,60 @@ $(document).on("change", "select[data-controlall]", function() {
}
});
$
(
"#delete_confirm"
).
click
(
function
()
{
//get data-id attribute of the clicked element
var
pathname
=
document
.
getElementsByTagName
(
"script"
),
src
=
pathname
[
pathname
.
length
-
1
].
src
;
var
path
=
src
.
substring
(
0
,
src
.
lastIndexOf
(
"/"
));
var
deleteId
=
$
(
this
).
data
(
"delete-id"
);
var
bookFormat
=
$
(
this
).
data
(
"delete-format"
);
if
(
bookFormat
)
{
window
.
location
.
href
=
path
+
"/../../delete/"
+
deleteId
+
"/"
+
bookFormat
;
}
else
{
if
(
$
(
this
).
data
(
"delete-format"
))
{
path
=
path
+
"/../../ajax/delete/"
+
deleteId
;
$
.
ajax
({
method
:
"get"
,
url
:
path
,
timeout
:
900
,
success
:
function
(
data
)
{
data
.
forEach
(
function
(
item
)
{
if
(
!
jQuery
.
isEmptyObject
(
item
))
{
if
(
item
.
format
!=
""
)
{
$
(
"button[data-delete-format='"
+
item
.
format
+
"']"
).
addClass
(
'hidden'
);
}
$
(
".navbar"
).
after
(
'<div class="row-fluid text-center" style="margin-top: -20px;">'
+
'<div id="flash_'
+
item
.
type
+
'" class="alert alert-'
+
item
.
type
+
'">'
+
item
.
message
+
'</div>'
+
'</div>'
);
}
});
}
});
}
else
{
window
.
location
.
href
=
path
+
"/../../delete/"
+
deleteId
;
}
}
});
//triggered when modal is about to be shown
$
(
"#deleteModal"
).
on
(
"show.bs.modal"
,
function
(
e
)
{
//get data-id attribute of the clicked element and store in button
var
bookId
=
$
(
e
.
relatedTarget
).
data
(
"delete-id"
);
var
bookfomat
=
$
(
e
.
relatedTarget
).
data
(
"delete-format"
);
if
(
bookfomat
)
{
$
(
"#book_format"
).
removeClass
(
'hidden'
);
$
(
"#book_complete"
).
addClass
(
'hidden'
);
}
else
{
$
(
"#book_complete"
).
removeClass
(
'hidden'
);
$
(
"#book_format"
).
addClass
(
'hidden'
);
}
$
(
e
.
currentTarget
).
find
(
"#delete_confirm"
).
data
(
"delete-id"
,
bookId
);
$
(
e
.
currentTarget
).
find
(
"#delete_confirm"
).
data
(
"delete-format"
,
bookfomat
);
});
$
(
function
()
{
var
updateTimerID
;
...
...
This diff is collapsed.
Click to expand it.
cps/static/js/table.js
View file @
22344a39
...
...
@@ -128,28 +128,14 @@ $(function() {
onColumnSwitch
:
function
(
field
,
checked
)
{
var
visible
=
$
(
"#books-table"
).
bootstrapTable
(
'getVisibleColumns'
);
var
hidden
=
$
(
"#books-table"
).
bootstrapTable
(
'getHiddenColumns'
);
// to save current setting
// coresponding event: onColumnSwitch
//$table.bootstrapTable('getVisibleColumns')
//$table.bootstrapTable('getHiddenColumns').
var
visibility
=
[]
var
st
=
""
visible
.
forEach
(
function
(
item
)
{
st
+=
"
\"
"
+
item
.
field
+
"
\"
:
\"
"
+
"true"
+
"
\"
,"
/*var element = {};
element[item.field] = "true";
visibility.push(element);*/
});
hidden
.
forEach
(
function
(
item
)
{
st
+=
"
\"
"
+
item
.
field
+
"
\"
:
\"
"
+
"false"
+
"
\"
,"
/*var element = {};
element[item.field] = "false";
visibility.push(element);*/
});
/*
visibility.forEach(function(item) {
st += JSON.stringify(item) + ',';
});*/
st
=
st
.
slice
(
0
,
-
1
);
$
.
ajax
({
method
:
"post"
,
...
...
@@ -238,29 +224,6 @@ $(function() {
$
(
e
.
currentTarget
).
find
(
"#btndeletedomain"
).
data
(
"domainId"
,
domainId
);
});
$
(
"#delete_confirm"
).
click
(
function
()
{
//get data-id attribute of the clicked element
var
deleteId
=
$
(
this
).
data
(
"deleteid"
);
$
.
ajax
({
method
:
"get"
,
url
:
window
.
location
.
pathname
+
"/../../delete/"
+
deleteId
,
});
});
//triggered when modal is about to be shown
$
(
"#deleteModal"
).
on
(
"show.bs.modal"
,
function
(
e
)
{
//get data-id attribute of the clicked element and store in button
var
bookId
=
$
(
e
.
relatedTarget
).
data
(
"delete-id"
);
$
(
e
.
currentTarget
).
find
(
"#delete_confirm"
).
data
(
"deleteid"
,
bookId
);
});
// receive result from request, dismiss modal dialog, show flash message
// insert after navbar
/*$("#deleteModal").on("hidden.bs.modal", function () {
<div class="row-fluid text-center" style="margin-top: -20px;">
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div>
</div>*/
$
(
"#restrictModal"
).
on
(
"hidden.bs.modal"
,
function
()
{
// Destroy table and remove hooks for buttons
$
(
"#restrict-elements-table"
).
unbind
();
...
...
@@ -385,7 +348,7 @@ function RestrictionActions (value, row) {
/* Function for deleting books */
function
EbookActions
(
value
,
row
)
{
return
[
"<div class=
\"
book-remove
\"
data-toggle=
\"
modal
\"
data-target=
\"
#deleteModal
\"
data-delete-id=
\"
"
+
row
.
id
+
"
\"
title=
\"
Remove
\"
>"
,
"<div class=
\"
book-remove
\"
data-toggle=
\"
modal
\"
data-target=
\"
#deleteModal
\"
data-
ajax=
\"
1
\"
data-
delete-id=
\"
"
+
row
.
id
+
"
\"
title=
\"
Remove
\"
>"
,
"<i class=
\"
glyphicon glyphicon-trash
\"
></i>"
,
"</div>"
].
join
(
""
);
...
...
This diff is collapsed.
Click to expand it.
cps/templates/book_edit.html
View file @
22344a39
...
...
@@ -7,14 +7,12 @@
</div>
{% if g.user.role_delete_books() %}
<div
class=
"text-center"
>
<button
type=
"button"
class=
"btn btn-danger"
id=
"delete"
data-toggle=
"modal"
data-target=
"#deleteModal"
>
{{_("Delete Book")}}
</button>
<button
type=
"button"
class=
"btn btn-danger"
id=
"delete"
data-toggle=
"modal"
data-
delete-id=
"{{ book.id }}"
data-
target=
"#deleteModal"
>
{{_("Delete Book")}}
</button>
</div>
{% if book.data|length > 1 %}
<div
class=
"text-center more-stuff"
><h4>
{{_('Delete formats:')}}
</h4>
{% for file in book.data %}
<div
class=
"form-group"
>
<a
href=
"{{ url_for('editbook.delete_book', book_id=book.id, book_format=file.format) }}"
class=
"btn btn-danger"
type=
"button"
>
{{_('Delete')}} - {{file.format}}
</a>
</div>
<button
type=
"button"
class=
"btn btn-danger"
id=
"delete_format"
data-toggle=
"modal"
data-delete-id=
"{{ book.id }}"
data-delete-format=
"{{ file.format }}"
data-target=
"#deleteModal"
>
{{_('Delete')}} - {{file.format}}
</button>
{% endfor %}
</div>
{% endif %}
...
...
This diff is collapsed.
Click to expand it.
cps/templates/book_table.html
View file @
22344a39
...
...
@@ -51,7 +51,7 @@
{{ text_table_row('series', _('Enter Series'),_('Series'), false) }}
<th
data-field=
"series_index"
id=
"series_index"
data-visible=
"{{visiblility.get('series_index')}}"
data-edit-validate=
"{{ _('This Field is Required') }}"
data-sortable=
"true"
{%
if
g
.
user
.
role_edit
() %}
data-editable-type=
"number"
data-editable-placeholder=
"1"
data-editable-step=
"0.01"
data-editable-min=
"0"
data-editable-url=
"{{ url_for('editbook.edit_list_book', param='series_index')}}"
data-edit=
"true"
data-editable-title=
"{{_('Enter title')}}"
{%
endif
%}
>
{{_('Series Index')}}
</th>
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false) }}
<
th
data-field=
"pubdate"
data-type=
"date"
data-visible=
"{{visiblility.get('pubdate')}}"
data-viewformat=
"dd.mm.yyyy"
id=
"pubdate"
data-sortable=
"true"
>
{{_('Publishing Date')}}
</th
>
<
!--th data-field="pubdate" data-type="date" data-visible="{{visiblility.get('pubdate')}}" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">{{_('Publishing Date')}}</th--
>
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false) }}
{% if g.user.role_edit() %}
<th
data-align=
"right"
data-formatter=
"EbookActions"
data-switchable=
"false"
>
{{_('Delete')}}
</th>
...
...
This diff is collapsed.
Click to expand it.
cps/templates/modal_dialogs.html
View file @
22344a39
...
...
@@ -47,7 +47,8 @@
</div>
<div
class=
"modal-body text-center"
>
<p>
<span>
{{_('This book will be permanently erased from database')}}
</span>
<span
class=
"hidden"
id=
"book_format"
>
{{_('This book format will be permanently erased from database')}}
</span>
<span
class=
"hidden"
id=
"book_complete"
>
{{_('This book will be permanently erased from database')}}
</span>
<span>
{{_('and hard disk')}}
</span>
</p>
{% if config.config_kobo_sync %}
...
...
@@ -60,7 +61,6 @@
<div
class=
"modal-footer"
>
<input
type=
"button"
class=
"btn btn-danger"
value=
"{{_('Delete')}}"
name=
"delete_confirm"
id=
"delete_confirm"
data-dismiss=
"modal"
>
<!--a href="{{ url_for('editbook.delete_book', book_id=bookid) }}" id="delete_confirm" class="btn btn-danger">{{_('Delete')}}</a-->
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{{_('Cancel')}}
</button>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment