Bug 20538: Remove the need of writing [% KOHA_VERSION %] everywhere
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / upload.tt
1 [% USE Asset %]
2 [% USE Koha %]
3 [% SET footerjs = 1 %]
4 [% INCLUDE 'doc-head-open.inc' %]
5 [% IF plugin %]
6     <title>Upload plugin</title>
7 [% ELSE %]
8     <title>Koha &rsaquo; Tools &rsaquo; Upload</title>
9 [% END %]
10 [% INCLUDE 'doc-head-close.inc' %]
11 [% Asset.css("css/datatables.css") %]
12
13 [% BLOCK plugin_pars %]
14     [% IF plugin %]
15         <input type="hidden" name="plugin" value="1" />
16         <input type="hidden" name="index" value="[% index %]" />
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 %]">[% cat.name %]</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">Actions</th>
163     </tr>
164     </thead>
165     <tbody>
166     [% FOREACH record IN uploads %]
167     <tr>
168         <td>[% record.filename %]</td>
169         <td>[% record.filesize %]</td>
170         <td>[% record.hashvalue %]</td>
171         <td>[% record.uploadcategorycode %]</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 %]"><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 %]"><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 %]"><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 type="text/css">
192     #fileuploadstatus,#fileuploadfailed { display : none; }
193     #fileuploadstatus { margin:.4em; }
194     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/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="yui-t7">
203             <div id="bd">
204                 <div class="yui-g">
205 [% ELSE %]
206     <body id="tools_upload" class="tools">
207     [% INCLUDE 'header.inc' %]
208     [% INCLUDE 'cat-search.inc' %]
209     [% PROCESS breadcrumbs %]
210     <div id="doc3" class="yui-t2">
211         <div id="bd">
212             <div id="yui-main">
213                 <div class="yui-b">
214 [% END %]
215
216
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 </div>
239
240 [% IF !plugin %]
241 </div>
242     <div class="yui-b noprint">
243         [% INCLUDE 'tools-menu.inc' %]
244     </div>
245 [% END %]
246
247 </div>
248
249 [% MACRO jsinclude BLOCK %]
250     [% Asset.js("js/tools-menu.js") %]
251     [% INCLUDE 'datatables.inc' %]
252     <script type="text/javascript">
253         var errMESSAGES = [
254             "Error 0: Not in use",
255             _("This file already exists (in this category)."),
256             _("File could not be created. Check permissions."),
257             _("Your koha-conf.xml does not contain a valid upload_path."),
258             _("No temporary directory found."),
259             _("File could not be read."),
260             _("File has been deleted."),
261             _("File or upload record could not be deleted."),
262         ];
263     </script>
264     [% Asset.js("js/file-upload.js") %]
265     <script type="text/javascript">
266         function StartUpload() {
267             if( $('#fileToUpload').prop('files').length == 0 ) return;
268             $('#fileToUpload').prop('disabled',true);
269             $('#fileuploadbutton').hide();
270             $("#fileuploadcancel").show();
271             $("#fileuploadfailed").html('');
272             $("#myalerts").hide('');
273             $("#myalerts").html('');
274             $("#fileuploadstatus").show();
275             $("#uploadedfileid").val('');
276             $("#searchfile").hide();
277             $("#lastbreadcrumb").text( _("Add a new upload") );
278
279             var cat, xtra='';
280             if( $("#uploadcategory").val() )
281                 cat = encodeURIComponent( $("#uploadcategory").val() );
282             if( cat ) xtra= 'category=' + cat + '&';
283             [% IF plugin %]
284                 xtra = xtra + 'public=1&temp=0';
285             [% ELSE %]
286                 if( !cat ) xtra = 'temp=1&';
287                 if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
288             [% END %]
289             xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
290         }
291         function CancelUpload() {
292             if( xhr ) xhr.abort();
293             $("#fileuploadstatus").hide();
294             $('#fileToUpload').prop('disabled', false);
295             $('#fileuploadbutton').show();
296             $("#fileuploadcancel").hide();
297             $("#fileuploadfailed").show();
298             $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
299         }
300         function cbUpload( status, fileid, err ) {
301             $('#fileToUpload').prop('disabled', false);
302             if( status=='done' ) {
303                 var e = err? JSON.stringify(err): '';
304                 SubmitMe( 'search', fileid, e );
305             } else {
306                 $('#fileuploadbutton').show();
307                 $("#fileuploadcancel").hide();
308                 $("#fileuploadstatus").hide();
309                 $("#fileuploadfailed").show();
310                 $("#fileuploadfailed").html( _("Upload status: ") +
311                     ( status=='failed'? _("Failed"):
312                     ( status=='denied'? _("Denied"): status ))
313                 );
314                 ShowAlerts( err );
315             }
316         }
317         function ShowAlerts(err) {
318             var str = '';
319             for( var file in err ) {
320                 str= str + '<p>' + file + ': ' +
321                     errMESSAGES[ err[file].code ] + '</p>';
322             }
323             if( str ) {
324                 $('#myalerts').html(str);
325                 $('#myalerts').show();
326             }
327         }
328         function CheckSearch() {
329             if( $("#term").val()=="" ) {
330                 alert( _("Please enter a search term.") );
331                 return false;
332             }
333             return true;
334         }
335         function SubmitMe(op, id, msg ) {
336             $("#submitter #op").val( op );
337             $("#submitter #id").val( id );
338             $("#submitter #msg").val( msg );
339             $("#submitter").submit();
340         }
341         function DeleteEntry(id) {
342             if( !confirm( _("Do you really want to delete this upload?") ))
343                 return false;
344             ClearField();
345             SubmitMe( 'delete', id );
346         }
347         function ClearField() {
348             [% IF plugin %]
349                 $(window.opener.document).find('#[% index %]').val( '' );
350             [% END %]
351         }
352         function Choose(hashval) {
353             var res = '[% Koha.Preference('OPACBaseURL') %]';
354             res = res.replace( /\/$/, '');
355             res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
356             [% IF index %]
357                 $(window.opener.document).find('#[% index %]').val( res );
358             [% END %]
359             window.close();
360         }
361         $(document).ready(function() {
362             $("#uploadresults").dataTable($.extend(true, {}, dataTablesDefaults, {
363                 "aoColumnDefs": [
364                     { 'bSortable': false, 'aTargets': [ 'nosort' ] }
365                 ],
366                 "sPaginationType": "four_button"
367             }));
368             [% IF msg %]
369                 ShowAlerts( [% msg %] );
370             [% END %]
371             $("#fileuploadcancel").hide();
372             $("#public_cb").click(function() {
373                 $("#public").click();
374             });
375             $("#fileuploadbutton").on("click",function(e){
376                 e.preventDefault();
377                 StartUpload();
378             });
379             $("#fileuploadcancel").on("click",function(e){
380                 e.preventDefault();
381                 CancelUpload();
382             });
383             $("#searchbutton").on("click",function(){
384                 return CheckSearch();
385             });
386             $(".choose_entry").on("click",function(e){
387                 e.preventDefault();
388                 var record_hashvalue = $(this).data("record-hashvalue");
389                 Choose( record_hashvalue );
390             });
391             $(".download_entry").on("click",function(e){
392                 e.preventDefault();
393                 var record_id = $(this).data("record-id");
394                 SubmitMe( 'download', record_id );
395             });
396             $(".delete_entry").on("click",function(e){
397                 e.preventDefault();
398                 var record_id = $(this).data("record-id");
399                 DeleteEntry( record_id );
400             });
401             $("#new_search").on("click",function(e){
402                 e.preventDefault();
403                 SubmitMe('new');
404             });
405         });
406     </script>
407 [% END %]
408
409 [% INCLUDE 'intranet-bottom.inc' %]