Bug 26602: Don't export "actions" column
[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>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
174             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
175         [% END %]
176         <td class="actions">
177             [% IF plugin %]
178                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
179             [% END %]
180             <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
181             [% IF record.owner == owner || CAN_user_tools_upload_manage %]
182                 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
183             [% END %]
184         </td>
185    </tr>
186    [% END %]
187    </tbody>
188    </table>
189 [% END %]
190
191 <style>
192     #fileuploadstatus,#fileuploadfailed { display : none; }
193     #fileuploadstatus { margin:.4em; }
194     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
195 </style>
196
197
198 </head>
199
200 [% IF ( plugin ) %]
201     <body id="tools_upload" class="tools">
202         <div class="main container-fluid">
203             <div class="row">
204                 <div class="col-sm-12">
205                     <main>
206 [% ELSE %]
207     <body id="tools_upload" class="tools">
208     [% INCLUDE 'header.inc' %]
209     [% INCLUDE 'cat-search.inc' %]
210     [% PROCESS breadcrumbs %]
211
212     <div class="main container-fluid">
213         <div class="row">
214             <div class="col-sm-10 col-sm-push-2">
215                 <main>
216 [% END %]
217
218 <h1>Upload</h1>
219 <div class="dialog alert" id="myalerts" style="display:none;"></div>
220
221 [% PROCESS submitter %]
222 [% IF mode == 'new' || mode == 'deleted' %]
223     [% PROCESS form_new %]
224     [% PROCESS form_search %]
225     [% PROCESS closer %]
226 [% ELSIF mode == 'report' %]
227     [% IF uploads %]
228         <h3>Your request gave the following results:</h3>
229         [% PROCESS table_results %]
230         [% PROCESS closer %]
231         [% PROCESS back %]
232     [% ELSE %]
233         <h4>Sorry, your request had no results.</h4>
234         [% PROCESS newsearch %]
235     [% END %]
236 [% END %]
237
238 [% IF !plugin %]
239             </main>
240         </div> <!-- /.col-sm-10.col-sm-push-2 -->
241
242         <div class="col-sm-2 col-sm-pull-10">
243             <aside>
244                 [% INCLUDE 'tools-menu.inc' %]
245             </aside>
246         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
247      </div> <!-- /.row -->
248 [% ELSE %]
249             </main>
250         </div> <!-- .col-sm-12 -->
251      </div> <!-- /.row -->
252 [% END %]
253
254
255 [% MACRO jsinclude BLOCK %]
256     [% Asset.js("js/tools-menu.js") | $raw %]
257     [% INCLUDE 'datatables.inc' %]
258     [% Asset.js("js/file-upload.js") | $raw %]
259     <script>
260         function StartUpload() {
261             if( $('#fileToUpload').prop('files').length == 0 ) return;
262             $('#fileToUpload').prop('disabled',true);
263             $('#fileuploadbutton').hide();
264             $("#fileuploadcancel").show();
265             $("#fileuploadfailed").html('');
266             $("#myalerts").hide('');
267             $("#myalerts").html('');
268             $("#fileuploadstatus").show();
269             $("#uploadedfileid").val('');
270             $("#searchfile").hide();
271             $("#lastbreadcrumb").text( _("Add a new upload") );
272
273             var cat, xtra='';
274             if( $("#uploadcategory").val() )
275                 cat = encodeURIComponent( $("#uploadcategory").val() );
276             if( cat ) xtra= 'category=' + cat + '&';
277             [% IF plugin %]
278                 xtra = xtra + 'public=1&temp=0';
279             [% ELSE %]
280                 if( !cat ) xtra = 'temp=1&';
281                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
282             [% END %]
283             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
284         }
285         function CancelUpload() {
286             if( xhr ) xhr.abort();
287             $("#fileuploadstatus").hide();
288             $('#fileToUpload').prop('disabled', false);
289             $('#fileuploadbutton').show();
290             $("#fileuploadcancel").hide();
291             $("#fileuploadfailed").show();
292             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
293         }
294         function cbUpload( status, fileid, err ) {
295             $('#fileToUpload').prop('disabled', false);
296             if( status=='done' ) {
297                 var e = err? JSON.stringify(err): '';
298                 SubmitMe( 'search', fileid, e );
299             } else {
300                 $('#fileuploadbutton').show();
301                 $("#fileuploadcancel").hide();
302                 $("#fileuploadstatus").hide();
303                 $("#fileuploadfailed").show();
304                 $("#fileuploadfailed").html( _("Upload status: ") +
305                     ( status=='failed'? _("Failed"):
306                     ( status=='denied'? _("Denied"): status ))
307                 );
308                 ShowAlerts( err );
309             }
310         }
311         function ShowAlerts(err) {
312             var str = '';
313             for( var file in err ) {
314                 str= str + '<p>' + file + ': ' +
315                     errMESSAGES( err[file].code ) + '</p>';
316             }
317             if( str ) {
318                 $('#myalerts').html(str);
319                 $('#myalerts').show();
320             }
321         }
322         function errMESSAGES(code) {
323             var rv;
324             switch(code) {
325                 case 'UPLERR_ALREADY_EXISTS':
326                     rv = _("This file already exists (in this category).");
327                     break;
328                 case 'UPLERR_CANNOT_WRITE':
329                     rv = _("File could not be created. Check permissions.");
330                     break;
331                 case 'UPLERR_NO_ROOT_DIR':
332                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
333                     break;
334                 case 'UPLERR_NO_TEMP_DIR':
335                     rv = _("No temporary directory found.");
336                     break;
337                 case 'UPLERR_FILE_NOT_READ':
338                     rv = _("File could not be read.");
339                     break;
340                 case 'UPL_FILE_DELETED': // An alert, no error
341                     rv = _("File has been deleted.");
342                     break;
343                 case 'UPLERR_FILE_NOT_DELETED':
344                     rv = _("File or upload record could not be deleted.");
345                     break;
346                 default:
347                     rv = code;
348             }
349             return rv;
350         }
351         function CheckSearch() {
352             if( $("#term").val()=="" ) {
353                 alert( _("Please enter a search term.") );
354                 return false;
355             }
356             return true;
357         }
358         function SubmitMe(op, id, msg ) {
359             $("#submitter #op").val( op );
360             $("#submitter #id").val( id );
361             $("#submitter #msg").val( msg );
362             $("#submitter").submit();
363         }
364         function DeleteEntry(id) {
365             if( !confirm( _("Do you really want to delete this upload?") ))
366                 return false;
367             ClearField();
368             SubmitMe( 'delete', id );
369         }
370         function ClearField() {
371             [% IF plugin %]
372                 $(window.opener.document).find('#[% index | html %]').val( '' );
373             [% END %]
374         }
375         function Choose(hashval) {
376             var res = '[% Koha.Preference('OPACBaseURL') | html %]';
377             res = res.replace( /\/$/, '');
378             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
379             [% IF index %]
380                 $(window.opener.document).find('#[% index | html %]').val( res );
381             [% END %]
382             window.close();
383         }
384         $(document).ready(function() {
385             $("#uploadresults").dataTable($.extend(true, {}, dataTablesDefaults, {
386                 "aoColumnDefs": [
387                     { 'bSortable': false, 'aTargets': [ 'nosort' ] }
388                 ],
389                 "sPaginationType": "full"
390             }));
391             [% IF msg %]
392                 ShowAlerts( [% msg | html %] );
393             [% END %]
394             $("#fileuploadcancel").hide();
395             $("#public_cb").click(function() {
396                 $("#public").click();
397             });
398             $("#fileuploadbutton").on("click",function(e){
399                 e.preventDefault();
400                 StartUpload();
401             });
402             $("#fileuploadcancel").on("click",function(e){
403                 e.preventDefault();
404                 CancelUpload();
405             });
406             $("#searchbutton").on("click",function(){
407                 return CheckSearch();
408             });
409             $(".choose_entry").on("click",function(e){
410                 e.preventDefault();
411                 var record_hashvalue = $(this).data("record-hashvalue");
412                 Choose( record_hashvalue );
413             });
414             $(".download_entry").on("click",function(e){
415                 e.preventDefault();
416                 var record_id = $(this).data("record-id");
417                 SubmitMe( 'download', record_id );
418             });
419             $(".delete_entry").on("click",function(e){
420                 e.preventDefault();
421                 var record_id = $(this).data("record-id");
422                 DeleteEntry( record_id );
423             });
424             $("#new_search").on("click",function(e){
425                 e.preventDefault();
426                 SubmitMe('new');
427             });
428         });
429     </script>
430 [% END %]
431
432 [% INCLUDE 'intranet-bottom.inc' %]