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
80e6311b
Commit
80e6311b
authored
Feb 21, 2017
by
idalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fetch metadata from douban while editing metadata
parent
4ec30500
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
0 deletions
+104
-0
douban_meta.js
cps/static/js/douban_meta.js
+87
-0
book_edit.html
cps/templates/book_edit.html
+17
-0
No files found.
cps/static/js/douban_meta.js
0 → 100644
View file @
80e6311b
/*
* Get Metadata from Douban api
* Created by idalin<dalin.lin@gmail.com>
*/
$
(
document
).
ready
(
function
()
{
var
get_meta_btn
=
'<li>'
+
'<a href="#" id="get_meta" data-toggle="modal" data-target="#metaModal">'
+
'获取Meta</a></li>'
;
$
(
'#main-nav'
).
prepend
(
get_meta_btn
);
var
douban
=
'https://api.douban.com'
;
var
search
=
'/v2/book/search'
;
var
get_info
=
'/v2/book/'
;
var
get_info_by_isbn
=
'/v2/book/isbn/ '
;
$
.
ajaxSetup
({
type
:
"GET"
,
dataType
:
"jsonp"
,
jsonp
:
'callback'
,
async
:
false
});
get_meta
=
function
(
id
)
{
var
url
=
douban
+
get_info
+
id
;
console
.
log
(
'getting book meta:'
+
id
);
$
.
ajax
({
url
:
url
,
success
:
function
(
meta
)
{
console
.
log
(
meta
);
//$('#metaModal').modal('hide');
$
(
'#description'
).
val
(
meta
.
summary
);
$
(
'#bookAuthor'
).
val
(
meta
.
author
.
join
(
' & '
));
$
(
'#book_title'
).
val
(
meta
.
title
);
var
tags
=
''
;
for
(
var
i
=
0
;
i
<
meta
.
tags
.
length
;
i
++
)
{
tags
=
tags
+
meta
.
tags
[
i
].
title
+
','
;
}
$
(
'#tags'
).
val
(
tags
);
$
(
'#rating'
).
val
(
Math
.
round
(
meta
.
rating
.
average
/
4
));
}
});
}
get_meta_by_isbn
=
function
(
isbn
)
{
var
url
=
douban
+
get_info_by_isbn
+
isbn
;
}
search_book
=
function
(
title
)
{
var
url
=
douban
+
search
+
'?q='
+
title
+
'&fields=id,title,author,publisher,isbn13,image,summary'
;
$
.
ajax
({
url
:
url
,
success
:
function
(
data
)
{
if
(
data
.
books
.
length
<
1
)
{
$
(
'#meta-info'
).
html
(
'<p class="text-danger">搜索不到对应的书籍</p>'
);
}
else
{
$
(
'#meta-info'
).
html
(
'<ul id="book-list" class="media-list"></ul>'
);
for
(
var
i
=
0
;
i
<
data
.
books
.
length
;
i
++
)
{
var
book
=
'<li class="media">'
+
'<img class="pull-left img-responsive" data-toggle="modal" data-target="#metaModal" src="'
+
data
.
books
[
i
].
image
+
'" alt="Cover" onclick="javascript:get_meta('
+
data
.
books
[
i
].
id
+
')">'
+
'<div class="media-body">'
+
'<h4 class="media-heading"><a href="https://book.douban.com/subject/'
+
data
.
books
[
i
].
id
+
'" target="_blank">'
+
data
.
books
[
i
].
title
+
'</a></h4>'
+
'<p>作者:'
+
data
.
books
[
i
].
author
+
'</p>'
+
'<p>出版社:'
+
data
.
books
[
i
].
publisher
+
'</p>'
+
'<p>简介:'
+
data
.
books
[
i
].
summary
+
'</p>'
+
'</div>'
+
'</li>'
;
$
(
"#book-list"
).
append
(
book
);
}
}
},
error
:
function
()
{
$
(
'#meta-info'
).
html
(
'<p class="text-danger">搜索出错</p>'
);
}
});
}
$
(
'#get_meta'
).
click
(
function
()
{
var
book_title
=
$
(
'#book_title'
).
val
();
if
(
book_title
)
{
// console.log(book_title);
search_book
(
book_title
);
}
});
});
\ No newline at end of file
cps/templates/book_edit.html
View file @
80e6311b
...
...
@@ -109,11 +109,28 @@
</form>
</div>
{% endif %}
<div
class=
"modal fade"
id=
"metaModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"metaModalLabel"
>
<div
class=
"modal-dialog"
role=
"document"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
<h4
class=
"modal-title"
id=
"metaModalLabel"
>
{{_('Get meta data')}}
</h4>
</div>
<div
class=
"modal-body"
id=
"meta-info"
>
{{_("Loading...")}}
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{{_('Close')}}
</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<script
src=
"{{ url_for('static', filename='js/libs/typeahead.bundle.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/edit_books.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/douban_meta.js') }}"
></script>
{% endblock %}
{% block header %}
<link
href=
"{{ url_for('static', filename='css/libs/typeahead.css') }}"
rel=
"stylesheet"
media=
"screen"
>
...
...
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