Bug 30993: Improve translatabilty of UPLOAD av hint
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / upload.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE TablesSettings %]
6 [% USE AuthorisedValues %]
7 [%- USE KohaSpan -%]
8 [% SET footerjs = 1 %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 [% IF plugin %]
11     <title>Upload plugin</title>
12 [% ELSE %]
13     <title>Upload &rsaquo; Tools &rsaquo; Koha</title>
14 [% END %]
15 [% INCLUDE 'doc-head-close.inc' %]
16
17 [% BLOCK plugin_pars %]
18     [% IF plugin %]
19         <input type="hidden" name="plugin" value="1" />
20         <input type="hidden" name="index" value="[% index | html %]" />
21     [% END %]
22 [% END %]
23
24 [% BLOCK breadcrumbs %]
25     [% WRAPPER 'sub-header.inc' %]
26     <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
27         <ol>
28             <li>
29                 <a href="/cgi-bin/koha/mainpage.pl">Home</a>
30             </li>
31             <li>
32                 <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
33             </li>
34             <li>
35                 <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
36             </li>
37             <li>
38                 <a href="#" aria-current="page">
39                     [% IF mode=='new' || mode =='deleted'%]
40                         Add new upload or search
41                     [% ELSE %]
42                         Results
43                     [% END %]
44                 </a>
45             </li>
46         </ol>
47     </nav>
48     [% END %]
49 [% END %]
50
51 [% BLOCK form_new %]
52     <form method="post" action="/cgi-bin/koha/tools/upload.pl" id="uploadfile" enctype="multipart/form-data">
53         [% PROCESS plugin_pars %]
54         <fieldset class="rows" id="uploadform">
55         <legend>Upload new files</legend>
56         <ol>
57         <li>
58         <div id="fileuploadform">
59             <label for="fileToUpload">Select files: </label>
60             <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
61         </div>
62         </li>
63         [% IF uploadcategories %]
64             <li>
65                 <label for="uploadcategory">Category: </label>
66                 <select id="uploadcategory" name="uploadcategory">
67                 [% IF !plugin %]
68                     <option value=""></option>
69                 [% END %]
70                 [% FOREACH cat IN uploadcategories %]
71                     <option value="[% cat.code | html %]">[% cat.name | html %]</option>
72                 [% END %]
73                 </select>
74             </li>
75         [% END %]
76         [% IF !plugin %]
77             <li>
78             [% IF uploadcategories %]
79                 <div class="hint">Note: For temporary uploads do not select a category.</div>
80             [% ELSE %]
81                 <div class="hint">
82                     Note: No upload categories are defined.
83                     [% IF ( CAN_user_parameters_manage_auth_values ) -%]
84                         [% av_UPLOAD_link = BLOCK %]<a href='/cgi-bin/koha/admin/authorised_values.pl?searchfield=UPLOAD'>UPLOAD</a>[% END %]
85                         <span>Add values to the [% av_UPLOAD_link | $KohaSpan %] authorized value category otherwise all uploads will be marked as temporary.</span>
86                     [% ELSE -%]
87                         <span>An administrator must add values to the UPLOAD authorized value category otherwise all uploads will be marked as temporary.</span>
88                     [% END %]
89                 </div>
90             [% END %]
91             </li>
92         [% END %]
93         <li>
94             [% IF plugin %]
95                 <input type="hidden" id="public" name="public" value="1"/>
96             [% ELSE %]
97                 <label id="public_cb">Allow public downloads:</label>
98                 <input type="checkbox" id="public" name="public" />
99             [% END %]
100         </li>
101         </ol>
102         <fieldset class="action">
103             <button id="fileuploadbutton" class="btn btn-primary">Upload</button>
104             <button id="fileuploadcancel">Cancel</button>
105         </fieldset>
106         </fieldset>
107         <div id="fileuploadpanel">
108             <div id="fileuploadstatus" class="progress_panel">Upload progress:
109             <progress id="fileuploadprogress" max="100" value="0">
110             </progress>
111             <span class="fileuploadpercent">0</span>%
112             </div>
113             <div id="fileuploadfailed"></div>
114         </div>
115     </form>
116 [% END %]
117
118 [% BLOCK form_browse %]
119     [% IF uploadcategories %]
120     <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl">
121         [% PROCESS plugin_pars %]
122         <input type="hidden" name="op" value="browse"/>
123         <fieldset class="brief">
124         <h4>Search uploads by category</h4>
125         <ol>
126             <li>
127                 <label for="browsecategory">Category: </label>
128                 <select id="browsecategory" name="browsecategory" required="required">
129                     <option value="">Choose</option>
130                     [% FOREACH cat IN uploadcategories %]
131                         [% IF cat.code == browsecategory %]
132                             <option value="[% cat.code | html %]" selected="selected">[% cat.name | html %]</option>
133                         [% ELSE -%]
134                             <option value="[% cat.code | html %]">[% cat.name | html %]</option>
135                         [% END %]
136                     [% END %]
137                 </select>
138             </li>
139         </ol>
140         <fieldset class="action">
141             <button id="browsebutton" class="btn btn-primary">Search</button>
142         </fieldset>
143         </fieldset>
144     </form>
145     [% END %]
146 [% END %]
147
148 [% BLOCK form_search %]
149     <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl">
150         [% PROCESS plugin_pars %]
151         <input type="hidden" name="op" value="search"/>
152         <fieldset class="brief">
153         <h4>Search uploads by name or hashvalue</h4>
154         <ol>
155         <li>
156             <label for="term">Search term: </label>
157             <input type="text" id="term" name="term" value=""/>
158         </li>
159         </ol>
160         <fieldset class="action">
161             <button id="searchbutton" class="btn btn-primary">Search</button>
162         </fieldset>
163         </fieldset>
164     </form>
165 [% END %]
166
167 [% BLOCK submitter %]
168     <form id="submitter" style="display:none;" method="post">
169         [% PROCESS plugin_pars %]
170         <input type="hidden" name="op" id="op" value=""/>
171         <input type="hidden" name="id" id="id" value="" />
172         <input type="hidden" name="msg" id="msg" value="" />
173     </form>
174 [% END %]
175
176 [% BLOCK closer %]
177     [% IF plugin %]
178         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
179     [% END %]
180 [% END %]
181
182 [% BLOCK back %]
183     [% IF !plugin %]
184         <form id="back">
185             <fieldset class="action">
186                 <button class="submit">Back</button>
187             </fieldset>
188         </form>
189     [% END %]
190 [% END %]
191
192 [% BLOCK newsearch %]
193     <form id="newsearch">
194         <fieldset class="action">
195             <button id="new_search">New search</button>
196         </fieldset>
197     </form>
198     [% IF plugin %]
199         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
200     [% END %]
201 [% END %]
202
203 [% BLOCK table_results %]
204     <div class="page-section">
205         <table id="uploadresults">
206             <thead>
207                 <tr>
208                     <th>Filename</th>
209                     <th>Size</th>
210                     <th>Hashvalue</th>
211                     <th>Date added</th>
212                     <th>Category</th>
213                     [% IF !plugin %]<th>Public</th>[% END %]
214                     [% IF !plugin %]<th>Temporary</th>[% END %]
215                     <th class="NoSort noExport">Actions</th>
216                 </tr>
217             </thead>
218             <tbody>
219                 [% FOREACH record IN uploads %]
220                     <tr>
221                         <td>[% record.filename | html %]</td>
222                         <td>[% record.filesize | html %]</td>
223                         <td>[% record.hashvalue | html %]</td>
224                         <td data-order="[% record.dtcreated | html %]">[% record.dtcreated | $KohaDates with_hours = 1 %]</td>
225                         <td>
226                             <a href="/cgi-bin/koha/tools/upload.pl?op=browse&browsecategory=[% record.uploadcategorycode | uri %]">[% AuthorisedValues.GetByCode( 'UPLOAD', record.uploadcategorycode ) | html %]</a>
227                         </td>
228                         [% IF !plugin %]
229                             <td>
230                                 [% IF record.public %]
231                                     <a href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-retrieve-file.pl?id=[% record.hashvalue | uri %]" class="get-file" data-toggle="tooltip"><i class="fa fa-link" aria-hidden="true"></i> Yes</a>
232                                 [% ELSE %]
233                                     No
234                                 [% END %]
235                             </td>
236                             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
237                         [% END %]
238                         <td class="actions">
239                             [% IF plugin %]
240                                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
241                             [% END %]
242                             <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
243                             [% IF record.owner == owner || CAN_user_tools_upload_manage %]
244                                 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
245                             [% END %]
246                         </td>
247                     </tr>
248                 [% END %]
249             </tbody>
250         </table>
251     </div> <!-- /.page-section -->
252 [% END %]
253
254 <style>
255     #fileuploadstatus,#fileuploadfailed { display : none; }
256     #fileuploadstatus { margin:.4em; }
257     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
258 </style>
259
260
261 </head>
262
263 [% IF ( plugin ) %]
264     <body id="tools_upload" class="tools">
265         <div class="main container-fluid">
266             <div class="row">
267                 <div class="col-sm-12">
268                     <main>
269 [% ELSE %]
270     <body id="tools_upload" class="tools">
271     [% INCLUDE 'header.inc' %]
272     [% INCLUDE 'cat-search.inc' %]
273     [% PROCESS breadcrumbs %]
274
275     <div class="main container-fluid">
276         <div class="row">
277             <div class="col-sm-10 col-sm-push-2">
278                 <main>
279 [% END %]
280
281 <h1>Upload</h1>
282 <div class="dialog alert" id="myalerts" style="display:none;"></div>
283
284 [% PROCESS submitter %]
285 [% IF mode == 'new' || mode == 'deleted' %]
286     [% PROCESS form_new %]
287     <div class="row">
288         [% IF uploadcategories %]
289             <div class="col-xs-6">
290                 [% PROCESS form_browse %]
291             </div>
292             <div class="col-xs-6">
293         [% ELSE %]
294             <div class="col-xs-12">
295         [% END %]
296             [% PROCESS form_search %]
297         </div>
298     </div>
299     [% PROCESS closer %]
300 [% ELSIF mode == 'report' %]
301     <div id="toolbar" class="btn-toolbar">
302         <a href="/cgi-bin/koha/tools/upload.pl" class="btn btn-default">Upload file</a>
303     </div>
304     [% IF uploads %]
305         <h3>Your request gave the following results:</h3>
306         [% PROCESS table_results %]
307         [% PROCESS closer %]
308         [% PROCESS back %]
309     [% ELSE %]
310         <h4>Sorry, your request had no results.</h4>
311         [% PROCESS newsearch %]
312     [% END %]
313 [% END %]
314
315 [% IF !plugin %]
316             </main>
317         </div> <!-- /.col-sm-10.col-sm-push-2 -->
318
319         <div class="col-sm-2 col-sm-pull-10">
320             <aside>
321                 [% IF mode == 'report' %]
322                     [% PROCESS form_browse %]
323                     [% PROCESS form_search %]
324                 [% END %]
325
326
327                 [% INCLUDE 'tools-menu.inc' %]
328             </aside>
329         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
330      </div> <!-- /.row -->
331 [% ELSE %]
332             </main>
333         </div> <!-- .col-sm-12 -->
334      </div> <!-- /.row -->
335 [% END %]
336
337
338 [% MACRO jsinclude BLOCK %]
339     [% Asset.js("js/tools-menu.js") | $raw %]
340     [% INCLUDE 'datatables.inc' %]
341     [% Asset.js("js/file-upload.js") | $raw %]
342     [% INCLUDE 'columns_settings.inc' %]
343     <script>
344         function StartUpload() {
345             if( $('#fileToUpload').prop('files').length == 0 ) return;
346             $('#fileToUpload').prop('disabled',true);
347             $('#fileuploadbutton').hide();
348             $("#fileuploadcancel").show();
349             $("#fileuploadfailed").html('');
350             $("#myalerts").hide('');
351             $("#myalerts").html('');
352             $("#fileuploadstatus").show();
353             $("#uploadedfileid").val('');
354             $("#searchfile").hide();
355             $("#lastbreadcrumb").text( _("Add a new upload") );
356
357             var cat, xtra='';
358             if( $("#uploadcategory").val() )
359                 cat = encodeURIComponent( $("#uploadcategory").val() );
360             if( cat ) xtra= 'category=' + cat + '&';
361             [% IF plugin %]
362                 xtra = xtra + 'public=1&temp=0';
363             [% ELSE %]
364                 if( !cat ) xtra = 'temp=1&';
365                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
366             [% END %]
367             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
368         }
369         function CancelUpload() {
370             if( xhr ) xhr.abort();
371             $("#fileuploadstatus").hide();
372             $('#fileToUpload').prop('disabled', false);
373             $('#fileuploadbutton').show();
374             $("#fileuploadcancel").hide();
375             $("#fileuploadfailed").show();
376             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
377         }
378         function cbUpload( status, fileid, err ) {
379             $('#fileToUpload').prop('disabled', false);
380             if( status=='done' ) {
381                 var e = err? JSON.stringify(err): '';
382                 SubmitMe( 'search', fileid, e );
383             } else {
384                 $('#fileuploadbutton').show();
385                 $("#fileuploadcancel").hide();
386                 $("#fileuploadstatus").hide();
387                 $("#fileuploadfailed").show();
388                 $("#fileuploadfailed").html( _("Upload status: ") +
389                     ( status=='failed'? _("Failed"):
390                     ( status=='denied'? _("Denied"): status ))
391                 );
392                 ShowAlerts( err );
393             }
394         }
395         function ShowAlerts(err) {
396             var str = '';
397             for( var file in err ) {
398                 str= str + '<p>' + file + ': ' +
399                     errMESSAGES( err[file].code ) + '</p>';
400             }
401             if( str ) {
402                 $('#myalerts').html(str);
403                 $('#myalerts').show();
404             }
405         }
406         function errMESSAGES(code) {
407             var rv;
408             switch(code) {
409                 case 'UPLERR_ALREADY_EXISTS':
410                     rv = _("This file already exists (in this category).");
411                     break;
412                 case 'UPLERR_CANNOT_WRITE':
413                     rv = _("File could not be created. Check permissions.");
414                     break;
415                 case 'UPLERR_NO_ROOT_DIR':
416                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
417                     break;
418                 case 'UPLERR_NO_TEMP_DIR':
419                     rv = _("No temporary directory found.");
420                     break;
421                 case 'UPLERR_FILE_NOT_READ':
422                     rv = _("File could not be read.");
423                     break;
424                 case 'UPL_FILE_DELETED': // An alert, no error
425                     rv = _("File has been deleted.");
426                     break;
427                 case 'UPLERR_FILE_NOT_DELETED':
428                     rv = _("File or upload record could not be deleted.");
429                     break;
430                 default:
431                     rv = code;
432             }
433             return rv;
434         }
435         function CheckSearch() {
436             if( $("#term").val()=="" ) {
437                 alert( _("Please enter a search term.") );
438                 return false;
439             }
440             return true;
441         }
442         function SubmitMe(op, id, msg ) {
443             $("#submitter #op").val( op );
444             $("#submitter #id").val( id );
445             $("#submitter #msg").val( msg );
446             $("#submitter").submit();
447         }
448         function DeleteEntry(id) {
449             if( !confirm( _("Do you really want to delete this upload?") ))
450                 return false;
451             ClearField();
452             SubmitMe( 'delete', id );
453         }
454         function ClearField() {
455             [% IF plugin %]
456                 $(window.opener.document).find('#[% index | html %]').val( '' );
457             [% END %]
458         }
459         function Choose(hashval) {
460             var res = '[% Koha.Preference('OPACBaseURL') | html %]';
461             res = res.replace( /\/$/, '');
462             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
463             [% IF index %]
464                 $(window.opener.document).find('#[% index | html %]').val( res );
465             [% END %]
466             window.close();
467         }
468         var table_settings = [% TablesSettings.GetTableSettings( 'tools', 'upload', 'uploadresults', 'json' ) | $raw %];
469         [% IF plugin %]
470             table_settings['columns'].splice(6, 1);
471             table_settings['columns'].splice(5, 1);
472         [% END %]
473         $(document).ready(function() {
474             KohaTable("uploadresults",{
475             }, table_settings);
476
477             [% IF msg %]
478                 ShowAlerts( [% msg | html %] );
479             [% END %]
480             $("#fileuploadcancel").hide();
481             $("#public_cb").click(function() {
482                 $("#public").click();
483             });
484             $("#fileuploadbutton").on("click",function(e){
485                 e.preventDefault();
486                 StartUpload();
487             });
488             $("#fileuploadcancel").on("click",function(e){
489                 e.preventDefault();
490                 CancelUpload();
491             });
492             $("#searchbutton").on("click",function(){
493                 return CheckSearch();
494             });
495             $("#uploadresults tbody").on("click",".choose_entry",function(e){
496                 e.preventDefault();
497                 var record_hashvalue = $(this).data("record-hashvalue");
498                 Choose( record_hashvalue );
499             });
500             $("#uploadresults tbody").on("click",".download_entry",function(e){
501                 e.preventDefault();
502                 var record_id = $(this).data("record-id");
503                 SubmitMe( 'download', record_id );
504             });
505             $("#uploadresults tbody").on("click",".delete_entry",function(e){
506                 e.preventDefault();
507                 var record_id = $(this).data("record-id");
508                 DeleteEntry( record_id );
509             });
510             $("#new_search").on("click",function(e){
511                 e.preventDefault();
512                 SubmitMe('new');
513             });
514
515             if ( window.isSecureContext ) {
516                 $(".get-file").on("click", function(e){
517                     e.preventDefault();
518                     if( navigator.clipboard && navigator.clipboard.writeText){
519                         navigator.clipboard.writeText( $(this).attr("href") );
520                         $(this).attr("data-original-title", _( "Link copied to the clipboard" ) )
521                             .tooltip("show");
522                     }
523                 });
524                 $(".get-file").tooltip({
525                     delay: { "show": 100, "hide": 500 }
526                 }).on("hidden.bs.tooltip", function(){
527                     $(this).attr("data-original-title", _( "Copy link to this file" ) );
528                 });
529             }
530         });
531     </script>
532 [% END %]
533
534 [% INCLUDE 'intranet-bottom.inc' %]