]> git.phdru.name Git - m_librarian.git/blob - m_librarian/web/views/list_books.tmpl
Feat(web/views/list_books): Toggle checkboxes for an author
[m_librarian.git] / m_librarian / web / views / list_books.tmpl
1 #encoding utf-8
2 #import cgi
3 #from m_librarian.translations import translations
4 #extends views.layout
5 #attr $title = 'Список книг'
6 #def body
7 <h1>$title</h1>
8
9 <script type="text/javascript" language="Javascript">
10 <!--
11 function toggleBooks(selector, value) {
12   cboxes = document.querySelectorAll(selector);
13   for (var i = 0; i < cboxes.length; i++) {
14     cboxes[i].checked = value;
15   }
16 }
17
18 function toggleAuthor(name, value) {
19   toggleBooks('input[type=checkbox][name^=' + name + ']', value);
20 }
21
22 function toggleSeries(name, value) {
23   toggleBooks('input[type=checkbox][name^=' + name + '_book]', value);
24 }
25 // -->
26 </script>
27
28 #if $books_by_author
29   <form action="/download/" method="POST" style="height: 80%">
30   <table style="width: 100%; height: 90%">
31   <tr>
32   <td>&nbsp;</td>
33   #set $_ = $getattr($translations, 'ugettext', None) or $translations.gettext
34   #for $column in $columns
35     <td style="text-align: center">$cgi.escape($_($column))</td>
36   #end for
37   </tr>
38   #set $columns1 = $len($columns)+1
39   #for $anum, $author in $enumerate($sorted($books_by_author))
40     #set $series = None
41     #set $snum = 0
42     #set $books = $books_by_author[$author]
43   <tr>
44   <td><input type=checkbox name="a${anum+1}_"
45   onClick="toggleAuthor(this.name, this.checked)"></td>
46   <td colspan="${columns1-1}"><b>$author</b></td>
47   </tr>
48     #for $book in $books
49     #if $book.series != $series
50     #set $series = $book.series
51     #set $snum += 1
52   <tr>
53   <td><input type=checkbox name="a${anum+1}_s${snum}"
54   onClick="toggleSeries(this.name, this.checked)"></td>
55   <td colspan="${columns1-1}"><b>
56   $author — <i>
57   #if $book.series
58 $cgi.escape($series, 1)#slurp
59   #else
60 Вне серий#slurp
61   #end if
62   </i></b></td>
63   </tr>
64     #end if
65   <tr>
66   <td><input type=checkbox name="a${anum+1}_s${snum}_books" value="$book.id"></td>
67   #for $column in $columns
68   #if $column in ('ser_no', 'size')
69   #set $style = ' style="text-align: right; width: 5ex"'
70   #else
71   #set $style = ''
72   #end if
73   <td$style>$cgi.escape(unicode($getattr($book, $column) or ''))</td>
74   #end for
75   </tr>
76     #end for
77   #end for
78   <tr>
79   <td colspan="$columns1" style="text-align: center"><input type="submit" value="Скачать"></td>
80   </tr>
81   </table>
82   </form>
83 #else
84   <p>Не найдено ни одной книги!</p>
85 #end if
86 #end def