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