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