Bug 26703: tools folder
[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>Upload &rsaquo; Tools &rsaquo; Koha</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_browse %]
113     [% IF uploadcategories %]
114     <form method="post" id="browsefile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
115         [% PROCESS plugin_pars %]
116         <input type="hidden" name="op" value="browse"/>
117         <fieldset class="rows">
118         <legend>Search uploads by category</legend>
119         <ol>
120             <li>
121                 <label for="browsecategory">Category: </label>
122                 <select id="browsecategory" name="browsecategory">
123                 [% FOREACH cat IN uploadcategories %]
124                     <option value="[% cat.code | html %]">[% cat.name | html %]</option>
125                 [% END %]
126                 </select>
127             </li>
128         </ol>
129         <fieldset class="action">
130             <button id="browsebutton" class="submit">Search</button>
131         </fieldset>
132         </fieldset>
133     </form>
134     [% END %]
135 [% END %]
136
137 [% BLOCK form_search %]
138     <form method="post" id="searchfile" action="/cgi-bin/koha/tools/upload.pl" enctype="multipart/form-data">
139         [% PROCESS plugin_pars %]
140         <input type="hidden" name="op" value="search"/>
141         <fieldset class="rows">
142         <legend>Search uploads by name or hashvalue</legend>
143         <ol>
144         <li>
145             <label for="term">Search term: </label>
146             <input type="text" id="term" name="term" value=""/>
147         </li>
148         </ol>
149         <fieldset class="action">
150             <button id="searchbutton" class="submit">Search</button>
151         </fieldset>
152         </fieldset>
153     </form>
154 [% END %]
155
156 [% BLOCK submitter %]
157     <form id="submitter" style="display:none;" method="post">
158         [% PROCESS plugin_pars %]
159         <input type="hidden" name="op" id="op" value=""/>
160         <input type="hidden" name="id" id="id" value="" />
161         <input type="hidden" name="msg" id="msg" value="" />
162     </form>
163 [% END %]
164
165 [% BLOCK closer %]
166     [% IF plugin %]
167         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
168     [% END %]
169 [% END %]
170
171 [% BLOCK back %]
172     [% IF !plugin %]
173         <form id="back">
174             <fieldset class="action">
175                 <button class="submit">Back</button>
176             </fieldset>
177         </form>
178     [% END %]
179 [% END %]
180
181 [% BLOCK newsearch %]
182     <form id="newsearch">
183         <fieldset class="action">
184             <button id="new_search">New search</button>
185         </fieldset>
186     </form>
187     [% IF plugin %]
188         <div id="closewindow"><a class="btn btn-default btn-default close" href="#">Close</a></div>
189     [% END %]
190 [% END %]
191
192 [% BLOCK table_results %]
193     <table id="uploadresults">
194     <thead>
195     <tr>
196         <th>Filename</th>
197         <th>Size</th>
198         <th>Hashvalue</th>
199         <th>Category</th>
200         [% IF !plugin %]<th>Public</th>[% END %]
201         [% IF !plugin %]<th>Temporary</th>[% END %]
202         <th class="NoSort noExport">Actions</th>
203     </tr>
204     </thead>
205     <tbody>
206     [% FOREACH record IN uploads %]
207     <tr>
208         <td>[% record.filename | html %]</td>
209         <td>[% record.filesize | html %]</td>
210         <td>[% record.hashvalue | html %]</td>
211         <td>[% record.uploadcategorycode | html %]</td>
212         [% IF !plugin %]
213             <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
214             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
215         [% END %]
216         <td class="actions">
217             [% IF plugin %]
218                 <button class="btn btn-default btn-xs choose_entry" data-record-hashvalue="[% record.hashvalue | html %]"><i class="fa fa-plus"></i> Choose</button>
219             [% END %]
220             <button class="btn btn-default btn-xs download_entry" data-record-id="[% record.id | html %]"><i class="fa fa-download"></i> Download</button>
221             [% IF record.owner == owner || CAN_user_tools_upload_manage %]
222                 <button class="btn btn-default btn-xs delete_entry" data-record-id="[% record.id | html %]"><i class="fa fa-trash"></i> Delete</button>
223             [% END %]
224         </td>
225    </tr>
226    [% END %]
227    </tbody>
228    </table>
229 [% END %]
230
231 <style>
232     #fileuploadstatus,#fileuploadfailed { display : none; }
233     #fileuploadstatus { margin:.4em; }
234     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface | html %]/[% theme | html %]/img/progress.png') -300px 0px no-repeat; }
235 </style>
236
237
238 </head>
239
240 [% IF ( plugin ) %]
241     <body id="tools_upload" class="tools">
242         <div class="main container-fluid">
243             <div class="row">
244                 <div class="col-sm-12">
245                     <main>
246 [% ELSE %]
247     <body id="tools_upload" class="tools">
248     [% INCLUDE 'header.inc' %]
249     [% INCLUDE 'cat-search.inc' %]
250     [% PROCESS breadcrumbs %]
251
252     <div class="main container-fluid">
253         <div class="row">
254             <div class="col-sm-10 col-sm-push-2">
255                 <main>
256 [% END %]
257
258 <h1>Upload</h1>
259 <div class="dialog alert" id="myalerts" style="display:none;"></div>
260
261 [% PROCESS submitter %]
262 [% IF mode == 'new' || mode == 'deleted' %]
263     [% PROCESS form_new %]
264     [% PROCESS form_browse %]
265     [% PROCESS form_search %]
266     [% PROCESS closer %]
267 [% ELSIF mode == 'report' %]
268     [% IF uploads %]
269         <h3>Your request gave the following results:</h3>
270         [% PROCESS table_results %]
271         [% PROCESS closer %]
272         [% PROCESS back %]
273     [% ELSE %]
274         <h4>Sorry, your request had no results.</h4>
275         [% PROCESS newsearch %]
276     [% END %]
277 [% END %]
278
279 [% IF !plugin %]
280             </main>
281         </div> <!-- /.col-sm-10.col-sm-push-2 -->
282
283         <div class="col-sm-2 col-sm-pull-10">
284             <aside>
285                 [% INCLUDE 'tools-menu.inc' %]
286             </aside>
287         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
288      </div> <!-- /.row -->
289 [% ELSE %]
290             </main>
291         </div> <!-- .col-sm-12 -->
292      </div> <!-- /.row -->
293 [% END %]
294
295
296 [% MACRO jsinclude BLOCK %]
297     [% Asset.js("js/tools-menu.js") | $raw %]
298     [% INCLUDE 'datatables.inc' %]
299     [% Asset.js("js/file-upload.js") | $raw %]
300     [% INCLUDE 'columns_settings.inc' %]
301     <script>
302         function StartUpload() {
303             if( $('#fileToUpload').prop('files').length == 0 ) return;
304             $('#fileToUpload').prop('disabled',true);
305             $('#fileuploadbutton').hide();
306             $("#fileuploadcancel").show();
307             $("#fileuploadfailed").html('');
308             $("#myalerts").hide('');
309             $("#myalerts").html('');
310             $("#fileuploadstatus").show();
311             $("#uploadedfileid").val('');
312             $("#searchfile").hide();
313             $("#lastbreadcrumb").text( _("Add a new upload") );
314
315             var cat, xtra='';
316             if( $("#uploadcategory").val() )
317                 cat = encodeURIComponent( $("#uploadcategory").val() );
318             if( cat ) xtra= 'category=' + cat + '&';
319             [% IF plugin %]
320                 xtra = xtra + 'public=1&temp=0';
321             [% ELSE %]
322                 if( !cat ) xtra = 'temp=1&';
323                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
324             [% END %]
325             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
326         }
327         function CancelUpload() {
328             if( xhr ) xhr.abort();
329             $("#fileuploadstatus").hide();
330             $('#fileToUpload').prop('disabled', false);
331             $('#fileuploadbutton').show();
332             $("#fileuploadcancel").hide();
333             $("#fileuploadfailed").show();
334             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
335         }
336         function cbUpload( status, fileid, err ) {
337             $('#fileToUpload').prop('disabled', false);
338             if( status=='done' ) {
339                 var e = err? JSON.stringify(err): '';
340                 SubmitMe( 'search', fileid, e );
341             } else {
342                 $('#fileuploadbutton').show();
343                 $("#fileuploadcancel").hide();
344                 $("#fileuploadstatus").hide();
345                 $("#fileuploadfailed").show();
346                 $("#fileuploadfailed").html( _("Upload status: ") +
347                     ( status=='failed'? _("Failed"):
348                     ( status=='denied'? _("Denied"): status ))
349                 );
350                 ShowAlerts( err );
351             }
352         }
353         function ShowAlerts(err) {
354             var str = '';
355             for( var file in err ) {
356                 str= str + '<p>' + file + ': ' +
357                     errMESSAGES( err[file].code ) + '</p>';
358             }
359             if( str ) {
360                 $('#myalerts').html(str);
361                 $('#myalerts').show();
362             }
363         }
364         function errMESSAGES(code) {
365             var rv;
366             switch(code) {
367                 case 'UPLERR_ALREADY_EXISTS':
368                     rv = _("This file already exists (in this category).");
369                     break;
370                 case 'UPLERR_CANNOT_WRITE':
371                     rv = _("File could not be created. Check permissions.");
372                     break;
373                 case 'UPLERR_NO_ROOT_DIR':
374                     rv = _("Your koha-conf.xml does not contain a valid upload_path.");
375                     break;
376                 case 'UPLERR_NO_TEMP_DIR':
377                     rv = _("No temporary directory found.");
378                     break;
379                 case 'UPLERR_FILE_NOT_READ':
380                     rv = _("File could not be read.");
381                     break;
382                 case 'UPL_FILE_DELETED': // An alert, no error
383                     rv = _("File has been deleted.");
384                     break;
385                 case 'UPLERR_FILE_NOT_DELETED':
386                     rv = _("File or upload record could not be deleted.");
387                     break;
388                 default:
389                     rv = code;
390             }
391             return rv;
392         }
393         function CheckSearch() {
394             if( $("#term").val()=="" ) {
395                 alert( _("Please enter a search term.") );
396                 return false;
397             }
398             return true;
399         }
400         function SubmitMe(op, id, msg ) {
401             $("#submitter #op").val( op );
402             $("#submitter #id").val( id );
403             $("#submitter #msg").val( msg );
404             $("#submitter").submit();
405         }
406         function DeleteEntry(id) {
407             if( !confirm( _("Do you really want to delete this upload?") ))
408                 return false;
409             ClearField();
410             SubmitMe( 'delete', id );
411         }
412         function ClearField() {
413             [% IF plugin %]
414                 $(window.opener.document).find('#[% index | html %]').val( '' );
415             [% END %]
416         }
417         function Choose(hashval) {
418             var res = '[% Koha.Preference('OPACBaseURL') | html %]';
419             res = res.replace( /\/$/, '');
420             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
421             [% IF index %]
422                 $(window.opener.document).find('#[% index | html %]').val( res );
423             [% END %]
424             window.close();
425         }
426         $(document).ready(function() {
427             KohaTable("uploadresults",{});
428             [% IF msg %]
429                 ShowAlerts( [% msg | html %] );
430             [% END %]
431             $("#fileuploadcancel").hide();
432             $("#public_cb").click(function() {
433                 $("#public").click();
434             });
435             $("#fileuploadbutton").on("click",function(e){
436                 e.preventDefault();
437                 StartUpload();
438             });
439             $("#fileuploadcancel").on("click",function(e){
440                 e.preventDefault();
441                 CancelUpload();
442             });
443             $("#searchbutton").on("click",function(){
444                 return CheckSearch();
445             });
446             $(".choose_entry").on("click",function(e){
447                 e.preventDefault();
448                 var record_hashvalue = $(this).data("record-hashvalue");
449                 Choose( record_hashvalue );
450             });
451             $(".download_entry").on("click",function(e){
452                 e.preventDefault();
453                 var record_id = $(this).data("record-id");
454                 SubmitMe( 'download', record_id );
455             });
456             $(".delete_entry").on("click",function(e){
457                 e.preventDefault();
458                 var record_id = $(this).data("record-id");
459                 DeleteEntry( record_id );
460             });
461             $("#new_search").on("click",function(e){
462                 e.preventDefault();
463                 SubmitMe('new');
464             });
465         });
466     </script>
467 [% END %]
468
469 [% INCLUDE 'intranet-bottom.inc' %]