Bug 9483 - Use DataTables on batch patron modifications page
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / modborrowers.tt
1 [% USE KohaDates %]
2 [% INCLUDE 'doc-head-open.inc'%]
3 <title>Koha &rsaquo; Tools &rsaquo; Batch patron modification</title>
4 [% INCLUDE 'doc-head-close.inc' %]
5 [% INCLUDE 'calendar.inc' %]
6 <link rel="stylesheet" type="text/css" href="/intranet-tmpl/prog/en/css/datatables.css" />
7 <script type="text/javascript" src="/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.dataTables.min.js"></script>
8 [% INCLUDE 'datatables-strings.inc' %]
9 <script type="text/javascript" src="/intranet-tmpl/prog/en/js/datatables.js"></script>
10 <script type="text/javascript">
11 //<![CDATA[
12     [% IF (dateformat == 'metric') %]dt_add_type_uk_date();[% END %]
13         var patron_attributes_lib = new Array();
14         var patron_attributes_values = new Array();
15         $(document).ready(function() {
16             [% IF borrowers %]
17                 $("#borrowerst").dataTable($.extend(true, {}, dataTablesDefaults, {
18                     "sDom": 't',
19                     "aoColumnDefs": [
20                         { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }
21                     ],
22                     "bPaginate": false
23                 }));
24                 $("#selectallbutton").click(function() {
25                     $("#borrowerst").find("input:checkbox").each(function() {
26                         $(this).attr("checked", true);
27                     });
28                     return false;
29                 });
30                 $("#clearallbutton").click(function() {
31                     $("#borrowerst").find("input:checkbox").each(function() {
32                         $(this).attr("checked", false);
33                     });
34                     return false;
35                 });
36             [% END %]
37
38             var values = new Array();
39             var lib = new Array();
40             [% FOREACH pav IN patron_attributes_values %]
41                 values = new Array();
42                 lib = new Array();
43                 [% FOREACH option IN pav.options %]
44                     values.push("[% option.lib %]");
45                     lib.push("[% option.authorised_value %]");
46                 [% END %]
47                 patron_attributes_lib["[% pav.attribute_code %]"] = values;
48                 patron_attributes_values["[% pav.attribute_code %]"] = lib;
49             [% END %]
50
51             $('select[name="patron_attributes"]').change(function() {
52                 updateAttrValues(this);
53             } );
54
55             $('select[name="patron_attributes"]').change();
56
57         } );
58
59         function updateAttrValues (select_attr) {
60             var attr_code = $(select_attr).val();
61             var type = $(select_attr).find("option:selected").attr('data-type');
62             var category = $(select_attr).find("option:selected").attr('data-category');
63             var span = $(select_attr).parent().parent().find('span.patron_attributes_value');
64             var information_category_node = $(select_attr).parent().parent().find('span.information_category');
65             information_category_node.html("");
66             if ( category.length > 0 ) {
67                 information_category_node.html(_("This attribute will be only applied to the patron\'s category") +' "' + category + '"');
68             }
69             if ( type == 'select' ) {
70                 var options = '<option value = ""></option>';
71                 for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
72                     options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
73                 }
74                 span.html('<select name="patron_attributes_value">' + options + '</select>');
75             } else {
76                 span.html('<input type="text" name="patron_attributes_value"/>')
77             }
78         }
79
80         function add_attributes() {
81             var li_node = $("li.attributes:last");
82             var li_clone = $(li_node).clone();
83             if ( $(li_clone).find("a.delete").length == 0 ) {
84                 $(li_clone).append('<a href="#" title="Delete" class="delete clear-field" onclick="del_attributes(this);return false;">Delete</a>');
85             }
86             $(li_clone).find('select[name="patron_attributes"]').change(function() {
87                 updateAttrValues(this);
88             } );
89
90             $(li_clone).find('select[name="patron_attributes"]').change();
91
92             $("#fields_list>ol").append(li_clone);
93             update_attr_values();
94         }
95
96         function del_attributes(a_node) {
97             $(a_node).parent('li').remove();
98             update_attr_values();
99         }
100
101         function update_attr_values() {
102             $("li.attributes").each(function(i) {
103                 $(this).find("input:checkbox").val("attr"+i+"_value");
104             });
105         }
106         function clearDate(nodeid) {
107             $("#"+nodeid).val("");
108         }
109
110 //]]>
111 </script>
112 </head>
113 <body>
114 [% INCLUDE 'header.inc' %]
115 [% INCLUDE 'cat-search.inc' %]
116
117 <div id="breadcrumbs">
118     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
119     <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
120     <a href="/cgi-bin/koha/tools/modborrowers.pl">Batch patron modification</a>
121 </div>
122
123 <div id="doc3" class="yui-t2">
124     <div id="bd">
125         <div id="yui-main">
126             <div class="yui-b">
127                 [% IF ( op == 'show_form' ) %]
128                 <h1>Batch patron modification</h1>
129                 <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/modborrowers.pl">
130                     <fieldset class="rows">
131                     <legend>Use a file</legend>
132                     <ol>
133                     <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
134                     </ol>
135                     </fieldset>
136                     <fieldset class="rows">
137                         <legend>Or list cardnumbers one by one</legend>
138                         <ol>
139                             <li>
140                               <label for="cardnumberlist">Card number list (one cardnumber per line): </label>
141                               <textarea rows="10" cols="30" id="cardnumberlist" name="cardnumberlist">[% cardnumberlist %]</textarea>
142                             </li>
143                         </ol>
144                     </fieldset>
145                     <input type="hidden" name="op" value="show" />
146                     <fieldset class="action">
147                         <input type="submit" value="Continue" class="button" />
148                         <a class="cancel" href="/cgi-bin/koha/tools/tools-home.pl">Cancel</a>
149                     </fieldset>
150                 </form>
151                 [% END %]
152
153                 [% IF ( op == 'show' or op == 'show_results' ) %]
154                     [% IF ( op == 'show' ) %]
155                         <h1>Batch patrons modification</h1>
156                     [% ELSE %]
157                         <h1>Batch patrons results</h1>
158                     [% END %]
159                     [% IF ( notfoundcardnumbers ) %]
160                         <div class="dialog alert"><p>Warning, the following cardnumbers were not found:</p></div>
161                         <table style="margin:auto;">
162                             <thead>
163                                 <tr><th>Cardnumbers not found</th></tr>
164                             </thead>
165                             <tbody>
166                                 [% FOREACH notfoundcardnumber IN notfoundcardnumbers %]
167                                     <tr><td>[% notfoundcardnumber.cardnumber %]</td></tr>
168                                 [% END %]
169                             </tbody>
170                         </table>
171                     [% END %]
172
173                     [% IF ( op == 'show_results' ) %]
174                         [% IF ( errors ) %]
175                             <div class="dialog alert">
176                             <h4>Errors occured:</h4>
177                             <ul class="warnings">
178                             [% FOREACH error IN errors %]
179                                 [% IF ( error.error == 'can_not_update' ) %]
180                                     <li>Can not update patron with borrowernumber [% error.borrowernumber %]</li>
181                                 [% ELSE %]
182                                     <li>[% error.error %]</li>
183                                 [% END %]
184                             [% END %]
185                             </ul>
186                             </div>
187                         [% END %]
188                     [% END %]
189
190                     [% IF ( op == 'show' ) %]
191                     <form name="f" action="modborrowers.pl" method="post">
192                         <input type="hidden" name="op" value="do" />
193                         [% IF ( borrowers ) %]
194                             <div id="toolbar"><a id="selectallbutton" href="#">Select All</a> | <a id="clearallbutton" href="#">Clear All</a></div>
195                         [% END %]
196                     [% END %]
197                         [% IF borrowers %]
198                             <div id="cataloguing_additem_itemlist">
199                                 <div style="overflow:auto">
200                                     <table id="borrowerst">
201                                         <thead>
202                                             <tr>
203                                                 [% IF ( op == 'show' ) %]
204                                                     <th>&nbsp;</th>
205                                                 [% END %]
206                                                 <th>Card number</th>
207                                                 <th>Surname</th>
208                                                 <th>Firstname</th>
209                                                 <th>Library</th>
210                                                 <th>Category</th>
211                                                 <th>Registration date</th>
212                                                 <th>Expiry date</th>
213                                                 <th>Restricted</th>
214                                                 [% FOREACH attrh IN attributes_header %]
215                                                     <th>[% attrh.attribute %]</th>
216                                                 [% END %]
217                                             </tr>
218                                         </thead>
219                                         <tbody>
220                                             [% FOREACH borrower IN borrowers %]
221                                                 <tr>
222                                                     [% IF ( op == 'show' ) %]
223                                                         <td><input type="checkbox" name="borrowernumber" value="[% borrower.borrowernumber %]" checked="checked" /></td>
224                                                     [% END %]
225                                                     <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">[% borrower.cardnumber %]</a></td>
226                                                     <td>[% borrower.surname %]</td>
227                                                     <td>[% borrower.firstname %]</td>
228                                                     <td>[% borrower.branchname %]</td>
229                                                     <td>[% borrower.categorycode %]</td>
230                                                     <td>[% borrower.dateenrolled | $KohaDates %]</td>
231                                                     <td>[% borrower.dateexpiry | $KohaDates %]</td>
232                                                     <td>[% borrower.debarred | $KohaDates %]</td>
233                                                     [% FOREACH pa IN borrower.patron_attributes %]
234                                                         [% IF ( pa.code ) %]
235                                                             <td>[% pa.code %]=[% pa.value %]</td>
236                                                         [% ELSE %]
237                                                             <td></td>
238                                                         [% END %]
239                                                     [% END %]
240                                                 </tr>
241                                             [% END %]
242                                         </tbody>
243                                     </table>
244                                 </div>
245                             </div>
246
247                             [% IF ( op == 'show' ) %]
248                             <div id="cataloguing_additem_newitem">
249                                 <h2>Edit Patrons</h2>
250                                 <div class="hint">Checking the box right next the label will disable the entry and delete the values of that field on all selected patrons</div>
251                                 <fieldset class="rows" id="fields_list">
252                                     <ol>
253                                         [% FOREACH field IN fields %]
254                                         <li>
255                                             [% IF ( field.mandatory ) %]
256                                             <label for="[% field.name %]" class="required">
257                                             [% ELSE %]
258                                             <label for="[% field.name %]">
259                                             [% END %]
260                                             [% SWITCH ( field.name ) %]
261                                                 [% CASE 'surname' %]
262                                                 Surname:
263                                                 [% CASE 'firstname' %]
264                                                 First name:
265                                                 [% CASE 'branchcode' %]
266                                                 Library:
267                                                 [% CASE 'categorycode' %]
268                                                 Category
269                                                 [% CASE 'sort1' %]
270                                                 Sort 1:
271                                                 [% CASE 'sort2' %]
272                                                 Sort 2:
273                                                 [% CASE 'dateenrolled' %]
274                                                 Registration date:
275                                                 [% CASE 'dateexpiry' %]
276                                                 Expiry date:
277                                                 [% CASE 'debarred' %]
278                                                 Restricted:
279                                                 [% CASE 'debarredcomment' %]
280                                                 Restriction comment:
281                                                 [% CASE 'borrowernotes' %]
282                                                 Circulation note:
283                                             [% END %]
284                                             </label>
285                                             [% IF field.mandatory %]
286                                                 <input type="checkbox" title="This field is mandatory" name="disable_input" value="[% field.name %]" readonly="readonly" onclick="return false;" />
287                                             [% ELSE %]
288                                                 <input type="checkbox" title="Check to delete this field" name="disable_input" value="[% field.name %]" />
289                                             [% END %]
290                                             [% IF ( field.type == 'text' ) %]
291                                                 <input type="text" name="[% field.name %]" value="" />
292                                             [% END %]
293                                             [% IF ( field.type == 'select' ) %]
294                                                 [% IF field.option.size %]
295                                                     <select name="[% field.name %]" >
296                                                         [% FOREACH opt IN field.option %]
297                                                             <option value="[% opt.value %]">[% opt.lib %]</option>
298                                                         [% END %]
299                                                     </select>
300                                                 [% ELSE %]
301                                                     There is no value defined for [% field.name %]
302                                                 [% END %]
303                                             [% END %]
304                                             [% IF ( field.type == 'date' ) %]
305                                                 <input type="text" name="[% field.name %]" id="[% field.name %]" value="" size="10" maxlength="10" readonly="readonly" class="datepicker" />
306                                                 <a href="#" class="clear-field" onclick="clearDate('[% field.name %]');return false;">Clear</a>
307                                                 [% END %]
308                                         </li>
309                                         [% END %]
310                                         [% IF ( patron_attributes_codes ) %]
311                                             <li class="attributes">
312                                                 <label style="width:auto;">Attribute:
313                                                     <select name="patron_attributes">
314                                                         [% FOREACH pac IN patron_attributes_codes %]
315                                                             <option value="[% pac.attribute_code %]" data-type="[% pac.type %]" data-category="[% pac.category_lib %]">[% pac.attribute_lib %]</option>
316                                                         [% END %]
317                                                     </select>
318                                                 </label>
319                                                 <input type="checkbox" title="check to delete this field" name="disable_input" value="attr0_value" />
320                                                 <span class="patron_attributes_value"></span>
321                                                 <a href="#" class="clone-field" title="Add an attribute" onclick="add_attributes(); return false;">New</a>
322                                                 <span class="information_category hint" style="width:25%;float:right;"></span>
323                                             </li>
324                                         [% END %]
325                                     </ol>
326                                 </fieldset>
327                                 <fieldset class="action">
328                                     <input type="submit" name="mainformsubmit" value="Save" />
329                                     <a href="/cgi-bin/koha/tools/modborrowers.pl" class="cancel">Cancel</a>
330                                 </fieldset>
331                             </div>
332                         </form>
333                         [% END %]
334                     [% END %]
335                 [% END %]
336                 [% IF ( op == 'show_results' ) %]
337                 <p>
338                     <a href="/cgi-bin/koha/tools/modborrowers.pl" title="New batch patrons modification">New batch patron modification</a>
339                 </p>
340                 [% END %]
341             </div>
342             </div>
343             <div class="yui-b">
344                 [% INCLUDE 'tools-menu.inc' %]
345             </div>
346         </div>
347     </div>
348 </div>
349 </body>
350 </html>