Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve UI for activating ebooks #1001

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions frontend/templates/ebook_list.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{% if work.ebooks_all %}
<h3>Manage eBooks</h3>
<ul>
<li><span style='display:inline-block;padding-left:1em'>off</span><span style='display:inline-block;padding-left:1em'>on</span></li>
{% for ebook in work.ebooks_all %}
<li>
<span style='display:inline-block;padding-left:0em'>
<input type="radio" name="activate_ebook_{{ ebook.id }}" value="deactivate" class="deletebutton" title="deactivate ebook" {% if not ebook.active %}checked{% endif %} />
</span><span style='display:inline-block;padding-left:0em'>
<input type="radio" name="activate_ebook_{{ ebook.id }}" value="activate" class="deletebutton" title="activate ebook" {% if ebook.active %}checked{% endif %}/>
</span>
<a href="{{ ebook.url }}">{{ ebook.format }}{%if ebook.rights %}, {{ ebook.rights }}{% endif %}</a>, created {{ ebook.created }}{% if ebook.user %},
by <a href="{% url 'supporter' ebook.user_id %}">{{ ebook.user }}</a>{% endif %}.
{% if ebook.filesize %}{{ ebook.filesize }}{% else %}??{% endif %}B
{% if ebook.version_label %}{{ ebook.version }}{% endif %}
{% if ebook.active %}<input type="submit" name="deactivate_ebook_{{ ebook.id }}" value="deactivate" class="deletebutton" title="deactivate ebook" />{% else %}<input type="submit" name="activate_ebook_{{ ebook.id }}" value="activate" class="deletebutton" title="activate ebook" />{% endif %}{% if request.user.is_staff %} <a href="{% url 'admin:core_ebook_change' ebook.id %}">admin</a>{% endif %}
{% if request.user.is_staff %} <a href="{% url 'admin:core_ebook_change' ebook.id %}">admin</a>{% endif %}
</li>
{% endfor %}
</ul>
<br />
<input type="submit" name="activate_all_ebooks" value="activate all ebooks" class="deletebutton" title="activate all ebooks" />
<input type="submit" name="deactivate_all_ebooks" value="deactivate all ebooks" class="deletebutton" title="deactivate all ebooks" />
<input type="submit" name="activate_recent_ebooks" value="activate recent ebooks" class="deletebutton" title="activate recent ebooks" />
<input type="submit" name="activate_selected_ebooks" value="activate selected ebooks" class="deletebutton" title="activate selected ebooks" />
<br />
<br />
{{ form.set_rights}}<input type="submit" name="set_ebook_rights" value="set ebook licenses" class="deletebutton" title="set ebook licenses" />
Expand Down
31 changes: 24 additions & 7 deletions frontend/views/bibedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,30 @@ def edit_edition(request, work_id, edition_id, by=None):
ebook.rights = rights
ebook.save()
ebookchange = True
for ebook in work.ebooks_all():
if 'activate_ebook_%s' % ebook.id in request.POST or activate_all:
ebook.activate()
ebookchange = True
elif 'deactivate_ebook_%s' % ebook.id in request.POST or deactivate_all:
ebook.deactivate()
ebookchange = True
if 'activate_recent_ebooks' in request.POST:
done_fmt = set()
for ebook in work.ebooks_all():
for fmt in ['pdf', 'epub', 'mobi']:
if ebook.format == fmt:
if fmt not in done_fmt:
ebook.activate()
done_fmt.add(fmt)
else:
ebook.deactivate()
ebookchange = True
else:
for ebook in work.ebooks_all():
ebook_key = 'activate_ebook_%s' % ebook.id
if ebook_key in request.POST and "activate_selected_ebooks" in request.POST:
ebook_action = request.POST[ebook_key]
if ebook.active :
if ebook_action == 'deactivate':
ebook.deactivate()
ebookchange = True
else:
if ebook_action == 'activate':
ebook.activate()
ebookchange = True
if ebookchange:
keep_editing = True
form = EditionForm(instance=edition, data=request.POST, files=request.FILES)
Expand Down