Bug 34083: (follow-up) Prevent showing 'null'
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / patron_lists / list.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE KohaDates %]
4 [% USE TablesSettings %]
5 [% SET footerjs = 1 %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 [% INCLUDE 'columns_settings.inc' %]
8 <title>Add patrons &rsaquo; [% list.name | html %] &rsaquo; Patron lists &rsaquo; Tools &rsaquo; Koha</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10
11 <style>
12     #add_patrons_by_search {
13         display: none;
14     }
15     #patron_ids_line {
16         display: none;
17     }
18     #patron_ids_submit {
19         display: none;
20     }
21     #searchheader {
22         margin-top: 1em;
23     }
24 </style>
25 </head>
26
27 <body id="patlist_list" class="pat patlist">
28 [% WRAPPER 'header.inc'  %]
29     [% INCLUDE 'cat-search.inc' %]
30 [% END %]
31
32 [% WRAPPER 'sub-header.inc' %]
33     [% WRAPPER breadcrumbs %]
34         [% WRAPPER breadcrumb_item %]
35             <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
36         [% END %]
37         [% WRAPPER breadcrumb_item %]
38             <a href="lists.pl">Patron lists</a>
39         [% END %]
40         [% WRAPPER breadcrumb_item %]
41             <a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% list.id | uri %]">[% list.name | html %]</a>
42         [% END %]
43         [% WRAPPER breadcrumb_item bc_active= 1 %]
44             <span>Add patrons</span>
45         [% END %]
46     [% END #/ WRAPPER breadcrumbs %]
47 [% END #/ WRAPPER sub-header.inc %]
48
49 <div class="main container-fluid">
50     <div class="row">
51         <div class="col-sm-10 col-sm-push-2">
52             <main>
53
54         <h1>[% list.name | html %]</h1>
55
56         [% IF ( not_found.size > 0 ) %]
57         [% IF id_column == 'borrowernumbers' %]
58             <div class="dialog alert"><p>Warning, the following borrowernumbers were not found:</p></div>
59         [% ELSE %]
60             <div class="dialog alert"><p>Warning, the following cardnumbers were not found:</p></div>
61         [% END %]
62         <table style="margin:auto;">
63             <thead>
64                 [% IF id_column == 'borrowernumbers' %]
65                     <tr><th>Borrowernumbers not found</th></tr>
66                 [% ELSE %]
67                     <tr><th>Cardnumbers not found</th></tr>
68                 [% END %]
69             </thead>
70             <tbody>
71             [% FOREACH nf IN not_found %]
72                 <tr><td>[% nf | html %]</td></td>
73             [% END %]
74             </tbody>
75         </table>
76         [% END %]
77
78         [% IF ( existed.size > 0 ) %]
79         [% IF id_column == 'borrowernumbers' %]
80             <div class="dialog alert"><p>Warning, the following borrowernumbers were already in this list:</p></div>
81         [% ELSE %]
82             <div class="dialog alert"><p>Warning, the following cardnumbers were already in this list:</p></div>
83         [% END %]
84         <table style="margin:auto;">
85             <thead>
86                 [% IF id_column == 'borrowernumbers' %]
87                     <tr><th>Borrowernumbers already in list</th></tr>
88                 [% ELSE %]
89                     <tr><th>Cardnumbers already in list</th></tr>
90                 [% END %]
91             </thead>
92             <tbody>
93             [% FOREACH ed IN existed %]
94                 <tr><td>[% ed | html %]</td></td>
95             [% END %]
96             </tbody>
97         </table>
98         [% END %]
99
100         <form action="list.pl" id="add_patrons" method="post" class="clearfix">
101             <fieldset class="rows">
102                 <legend>Add patrons</legend>
103                 <ol>
104                     <li id="patron_search_line">
105                         <label for="find_patron">Patron search: </label>
106                         <input autocomplete="off" id="find_patron" type="text" style="width:150px" class="noEnterSubmit" />
107                     </li>
108                     <li id="add_patrons_by_search"><a href="#">
109                         <span class="label">&nbsp;</span>
110                         <i class="fa fa-plus"></i> Search for patrons</a></li>
111                     <li id="add_patrons_by_id"><a href="#">
112                         <span class="label">&nbsp;</span>
113                         <i class="fa fa-plus"></i> Add multiple patrons</a></li>
114                     <span id="patron_ids_line">
115                         <li><strong>Choose type of IDs to enter:</strong></li>
116                         <li class="radio">
117                             <label class="id_choice" for="add_by_cardnumbers">
118                                 <input id="add_by_cardnumbers" type="radio" name="id_column" value="cardnumbers" checked="checked">
119                                 <span class="add_by_cardnumbers">Cardnumbers</span>
120                             </label>
121                             <label class="id_choice" for="add_by_borrowernumbers">
122                                 <input id="add_by_borrwernumbers" type="radio" name="id_column" value="borrowernumbers">
123                                 <span class="add_by_borrowernumbers">Borrowernumbers</span>
124                             </label>
125                         </li>
126                         <li>
127                             <label for="patrons_by_id">List (one ID per line):</label>
128                             <textarea id="patrons_by_id" name="patrons_by_id" id="" cols="30" rows="10"></textarea>
129                         </li>
130                     </span>
131                 </ol>
132             </fieldset>
133             <fieldset id="patron_ids_submit" class="action">
134                 <input type="submit" class="btn btn-primary" value="Submit" />
135             </fieldset>
136
137             <div class="clearfix"></div>
138
139             <fieldset id="patrons_to_add_fieldset">
140                 <legend>Patrons to be added</legend>
141                 <div id="patrons_to_add"></div>
142
143                 <fieldset class="action">
144                     <input type="hidden" name="patron_list_id" value="[% list.patron_list_id | html %]" />
145                     <input type="submit" class="btn btn-primary" value="Add patrons" />
146                     <a href="lists.pl" class="cancel">Cancel</a>
147                 </fieldset>
148             </fieldset>
149         </form>
150
151         <form action="list.pl" id="remove_patrons" method="post">
152
153             <div class="searchheader" id="searchheader">
154                 <span class="checkall"><a id="CheckAll" href="#"><i class="fa fa-check"></i> Select all</a></span> |
155                 <span class="clearall"><a id="CheckNone" href="#"><i class="fa fa-times"></i> Clear all</a></span> |
156                 <div class="btn-group">
157                     <button class="btn btn-default btn-xs list-remove" type="submit"><i class="fa fa-trash-can"></i> Remove selected</button>
158                 </div>
159                 |
160                 <div class="btn-group">
161                     <button class="btn btn-default btn-xs merge-patrons"><i class="fa fa-compress"></i> Merge selected patrons</button>
162                 </div>
163             </div>
164
165             <div class="page-section">
166                 <table id="patron-list-table">
167                     <thead>
168                         <tr>
169                             <th class="NoSort">&nbsp;</th>
170                             <th>Card</th>
171                             <th>First name</th>
172                             <th>Surname</th>
173                             <th>Address</th>
174                             <th>Category</th>
175                             <th>Library</th>
176                             <th>Expires on</th>
177                             <th>Circ notes</th>
178                         </tr>
179                     </thead>
180
181                     <tbody>
182                         [% FOREACH p IN list.patron_list_patrons %]
183                             <tr>
184                                 <td>
185                                     <input type="checkbox" name="patrons_to_remove" class="selection" value="[% p.patron_list_patron_id | html %]" />
186                                     <input type="hidden" id="borrowernumber_[% p.patron_list_patron_id | html %]" value="[% p.borrowernumber.id | html %]" />
187                                 </td>
188                                 <td>
189                                     <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% p.borrowernumber.borrowernumber | uri %]">
190                                         [% p.borrowernumber.cardnumber | html %]
191                                     </a>
192                                 </td>
193                                 <td>[% p.borrowernumber.firstname | html %]</td>
194                                 <td>[% p.borrowernumber.surname | html %]</td>
195                                 <td>
196                                     [% p.borrowernumber.address | html %]
197                                     [% p.borrowernumber.address2 | html %]
198                                     [% p.borrowernumber.city | html %]
199                                     [% p.borrowernumber.state | html %]
200                                     [% p.borrowernumber.country | html %]
201                                 </td>
202                                 <td>[% p.borrowernumber.categorycode.description | html %] ([% p.borrowernumber.categorycode.categorycode | html %])</td>
203                                 <td>[% p.borrowernumber.branchcode.branchname | html %]</td>
204                                 <td data-order="[% p.borrowernumber.dateexpiry | html %]">[% p.borrowernumber.dateexpiry | $KohaDates %]</td>
205                                 <td>[% p.borrowernumber.borrowernotes | $raw | html_line_break %]</td>
206                             </tr>
207                         [% END %]
208                     </tbody>
209                 </table>
210             </div> <!-- /.page-section -->
211
212             <fieldset class="action">
213                 <input type="hidden" name="patron_list_id" value="[% list.patron_list_id | html %]" />
214                 <button type="submit" class="btn btn-default btn-sm list-remove"><i class="fa fa-trash-can" aria-hidden="true"></i> Remove selected patrons</button>
215                 <button class="btn btn-default btn-sm merge-patrons" type="submit"><i class="fa fa-compress"></i> Merge selected patrons</button>
216             </fieldset>
217         </form>
218
219             </main>
220         </div> <!-- /.col-sm-10.col-sm-push-2 -->
221
222         <div class="col-sm-2 col-sm-pull-10">
223             <aside>
224                 [% INCLUDE 'tools-menu.inc' %]
225             </aside>
226         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
227      </div> <!-- /.row -->
228
229 [% MACRO jsinclude BLOCK %]
230     [% Asset.js("js/tools-menu.js") | $raw %]
231     [% INCLUDE 'datatables.inc' %]
232
233     <script>
234         var MSG_REMOVE_PATRON = _("Remove");
235         $(document).ready(function() {
236             $('#patrons_to_add_fieldset').hide();
237
238                 var table_settings = [% TablesSettings.GetTableSettings('members', 'patron-lists', 'patron-list-table', 'json') | $raw %]
239                 KohaTable('patron-list-table', {
240                     "sPaginationType": "full"
241                 }, table_settings);
242
243             function AddPatron( patron_name, value, container, input_name ) {
244                 div = "<div id='borrower_" + value + "'>" + patron_name + " ( <a href='#' class='removePatron'><i class='fa fa-trash-can' aria-hidden='true'></i> " + MSG_REMOVE_PATRON + " </a> ) <input type='hidden' name='" + input_name + "' value='" + value + "' /></div>";
245                 $(container).append( div );
246
247                 $(container).parent().show( 800 );
248             }
249             function RemovePatron( cardnumber, container ) {
250                 $( '#borrower_' + cardnumber ).remove();
251
252                 if ( ! $(container).html() ) {
253                     $(container).parent("fieldset").hide( 800 );
254                 }
255             }
256             patron_autocomplete($("#find_patron"), {
257                 'on-select-callback': function( event, ui ) {
258                     var field = ui.item.cardnumber;
259                     AddPatron( ( ui.item.firstname || "" ) + " " + ( ui.item.middle_name || "" ) + " " + ( ui.item.surname || "" ), field, $("#patrons_to_add"), 'patrons_to_add' );
260                     $("#find_patron").val('').focus();
261                     return false;
262                 }
263             });
264             $("body").on("click",".removePatron",function(e){
265                 e.preventDefault();
266                 var divid = $(this).parent().attr("id");
267                 var cardnumber = divid.replace("borrower_","");
268                 RemovePatron(cardnumber, $("#patrons_to_add"));
269             });
270
271             $("body").on("click", "#CheckAll", function(e){
272                 e.preventDefault();
273                 $("input[type='checkbox']","#patron-list-table").each(function(){
274                     $(this).prop("checked",1);
275                 });
276             });
277             $("body").on("click", "#CheckNone", function(e){
278                 e.preventDefault();
279                 $("input[type='checkbox']","#patron-list-table").each(function(){
280                     $(this).prop("checked",0);
281                 });
282             });
283
284             $("#remove_patrons").submit(function(){
285                 var checkedItems = $("input:checked");
286                 if ($(checkedItems).size() == 0) {
287                     alert(_("You must select one or more patrons to remove"));
288                     return false;
289                 }
290                 $(checkedItems).parents('tr').addClass("warn");
291                 if( confirm(_("Are you sure you want to remove the selected patrons?")) ) {
292                     return true;
293                 } else {
294                     $(checkedItems).parents('tr').removeClass("warn");
295                     return false;
296                 }
297             });
298
299             $("#add_patrons_by_id a").on("click", function(){
300                 $("#add_patrons_by_id, #patron_search_line").hide();
301                 $("#add_patrons_by_search, #patron_ids_line, #patron_ids_submit").show();
302             });
303
304             $("#add_patrons_by_search a").on("click", function(){
305                 $("#add_patrons_by_id, #patron_search_line").show();
306                 $("#add_patrons_by_search, #patron_ids_line, #patron_ids_submit").hide();
307             });
308
309             $('.merge-patrons').on('click', function() {
310                 var checkedItems = $("input:checked");
311                 if ($(checkedItems).length < 2) {
312                     alert(_("You must select two or more patrons to merge"));
313                     return false;
314                 }
315                 $(checkedItems).parents('tr').addClass("warn");
316                 if (confirm(_("Are you sure you want to merge the selected patrons?"))) {
317                     var merge_patrons_url = '/cgi-bin/koha/members/merge-patrons.pl?' +
318                         $('.selection:checked')
319                         .map(function() {
320                             return "id=" + $( '#borrowernumber_' + $(this).val() ).val()
321                         }).get().join('&');
322
323                     window.location.href = merge_patrons_url;
324                     return false;
325                 } else {
326                     $(checkedItems).parents('tr').removeClass("warn");
327                     return false;
328                 }
329             });
330         });
331     </script>
332 [% END %]
333
334 [% INCLUDE 'intranet-bottom.inc' %]