Bug 14321: Integrate Upload.pm into Koha
[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>&nbsp;</label>
74                 <input type="checkbox" id="public" name="public">
75                     Allow public downloads
76                 </input>
77             [% END %]
78         </li>
79         </ol>
80         <fieldset class="action">
81             <button id="fileuploadbutton" onclick="StartUpload(); return false;">Upload</button>
82             <button id="fileuploadcancel" onclick="CancelUpload(); return false;">Cancel</button>
83         </fieldset>
84         </fieldset>
85         <div id="fileuploadpanel">
86             <div id="fileuploadstatus">Upload progress:
87             <progress id="fileuploadprogress" min="0" max="100" value="0">
88             </progress>
89             <span class="fileuploadpercent">0</span>%
90             </div>
91             <div id="fileuploadfailed"></div>
92         </div>
93     </form>
94 [% END %]
95
96 [% BLOCK form_search %]
97     <form method="post" id="searchfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
98         [% PROCESS plugin_pars %]
99         <input type="hidden" name="op" value="search"/>
100         <fieldset class="rows">
101         <legend>Search uploads by name or hashvalue</legend>
102         <ol>
103         <li>
104             <label for="searchupload">Search term: </label>
105             <input type="text" id="term" name="term" value=""/>
106         </li>
107         <li>
108             <fieldset class="action">
109                 <button id="searchbutton" onclick="return CheckSearch();" class="submit">Search</button>
110             </fieldset>
111         </li>
112         </ol>
113         </fieldset>
114     </form>
115 [% END %]
116
117 [% BLOCK submitter %]
118     <form id="submitter" style="display:none;" method="post">
119         [% PROCESS plugin_pars %]
120         <input type="hidden" name="op" id="op" value=""/>
121         <input type="hidden" name="id" id="id" value="" />
122         <input type="hidden" name="msg" id="msg" value="" />
123     </form>
124 [% END %]
125
126 [% BLOCK closer %]
127     [% IF plugin %]
128         <form id="closer">
129             <fieldset class="action">
130                 <button onclick="window.close();return false;">Close</button>
131             </fieldset>
132         </form>
133     [% END %]
134 [% END %]
135
136 [% BLOCK newsearch %]
137     <form id="newsearch">
138         <fieldset class="action">
139             <button onclick="SubmitMe('new'); return false;">New search</button>
140             [% IF plugin %]
141                 <button onclick="window.close();return false;">Close</button>
142             [% END %]
143         </fieldset>
144     </form>
145 [% END %]
146
147 [% BLOCK table_results %]
148     <table>
149     <thead>
150     <tr>
151         <th>Filename</td>
152         <th>Size</td>
153         <th>Hashvalue</td>
154         <th>Category</td>
155         [% IF !plugin %]<th>Public</td>[% END %]
156         [% IF !plugin %]<th>Temporary</td>[% END %]
157         <th>Actions</td>
158     </tr>
159     </thead>
160     <tbody>
161     [% FOREACH record IN uploads %]
162     <tr>
163         <td>[% record.name %]</td>
164         <td>[% record.filesize %]</td>
165         <td>[% record.hashvalue %]</td>
166         <td>[% record.categorycode %]</td>
167         [% IF !plugin %]
168             <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
169             <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
170         [% END %]
171         <td>
172             [% IF plugin %]
173                 <a href="" onclick="Choose('[% record.hashvalue %]'); return false;">Choose</a>&nbsp;
174             [% END %]
175             <a href="" onclick="SubmitMe( 'download', [% record.id %] ); return false;">Download</a>&nbsp;
176             <a href="" onclick="ClearField(); SubmitMe( 'delete', [% record.id %] ); return false;">Delete</a>
177         </td>
178    </tr>
179    [% END %]
180    </tbody>
181    </table>
182 [% END %]
183
184 <style type="text/css">
185     #fileuploadstatus,#fileuploadfailed { display : none; }
186     #fileuploadstatus { margin:.4em; }
187     #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }
188 </style>
189
190 <script type="text/javascript">
191 //<![CDATA[
192     var errMESSAGES = [
193         "Error 0: Not in use",
194         _("This file already exists (in this category)."),
195         _("File could not be created. Check permissions."),
196         _("Your koha-conf.xml does not contain a valid upload_path."),
197         _("No temporary directory found."),
198         _("File could not be read."),
199         _("File has been deleted."),
200         _("File could not be deleted."),
201     ];
202 //]]>
203 </script>
204 <script type="text/javascript" src="[% themelang %]/js/file-upload.js"></script>
205 <script type="text/javascript">
206 //<![CDATA[
207 function StartUpload() {
208     if( $('#fileToUpload').prop('files').length == 0 ) return;
209     $('#fileToUpload').prop('disabled',true);
210     $('#fileuploadbutton').hide();
211     $("#fileuploadcancel").show();
212     $("#fileuploadfailed").html('');
213     $("#myalerts").hide('');
214     $("#myalerts").html('');
215     $("#fileuploadstatus").show();
216     $("#uploadedfileid").val('');
217     $("#searchfile").hide();
218     $("#lastbreadcrumb").text( _("Add a new upload") );
219
220     var cat, xtra='';
221     if( $("#uploadcategory").val() )
222         cat = encodeURIComponent( $("#uploadcategory").val() );
223     if( cat ) xtra= 'category=' + cat + '&';
224     [% IF plugin %]
225         xtra = xtra + 'public=1&temp=0';
226     [% ELSE %]
227         if( !cat ) xtra = 'temp=1&';
228         if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
229     [% END %]
230     xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
231 }
232 function CancelUpload() {
233     if( xhr ) xhr.abort();
234     $("#fileuploadstatus").hide();
235     $('#fileToUpload').prop('disabled', false);
236     $('#fileuploadbutton').show();
237     $("#fileuploadcancel").hide();
238     $("#fileuploadfailed").show();
239     $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
240 }
241 function cbUpload( status, fileid, err ) {
242     $('#fileToUpload').prop('disabled', false);
243     if( status=='done' ) {
244         var e = err? JSON.stringify(err): '';
245         SubmitMe( 'search', fileid, e );
246     } else {
247         $('#fileuploadbutton').show();
248         $("#fileuploadcancel").hide();
249         $("#fileuploadstatus").hide();
250         $("#fileuploadfailed").show();
251         $("#fileuploadfailed").html( _("Upload status: ") +
252             ( status=='failed'? _("Failed"):
253             ( status=='denied'? _("Denied"): status ))
254         );
255         ShowAlerts( err );
256     }
257 }
258 function ShowAlerts(err) {
259     var str = '';
260     for( var file in err ) {
261         str= str + '<p>' + file + ': ' +
262             errMESSAGES[ err[file] ] + '</p>';
263     }
264     if( str ) {
265         $('#myalerts').html(str);
266         $('#myalerts').show();
267     }
268 }
269 function CheckSearch() {
270     if( $("#term").val()=="" ) {
271         alert( _("Please enter a search term.") );
272         return false;
273     }
274     return true;
275 }
276 function SubmitMe(op, id, msg ) {
277     $("#submitter #op").val( op );
278     $("#submitter #id").val( id );
279     $("#submitter #msg").val( msg );
280     $("#submitter").submit();
281 }
282 function ClearField() {
283     [% IF plugin %]
284         $(window.opener.document).find('#[% index %]').val( '' );
285     [% END %]
286 }
287 function Choose(hashval) {
288     var res = '[% Koha.Preference('OPACBaseURL') %]';
289     res = res.replace( /\/$/, '');
290     res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
291     [% IF index %]
292         $(window.opener.document).find('#[% index %]').val( res );
293     [% END %]
294     window.close();
295 }
296 $(document).ready(function() {
297     [% IF msg %]
298         ShowAlerts( [% msg %] );
299     [% END %]
300     $("#fileuploadcancel").hide();
301 });
302 //]]>
303 </script>
304 </head>
305
306 <body id="tools_upload" class="tools">
307 [% IF !plugin %]
308     [% INCLUDE 'header.inc' %]
309     [% INCLUDE 'cat-search.inc' %]
310     [% PROCESS breadcrumbs %]
311 [% END %]
312
313 <div id="doc3" class="yui-t2">
314    <div id="bd">
315     <div id="yui-main">
316     <div class="yui-b">
317
318 <h1>Upload</h1>
319
320 <div class="dialog alert" id="myalerts" style="display:none;"></div>
321
322 [% PROCESS submitter %]
323 [% IF mode == 'new' || mode == 'deleted' %]
324     [% PROCESS form_new %]
325     [% PROCESS form_search %]
326     [% PROCESS closer %]
327 [% ELSIF mode == 'report' %]
328     [% IF uploads %]
329         <h3>Your request gave the following results:</h3>
330         [% PROCESS table_results %]
331         [% PROCESS closer %]
332     [% ELSE %]
333         <h4>Sorry, your request had no results.</h4>
334         [% PROCESS newsearch %]
335     [% END %]
336 [% END %]
337
338 </div>
339 </div>
340 </div>
341
342 [% INCLUDE 'intranet-bottom.inc' %]