Bug 15867: Move MARC modification templates JavaScript into separate file
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / tools / upload.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 [% USE Koha %]
3 [% IF plugin %]
4     <title>Upload plugin</title>
5 [% ELSE %]
6     <title>Koha &rsaquo; Tools &rsaquo; Upload</title>
7 [% END %]
8 [% INCLUDE 'doc-head-close.inc' %]
9
10 [% BLOCK plugin_pars %]
11     [% IF plugin %]
12         <input type="hidden" name="plugin" value="1" />
13         <input type="hidden" name="index" value="[% index %]" />
14     [% END %]
15 [% END %]
16
17 [% BLOCK breadcrumbs %]
18     <div id="breadcrumbs">
19         <a href="/cgi-bin/koha/mainpage.pl">Home</a>
20         &rsaquo;
21         <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
22         &rsaquo;
23         <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
24         &rsaquo;
25         <span id="lastbreadcrumb">
26         [% IF mode=='new' || mode =='deleted'%]
27             Add new upload or search
28         [% ELSE %]
29             Results
30         [% END %]
31         </span>
32     </div>
33 [% END %]
34
35 [% BLOCK form_new %]
36     <form method="post" action="[% SCRIPT_NAME %]" id="uploadfile" enctype="multipart/form-data">
37         [% PROCESS plugin_pars %]
38         <fieldset class="rows" id="uploadform">
39         <legend>Upload new files</legend>
40         <ol>
41         <li>
42         <div id="fileuploadform">
43             <label for="fileToUpload">Select files: </label>
44             <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
45         </div>
46         </li>
47         [% IF uploadcategories %]
48             <li>
49                 <label for="uploadcategory">Category: </label>
50                 <select id="uploadcategory" name="uploadcategory">
51                 [% IF !plugin %]
52                     <option value="" disabled hidden selected></option>
53                 [% END %]
54                 [% FOREACH cat IN uploadcategories %]
55                     <option value="[% cat.code %]">[% cat.name %]</option>
56                 [% END %]
57                 </select>
58             </li>
59         [% END %]
60         [% IF !plugin %]
61             <li>
62             [% IF uploadcategories %]
63                 <div class="hint">Note: For temporary uploads do not select a category.</div>
64             [% ELSE %]
65                 <div class="hint">Note: No upload categories have been defined. All uploads will be marked as temporary.</div>
66             [% END %]
67             </li>
68         [% END %]
69         <li>
70             [% IF plugin %]
71                 <input type="hidden" id="public" name="public" value="1"/>
72             [% ELSE %]
73                 <label id="public_cb">Allow public downloads:</label>
74                 <input type="checkbox" id="public" name="public">
75                 </input>
76             [% END %]
77         </li>
78         </ol>
79         <fieldset class="action">
80             <button id="fileuploadbutton" onclick="StartUpload(); return false;">Upload</button>
81             <button id="fileuploadcancel" onclick="CancelUpload(); return false;">Cancel</button>
82         </fieldset>
83         </fieldset>
84         <div id="fileuploadpanel">
85             <div id="fileuploadstatus">Upload progress:
86             <progress id="fileuploadprogress" min="0" max="100" value="0">
87             </progress>
88             <span class="fileuploadpercent">0</span>%
89             </div>
90             <div id="fileuploadfailed"></div>
91         </div>
92     </form>
93 [% END %]
94
95 [% BLOCK form_search %]
96     <form method="post" id="searchfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
97         [% PROCESS plugin_pars %]
98         <input type="hidden" name="op" value="search"/>
99         <fieldset class="rows">
100         <legend>Search uploads by name or hashvalue</legend>
101         <ol>
102         <li>
103             <label for="searchupload">Search term: </label>
104             <input type="text" id="term" name="term" value=""/>
105         </li>
106         <li>
107             <fieldset class="action">
108                 <button id="searchbutton" onclick="return CheckSearch();" class="submit">Search</button>
109             </fieldset>
110         </li>
111         </ol>
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         <form id="closer">
128             <fieldset class="action">
129                 <button onclick="window.close();return false;">Close</button>
130             </fieldset>
131         </form>
132     [% END %]
133 [% END %]
134
135 [% BLOCK back %]
136     [% IF !plugin %]
137         <form id="back">
138             <fieldset class="action">
139                 <button class="submit">Back</button>
140             </fieldset>
141         </form>
142     [% END %]
143 [% END %]
144
145 [% BLOCK newsearch %]
146     <form id="newsearch">
147         <fieldset class="action">
148             <button onclick="SubmitMe('new'); return false;">New search</button>
149             [% IF plugin %]
150                 <button onclick="window.close();return false;">Close</button>
151             [% END %]
152         </fieldset>
153     </form>
154 [% END %]
155
156 [% BLOCK table_results %]
157     <table>
158     <thead>
159     <tr>
160         <th>Filename</td>
161         <th>Size</td>
162         <th>Hashvalue</td>
163         <th>Category</td>
164         [% IF !plugin %]<th>Public</td>[% END %]
165         [% IF !plugin %]<th>Temporary</td>[% END %]
166         <th>Actions</td>
167     </tr>
168     </thead>
169     <tbody>
170     [% FOREACH record IN uploads %]
171     <tr>
172         <td>[% record.name %]</td>
173         <td>[% record.filesize %]</td>
174         <td>[% record.hashvalue %]</td>
175         <td>[% record.uploadcategorycode %]</td>
176         [% IF !plugin %]
177             <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
178             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
179         [% END %]
180         <td>
181             [% IF plugin %]
182                 <a href="" onclick="Choose('[% record.hashvalue %]'); return false;">Choose</a>&nbsp;
183             [% END %]
184             <a href="" onclick="SubmitMe( 'download', [% record.id %] ); return false;">Download</a>&nbsp;
185             <a href="" onclick="DeleteEntry( [% record.id %] ); return false;">Delete</a>
186         </td>
187    </tr>
188    [% END %]
189    </tbody>
190    </table>
191 [% END %]
192
193 <style type="text/css">
194     #fileuploadstatus,#fileuploadfailed { display : none; }
195     #fileuploadstatus { margin:.4em; }
196     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }
197 </style>
198
199 <script type="text/javascript">
200 //<![CDATA[
201     var errMESSAGES = [
202         "Error 0: Not in use",
203         _("This file already exists (in this category)."),
204         _("File could not be created. Check permissions."),
205         _("Your koha-conf.xml does not contain a valid upload_path."),
206         _("No temporary directory found."),
207         _("File could not be read."),
208         _("File has been deleted."),
209         _("File could not be deleted."),
210     ];
211 //]]>
212 </script>
213 <script type="text/javascript" src="[% themelang %]/js/file-upload.js"></script>
214 <script type="text/javascript">
215 //<![CDATA[
216 function StartUpload() {
217     if( $('#fileToUpload').prop('files').length == 0 ) return;
218     $('#fileToUpload').prop('disabled',true);
219     $('#fileuploadbutton').hide();
220     $("#fileuploadcancel").show();
221     $("#fileuploadfailed").html('');
222     $("#myalerts").hide('');
223     $("#myalerts").html('');
224     $("#fileuploadstatus").show();
225     $("#uploadedfileid").val('');
226     $("#searchfile").hide();
227     $("#lastbreadcrumb").text( _("Add a new upload") );
228
229     var cat, xtra='';
230     if( $("#uploadcategory").val() )
231         cat = encodeURIComponent( $("#uploadcategory").val() );
232     if( cat ) xtra= 'category=' + cat + '&';
233     [% IF plugin %]
234         xtra = xtra + 'public=1&temp=0';
235     [% ELSE %]
236         if( !cat ) xtra = 'temp=1&';
237         if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
238     [% END %]
239     xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
240 }
241 function CancelUpload() {
242     if( xhr ) xhr.abort();
243     $("#fileuploadstatus").hide();
244     $('#fileToUpload').prop('disabled', false);
245     $('#fileuploadbutton').show();
246     $("#fileuploadcancel").hide();
247     $("#fileuploadfailed").show();
248     $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
249 }
250 function cbUpload( status, fileid, err ) {
251     $('#fileToUpload').prop('disabled', false);
252     if( status=='done' ) {
253         var e = err? JSON.stringify(err): '';
254         SubmitMe( 'search', fileid, e );
255     } else {
256         $('#fileuploadbutton').show();
257         $("#fileuploadcancel").hide();
258         $("#fileuploadstatus").hide();
259         $("#fileuploadfailed").show();
260         $("#fileuploadfailed").html( _("Upload status: ") +
261             ( status=='failed'? _("Failed"):
262             ( status=='denied'? _("Denied"): status ))
263         );
264         ShowAlerts( err );
265     }
266 }
267 function ShowAlerts(err) {
268     var str = '';
269     for( var file in err ) {
270         str= str + '<p>' + file + ': ' +
271             errMESSAGES[ err[file] ] + '</p>';
272     }
273     if( str ) {
274         $('#myalerts').html(str);
275         $('#myalerts').show();
276     }
277 }
278 function CheckSearch() {
279     if( $("#term").val()=="" ) {
280         alert( _("Please enter a search term.") );
281         return false;
282     }
283     return true;
284 }
285 function SubmitMe(op, id, msg ) {
286     $("#submitter #op").val( op );
287     $("#submitter #id").val( id );
288     $("#submitter #msg").val( msg );
289     $("#submitter").submit();
290 }
291 function DeleteEntry(id) {
292     if( !confirm( _("Do you really want to delete this upload?") ))
293         return false;
294     ClearField();
295     SubmitMe( 'delete', id );
296 }
297 function ClearField() {
298     [% IF plugin %]
299         $(window.opener.document).find('#[% index %]').val( '' );
300     [% END %]
301 }
302 function Choose(hashval) {
303     var res = '[% Koha.Preference('OPACBaseURL') %]';
304     res = res.replace( /\/$/, '');
305     res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
306     [% IF index %]
307         $(window.opener.document).find('#[% index %]').val( res );
308     [% END %]
309     window.close();
310 }
311 $(document).ready(function() {
312     [% IF msg %]
313         ShowAlerts( [% msg %] );
314     [% END %]
315     $("#fileuploadcancel").hide();
316     $("#public_cb").click(function() {
317         $("#public").click();
318     });
319 });
320 //]]>
321 </script>
322 </head>
323
324 <body id="tools_upload" class="tools">
325 [% IF !plugin %]
326     [% INCLUDE 'header.inc' %]
327     [% INCLUDE 'cat-search.inc' %]
328     [% PROCESS breadcrumbs %]
329 [% END %]
330
331 <div id="doc3" class="yui-t2">
332    <div id="bd">
333     <div id="yui-main">
334     <div class="yui-b">
335
336 <h1>Upload</h1>
337
338 <div class="dialog alert" id="myalerts" style="display:none;"></div>
339
340 [% PROCESS submitter %]
341 [% IF mode == 'new' || mode == 'deleted' %]
342     [% PROCESS form_new %]
343     [% PROCESS form_search %]
344     [% PROCESS closer %]
345 [% ELSIF mode == 'report' %]
346     [% IF uploads %]
347         <h3>Your request gave the following results:</h3>
348         [% PROCESS table_results %]
349         [% PROCESS closer %]
350         [% PROCESS back %]
351     [% ELSE %]
352         <h4>Sorry, your request had no results.</h4>
353         [% PROCESS newsearch %]
354     [% END %]
355 [% END %]
356
357 </div>
358 </div>
359 </div>
360
361 [% INCLUDE 'intranet-bottom.inc' %]