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