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