Content server: When browsing random books, add a button to the book page to get another random book. Fixes #1134958 (Request: Add random button to random results)

This commit is contained in:
Kovid Goyal 2013-02-28 10:17:15 +05:30
parent bbeebd1c1d
commit ff33a74a44
4 changed files with 24 additions and 5 deletions

View File

@ -482,5 +482,10 @@ h2.library_name {
border: none
}
.details #random_button {
display:block
}
/* }}} */

View File

@ -324,9 +324,15 @@ function show_details(a_dom) {
function book() {
hidesort();
$('.details .left img').load(function() {
var rb = $('#random_button');
rb.button();
var img = $('.details .left img');
var height = $('#main').height();
height = Math.max(height, img.height() + 100);
var bh = 0;
if (rb.length > 0) {
bh = rb.height();
}
height = Math.max(height, img.height() + bh + 100);
$('#main').height(height);
});
}

View File

@ -1,6 +1,7 @@
<div id="details_{id}" class="details">
<div class="left">
<a href="{get_url}" title="Click to read {title} in the {fmt} format" class="details_thumb"><img alt="Cover of {title}" src="{prefix}/get/cover/{id}" /></a>
{random}
</div>
<div class="right">
<div class="field formats">{formats}</div>

View File

@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import operator, os, json, re
import operator, os, json, re, time
from binascii import hexlify, unhexlify
from collections import OrderedDict
@ -819,7 +819,7 @@ class BrowseServer(object):
raw = json.dumps('\n'.join(summs), ensure_ascii=True)
return raw
def browse_render_details(self, id_):
def browse_render_details(self, id_, add_random_button=False):
try:
mi = self.db.get_metadata(id_, index_is_id=True)
except:
@ -886,11 +886,18 @@ class BrowseServer(object):
u'<div class="comment">%s</div></div>') % (xml(c[0]),
c[1]) for c in comments]
comments = u'<div class="comments">%s</div>'%('\n\n'.join(comments))
random = ''
if add_random_button:
href = '%s/browse/random?v=%s'%(
self.opts.url_prefix, time.time())
random = '<a href="%s" id="random_button" title="%s">%s</a>' % (
xml(href, True), xml(_('Choose another random book'), True),
xml(_('Another random book')))
return self.browse_details_template.format(
id=id_, title=xml(mi.title, True), fields=fields,
get_url=args['get_url'], fmt=args['fmt'],
formats=args['formats'], comments=comments)
formats=args['formats'], comments=comments, random=random)
@Endpoint(mimetype='application/json; charset=utf-8')
def browse_details(self, id=None):
@ -908,7 +915,7 @@ class BrowseServer(object):
import random
book_id = random.choice(self.db.search_getting_ids(
'', self.search_restriction))
ans = self.browse_render_details(book_id)
ans = self.browse_render_details(book_id, add_random_button=True)
return self.browse_template('').format(
title='', script='book();', main=ans)