Bug 14854: Add DataTables on upload results table
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / upload.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 [% USE Koha %]
3 [% IF plugin %]
4     <title>Upload plugin</title>
5 [% ELSE %]
6     <title>Koha &rsaquo; Tools &rsaquo; Upload</title>
7 [% END %]
8 [% INCLUDE 'doc-head-close.inc' %]
9 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" />
10
11 [% BLOCK plugin_pars %]
12     [% IF plugin %]
13         <input type="hidden" name="plugin" value="1" />
14         <input type="hidden" name="index" value="[% index %]" />
15     [% END %]
16 [% END %]
17
18 [% BLOCK breadcrumbs %]
19     <div id="breadcrumbs">
20         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
21         &rsaquo;
22         <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
23         &rsaquo;
24         <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
25         &rsaquo;
26         <span id="lastbreadcrumb">
27         [% IF mode=='new' || mode =='deleted'%]
28             Add new upload or search
29         [% ELSE %]
30             Results
31         [% END %]
32         </span>
33     </div>
34 [% END %]
35
36 [% BLOCK form_new %]
37     <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
38         [% PROCESS plugin_pars %]
39         <fieldset class="rows" id="uploadform">
40         <legend>Upload new files</legend>
41         <ol>
42         <li>
43         <div id="fileuploadform">
44             <label for="fileToUpload">Select files: </label>
45             <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
46         </div>
47         </li>
48         [% IF uploadcategories %]
49             <li>
50                 <label for="uploadcategory">Category: </label>
51                 <select id="uploadcategory" name="uploadcategory">
52                 [% IF !plugin %]
53                     <option value=""></option>
54                 [% END %]
55                 [% FOREACH cat IN uploadcategories %]
56                     <option value="[% cat.code %]">[% cat.name %]</option>
57                 [% END %]
58                 </select>
59             </li>
60         [% END %]
61         [% IF !plugin %]
62             <li>
63             [% IF uploadcategories %]
64                 <div class="hint">Note: For temporary uploads do not select a category.</div>
65             [% ELSE %]
66                 <div class="hint">Note: No upload categories are defined. Add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</div>
67             [% END %]
68             </li>
69         [% END %]
70         <li>
71             [% IF plugin %]
72                 <input type="hidden" id="public" name="public" value="1"/>
73             [% ELSE %]
74                 <label id="public_cb">Allow public downloads:</label>
75                 <input type="checkbox" id="public" name="public" />
76             [% END %]
77         </li>
78         </ol>
79         <fieldset class="action">
80             <button id="fileuploadbutton">Upload</button>
81             <button id="fileuploadcancel">Cancel</button>
82         </fieldset>
83         </fieldset>
84         <div id="fileuploadpanel">
85             <div id="fileuploadstatus" class="progress_panel">Upload progress:
86             <progress id="fileuploadprogress" max="100" value="0">
87             </progress>
88             <span class="fileuploadpercent">0</span>%
89             </div>
90             <div id="fileuploadfailed"></div>
91         </div>
92     </form>
93 [% END %]
94
95 [% BLOCK form_search %]
96     <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
97         [% PROCESS plugin_pars %]
98         <input type="hidden" name="op" value="search"/>
99         <fieldset class="rows">
100         <legend>Search uploads by name or hashvalue</legend>
101         <ol>
102         <li>
103             <label for="term">Search term: </label>
104             <input type="text" id="term" name="term" value=""/>
105         </li>
106         </ol>
107         <fieldset class="action">
108             <button id="searchbutton" class="submit">Search</button>
109         </fieldset>
110         </fieldset>
111     </form>
112 [% END %]
113
114 [% BLOCK submitter %]
115     <form id="submitter" style="display:none;" method="post">
116         [% PROCESS plugin_pars %]
117         <input type="hidden" name="op" id="op" value=""/>
118         <input type="hidden" name="id" id="id" value="" />
119         <input type="hidden" name="msg" id="msg" value="" />
120     </form>
121 [% END %]
122
123 [% BLOCK closer %]
124     [% IF plugin %]
125         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
126     [% END %]
127 [% END %]
128
129 [% BLOCK back %]
130     [% IF !plugin %]
131         <form id="back">
132             <fieldset class="action">
133                 <button class="submit">Back</button>
134             </fieldset>
135         </form>
136     [% END %]
137 [% END %]
138
139 [% BLOCK newsearch %]
140     <form id="newsearch">
141         <fieldset class="action">
142             <button id="new_search">New search</button>
143         </fieldset>
144     </form>
145     [% IF plugin %]
146         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
147     [% END %]
148 [% END %]
149
150 [% BLOCK table_results %]
151     <table id="uploadresults">
152     <thead>
153     <tr>
154         <th>Filename</th>
155         <th>Size</th>
156         <th>Hashvalue</th>
157         <th>Category</th>
158         [% IF !plugin %]<th>Public</th>[% END %]
159         [% IF !plugin %]<th>Temporary</th>[% END %]
160         <th class="nosort">Actions</th>
161     </tr>
162     </thead>
163     <tbody>
164     [% FOREACH record IN uploads %]
165     <tr>
166         <td>[% record.filename %]</td>
167         <td>[% record.filesize %]</td>
168         <td>[% record.hashvalue %]</td>
169         <td>[% record.uploadcategorycode %]</td>
170         [% IF !plugin %]
171             <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
172             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
173         [% END %]
174         <td class="actions">
175             [% IF plugin %]
176                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue %]"><i class="fa fa-plus"></i> Choose</button>
177             [% END %]
178             <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id %]"><i class="fa fa-download"></i> Download</button>
179             [% IF record.owner == owner || CAN_user_tools_upload_manage %]
180                 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id %]"><i class="fa fa-trash"></i> Delete</button>
181             [% END %]
182         </td>
183    </tr>
184    [% END %]
185    </tbody>
186    </table>
187 [% END %]
188
189 [% INCLUDE 'datatables.inc' %]
190 <style type="text/css">
191     #fileuploadstatus,#fileuploadfailed { display : none; }
192     #fileuploadstatus { margin:.4em; }
193     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }
194 </style>
195
196 <script type="text/javascript">
197 //<![CDATA[
198     var errMESSAGES = [
199         "Error 0: Not in use",
200         _("This file already exists (in this category)."),
201         _("File could not be created. Check permissions."),
202         _("Your koha-conf.xml does not contain a valid upload_path."),
203         _("No temporary directory found."),
204         _("File could not be read."),
205         _("File has been deleted."),
206         _("File or upload record could not be deleted."),
207     ];
208 //]]>
209 </script>
210 <script type="text/javascript" src="[% interface %]/[% theme %]/js/file-upload.js"></script>
211 <script type="text/javascript">
212 //<![CDATA[
213 function StartUpload() {
214     if( $('#fileToUpload').prop('files').length == 0 ) return;
215     $('#fileToUpload').prop('disabled',true);
216     $('#fileuploadbutton').hide();
217     $("#fileuploadcancel").show();
218     $("#fileuploadfailed").html('');
219     $("#myalerts").hide('');
220     $("#myalerts").html('');
221     $("#fileuploadstatus").show();
222     $("#uploadedfileid").val('');
223     $("#searchfile").hide();
224     $("#lastbreadcrumb").text( _("Add a new upload") );
225
226     var cat, xtra='';
227     if( $("#uploadcategory").val() )
228         cat = encodeURIComponent( $("#uploadcategory").val() );
229     if( cat ) xtra= 'category=' + cat + '&';
230     [% IF plugin %]
231         xtra = xtra + 'public=1&temp=0';
232     [% ELSE %]
233         if( !cat ) xtra = 'temp=1&';
234         if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
235     [% END %]
236     xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
237 }
238 function CancelUpload() {
239     if( xhr ) xhr.abort();
240     $("#fileuploadstatus").hide();
241     $('#fileToUpload').prop('disabled', false);
242     $('#fileuploadbutton').show();
243     $("#fileuploadcancel").hide();
244     $("#fileuploadfailed").show();
245     $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
246 }
247 function cbUpload( status, fileid, err ) {
248     $('#fileToUpload').prop('disabled', false);
249     if( status=='done' ) {
250         var e = err? JSON.stringify(err): '';
251         SubmitMe( 'search', fileid, e );
252     } else {
253         $('#fileuploadbutton').show();
254         $("#fileuploadcancel").hide();
255         $("#fileuploadstatus").hide();
256         $("#fileuploadfailed").show();
257         $("#fileuploadfailed").html( _("Upload status: ") +
258             ( status=='failed'? _("Failed"):
259             ( status=='denied'? _("Denied"): status ))
260         );
261         ShowAlerts( err );
262     }
263 }
264 function ShowAlerts(err) {
265     var str = '';
266     for( var file in err ) {
267         str= str + '<p>' + file + ': ' +
268             errMESSAGES[ err[file] ] + '</p>';
269     }
270     if( str ) {
271         $('#myalerts').html(str);
272         $('#myalerts').show();
273     }
274 }
275 function CheckSearch() {
276     if( $("#term").val()=="" ) {
277         alert( _("Please enter a search term.") );
278         return false;
279     }
280     return true;
281 }
282 function SubmitMe(op, id, msg ) {
283     $("#submitter #op").val( op );
284     $("#submitter #id").val( id );
285     $("#submitter #msg").val( msg );
286     $("#submitter").submit();
287 }
288 function DeleteEntry(id) {
289     if( !confirm( _("Do you really want to delete this upload?") ))
290         return false;
291     ClearField();
292     SubmitMe( 'delete', id );
293 }
294 function ClearField() {
295     [% IF plugin %]
296         $(window.opener.document).find('#[% index %]').val( '' );
297     [% END %]
298 }
299 function Choose(hashval) {
300     var res = '[% Koha.Preference('OPACBaseURL') %]';
301     res = res.replace( /\/$/, '');
302     res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
303     [% IF index %]
304         $(window.opener.document).find('#[% index %]').val( res );
305     [% END %]
306     window.close();
307 }
308 $(document).ready(function() {
309     $("#uploadresults").dataTable($.extend(true, {}, dataTablesDefaults, {
310         "aoColumnDefs": [
311             { 'bSortable': false, 'aTargets': [ 'nosort' ] }
312         ],
313         "sPaginationType": "four_button"
314     }));
315     [% IF msg %]
316         ShowAlerts( [% msg %] );
317     [% END %]
318     $("#fileuploadcancel").hide();
319     $("#public_cb").click(function() {
320         $("#public").click();
321     });
322     $("#fileuploadbutton").on("click",function(e){
323         e.preventDefault();
324         StartUpload();
325     });
326     $("#fileuploadcancel").on("click",function(e){
327         e.preventDefault();
328         CancelUpload();
329     });
330     $("#searchbutton").on("click",function(){
331         return CheckSearch();
332     });
333     $(".choose_entry").on("click",function(e){
334         e.preventDefault();
335         var record_hashvalue = $(this).data("record-hashvalue");
336         Choose( record_hashvalue );
337     });
338     $(".download_entry").on("click",function(e){
339         e.preventDefault();
340         var record_id = $(this).data("record-id");
341         SubmitMe( 'download', record_id );
342     });
343     $(".delete_entry").on("click",function(e){
344         e.preventDefault();
345         var record_id = $(this).data("record-id");
346         DeleteEntry( record_id );
347     });
348     $("#new_search").on("click",function(e){
349         e.preventDefault();
350         SubmitMe('new');
351     });
352 });
353 //]]>
354 </script>
355 </head>
356
357 [% IF ( plugin ) %]
358     <body id="tools_upload" class="tools">
359         <div class="yui-t7">
360             <div id="bd">
361                 <div class="yui-g">
362 [% ELSE %]
363     <body id="tools_upload" class="tools">
364     [% INCLUDE 'header.inc' %]
365     [% INCLUDE 'cat-search.inc' %]
366     [% PROCESS breadcrumbs %]
367     <div id="doc3" class="yui-t2">
368         <div id="bd">
369             <div id="yui-main">
370                 <div class="yui-b">
371 [% END %]
372
373
374
375 <h1>Upload</h1>
376 <div class="dialog alert" id="myalerts" style="display:none;"></div>
377
378 [% PROCESS submitter %]
379 [% IF mode == 'new' || mode == 'deleted' %]
380     [% PROCESS form_new %]
381     [% PROCESS form_search %]
382     [% PROCESS closer %]
383 [% ELSIF mode == 'report' %]
384     [% IF uploads %]
385         <h3>Your request gave the following results:</h3>
386         [% PROCESS table_results %]
387         [% PROCESS closer %]
388         [% PROCESS back %]
389     [% ELSE %]
390         <h4>Sorry, your request had no results.</h4>
391         [% PROCESS newsearch %]
392     [% END %]
393 [% END %]
394
395 </div>
396
397 [% IF !plugin %]
398 </div>
399     <div class="yui-b noprint">
400         [% INCLUDE 'tools-menu.inc' %]
401     </div>
402 [% END %]
403
404 </div>
405 [% INCLUDE 'intranet-bottom.inc' %]