Lines 2-12
Link Here
|
2 |
[% USE Asset %] |
2 |
[% USE Asset %] |
3 |
[% SET footerjs = 1 %] |
3 |
[% SET footerjs = 1 %] |
4 |
[% INCLUDE 'doc-head-open.inc' %] |
4 |
[% INCLUDE 'doc-head-open.inc' %] |
5 |
<title>Upload images › Tools › Koha</title> |
5 |
<title> |
|
|
6 |
Koha › |
7 |
Tools › |
8 |
Upload local cover image |
9 |
[% IF ( biblio ) %] |
10 |
› [% INCLUDE 'biblio-title-head.inc' %] |
11 |
[% END %] |
12 |
</title> |
6 |
[% INCLUDE 'doc-head-close.inc' %] |
13 |
[% INCLUDE 'doc-head-close.inc' %] |
7 |
<style> |
14 |
[% FILTER collapse %] |
8 |
#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; } |
15 |
<style> |
9 |
</style> |
16 |
#fileuploadstatus, |
|
|
17 |
#fileuploadfailed, |
18 |
#jobpanel, |
19 |
#jobstatus, |
20 |
#jobfailed, |
21 |
#fileuploadform, |
22 |
#upload_file_type, |
23 |
#upload_options, |
24 |
#process_images { |
25 |
display: none; |
26 |
} |
27 |
#uploadpanel { |
28 |
clear:both; |
29 |
margin-top: .9em; |
30 |
} |
31 |
#filedrag { |
32 |
background-color: #FFF; |
33 |
outline: 2px dashed #92b0b3; |
34 |
outline-offset: -10px; |
35 |
font-weight: bold; |
36 |
font-size: 130%; |
37 |
text-align: center; |
38 |
position: relative; |
39 |
padding: 50px 20px; |
40 |
margin: 1em; |
41 |
|
42 |
cursor: default; |
43 |
} |
44 |
|
45 |
#click_to_select:hover { |
46 |
color: #538200; |
47 |
cursor: pointer; |
48 |
} |
49 |
|
50 |
#filedrag.hover { |
51 |
outline-offset: -20px; |
52 |
outline-color: #c8dadf; |
53 |
background-color: #fff; |
54 |
} |
55 |
|
56 |
#messages { |
57 |
font-weight: normal; |
58 |
} |
59 |
.cover_preview { |
60 |
margin:1em; |
61 |
max-height:200px; |
62 |
max-width:200px; |
63 |
} |
64 |
.progress_panel { |
65 |
border: 0; |
66 |
border-radius: 0; |
67 |
margin: .9em; |
68 |
background-color: #FFF; |
69 |
} |
70 |
.fa-file-archive-o { |
71 |
color: #777; |
72 |
font-size: 300% |
73 |
} |
74 |
</style> |
75 |
[% END %] |
10 |
</head> |
76 |
</head> |
11 |
|
77 |
|
12 |
<body id="tools_upload-images" class="tools"> |
78 |
<body id="tools_upload-images" class="tools"> |
Lines 21-49
Link Here
|
21 |
<li> |
87 |
<li> |
22 |
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> |
88 |
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> |
23 |
</li> |
89 |
</li> |
|
|
90 |
<li> |
91 |
<a href="/cgi-bin/koha/tools/upload-cover-image.pl">Upload local cover image</a> |
92 |
</li> |
24 |
|
93 |
|
25 |
[% IF ( uploadimage ) %] |
94 |
[% IF ( uploadimage ) %] |
26 |
<li> |
|
|
27 |
<a href="/cgi-bin/koha/tools/upload-cover-image.pl">Upload local cover image</a> |
28 |
</li> |
29 |
<li> |
95 |
<li> |
30 |
<a href="#" aria-current="page"> |
96 |
<a href="#" aria-current="page"> |
31 |
Upload results |
97 |
Upload results |
32 |
</a> |
98 |
</a> |
33 |
</li> |
99 |
</li> |
|
|
100 |
[% IF ( biblionumber ) %] |
101 |
<li> |
102 |
<a href="#" aria-current="page"><em>[% INCLUDE 'biblio-title.inc' %]</em></a> |
103 |
</li> |
104 |
[% END %] |
34 |
[% ELSIF itemnumber %] |
105 |
[% ELSIF itemnumber %] |
35 |
<li> |
|
|
36 |
<a href="/cgi-bin/koha/tools/upload-cover-image.pl">Upload local cover image</a> |
37 |
</li> |
38 |
<li> |
106 |
<li> |
39 |
<a href="#" aria-current="page"> |
107 |
<a href="#" aria-current="page"> |
40 |
Upload cover for itemnumber: [% itemnumber | html %] |
108 |
Upload cover for itemnumber: [% itemnumber | html %] |
41 |
</a> |
109 |
</a> |
42 |
</li> |
110 |
</li> |
43 |
[% ELSIF biblionumber %] |
111 |
[% ELSIF biblionumber %] |
44 |
<li> |
|
|
45 |
<a href="/cgi-bin/koha/tools/upload-cover-image.pl">Upload local cover image</a> |
46 |
</li> |
47 |
<li> |
112 |
<li> |
48 |
<a href="#" aria-current="page"> |
113 |
<a href="#" aria-current="page"> |
49 |
Upload cover for biblionumber: [% biblionumber | html %] |
114 |
Upload cover for biblionumber: [% biblionumber | html %] |
Lines 64-106
Link Here
|
64 |
<div class="col-sm-10 col-sm-push-2"> |
129 |
<div class="col-sm-10 col-sm-push-2"> |
65 |
<main> |
130 |
<main> |
66 |
|
131 |
|
67 |
[% IF ( uploadimage ) %] |
|
|
68 |
<h1>Image upload results :</h1> |
69 |
<ul> |
70 |
<li>[% total | html %] images found</li> |
71 |
[% IF ( error ) %] |
72 |
<li> |
73 |
<div class="dialog alert"> |
74 |
[% IF ( error == 'UZIPFAIL' ) %] |
75 |
<p><strong>Failed to unzip archive.<br />Please ensure you are uploading a valid zip file and try again.</strong></p> |
76 |
[% ELSIF ( error == 'OPNLINK' ) %] |
77 |
<p><strong>Cannot open folder index (idlink.txt or datalink.txt) to read.<br />Please verify that it exists.</strong></p> |
78 |
[% ELSIF ( error == 'OPNIMG' ) %] |
79 |
<p><strong>Cannot process file as an image.<br />Please ensure you only upload GIF, JPEG, PNG, or XPM images.</strong></p> |
80 |
[% ELSIF ( error == 'DELERR' ) %] |
81 |
<p><strong>Unrecognized or missing field delimiter.<br />Please verify that you are using either a single quote or a tab.</strong></p> |
82 |
[% ELSIF ( error == 'DBERR' ) %] |
83 |
<p><strong>Unable to save image to database.</strong></p> |
84 |
[% ELSE %] |
85 |
<p><strong>An unknown error has occurred.<br />Please review the error log for more details.</strong></p> |
86 |
[% END %] |
87 |
</div> |
88 |
</li> |
89 |
[% END # /IF error %] |
90 |
<li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">View final record</a></li> |
91 |
<li><a href="/cgi-bin/koha/tools/tools-home.pl">Back</a></li> |
92 |
</ul> |
93 |
<hr /> |
94 |
[% END # /IF uploadimage %] |
95 |
|
96 |
[% UNLESS itemnumber || biblionumber %] |
132 |
[% UNLESS itemnumber || biblionumber %] |
97 |
<h1>Upload local cover image</h1> |
133 |
<h1>Upload local cover image</h1> |
|
|
134 |
[% ELSIF biblio %] |
135 |
<h1> |
136 |
Upload local cover image for <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]"><em>[% INCLUDE 'biblio-title.inc' %]</em></a> |
137 |
[% IF ( itemnumber ) %], Item number: [% itemnumber | html %][% END %] |
138 |
</h1> |
98 |
[% ELSIF itemnumber %] |
139 |
[% ELSIF itemnumber %] |
99 |
<h1>Upload local cover image for itemnumber: [% itemnumber | html %]</h1> |
140 |
<h1>Upload local cover image for item number: [% itemnumber | html %]</h1> |
100 |
[% ELSIF biblionumber %] |
|
|
101 |
<h1>Upload local cover image for biblionumber: [% biblionumber | html %]</h1> |
102 |
[% END %] |
141 |
[% END %] |
103 |
|
142 |
|
|
|
143 |
[% IF ( uploadimage ) %] |
144 |
<h2>Image upload results :</h2> |
145 |
<div id="upload_results"> |
146 |
[% IF ( error ) %] |
147 |
<div class="dialog alert"> |
148 |
[% IF ( error == 'UZIPFAIL' ) %] |
149 |
<p><strong>Failed to unzip archive.<br />Please ensure you are uploading a valid zip file and try again.</strong></p> |
150 |
[% ELSIF ( error == 'OPNLINK' ) %] |
151 |
<p><strong>Cannot open folder index (idlink.txt or datalink.txt) to read.<br />Please verify that it exists.</strong></p> |
152 |
[% ELSIF ( error == 'OPNIMG' ) %] |
153 |
<p><strong>Cannot process file as an image.<br />Please ensure you only upload GIF, JPEG, PNG, or XPM images.</strong></p> |
154 |
[% ELSIF ( error == 'DELERR' ) %] |
155 |
<p><strong>Unrecognized or missing field delimiter.<br />Please verify that you are using either a single quote or a tab.</strong></p> |
156 |
[% ELSIF ( error == 'DBERR' ) %] |
157 |
<p><strong>Unable to save image to database.</strong></p> |
158 |
[% ELSE %] |
159 |
<p><strong>An unknown error has occurred.<br />Please review the error log for more details.</strong></p> |
160 |
[% END %] |
161 |
</div> |
162 |
[% END # /IF error %] |
163 |
<h3>[% total | html %] images found</h3> |
164 |
<ul> |
165 |
[% FOREACH result IN results %] |
166 |
<li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% result.biblionumber | uri %]">[% result.title | html %]</a></li> |
167 |
[% END %] |
168 |
</ul> |
169 |
<hr /> |
170 |
</div> <!-- /#upload_results --> |
171 |
[% END # /IF uploadimage %] |
172 |
|
104 |
<ul> |
173 |
<ul> |
105 |
[% UNLESS itemnumber || biblionumber %] |
174 |
[% UNLESS itemnumber || biblionumber %] |
106 |
<li>Select an image file or ZIP file to upload. The tool will accept images in GIF, JPEG, PNG, and XPM formats.</li> |
175 |
<li>Select an image file or ZIP file to upload. The tool will accept images in GIF, JPEG, PNG, and XPM formats.</li> |
Lines 109-199
Link Here
|
109 |
[% END %] |
178 |
[% END %] |
110 |
</ul> |
179 |
</ul> |
111 |
|
180 |
|
112 |
<form method="post" action="/cgi-bin/koha/tools/upload-cover-image.pl" id="uploadfile" enctype="multipart/form-data"> |
181 |
<div class="row"> |
113 |
<fieldset class="rows" > |
182 |
[% IF ( cover_images ) %] |
114 |
<legend>Upload images</legend> |
183 |
<div class="col-sm-9"> |
115 |
<ol> |
184 |
[% ELSE %] |
116 |
<li> |
185 |
<div class="col-sm-12"> |
|
|
186 |
[% END %] |
187 |
|
188 |
<form method="post" action="/cgi-bin/koha/tools/upload-cover-image.pl" id="uploadfile" enctype="multipart/form-data"> |
189 |
<fieldset class="rows" > |
117 |
<div id="fileuploadform"> |
190 |
<div id="fileuploadform"> |
118 |
<label for="fileToUpload" class="required">Select the file to upload: </label> |
191 |
<label for="fileToUpload">Select the file to upload: </label> |
119 |
<input type="file" id="fileToUpload" name="fileToUpload" required="required" class="required" /> |
192 |
<input type="file" id="fileToUpload" name="fileToUpload" /> |
120 |
<span class="required">Required</span> |
|
|
121 |
</div> |
193 |
</div> |
122 |
</li> |
194 |
|
123 |
</ol> |
195 |
<div id="filedrag"> |
124 |
<fieldset class="action"><button class="submit btn btn-default">Upload file</button></fieldset> |
196 |
<a id="click_to_select" href="#">Drop files here or click to select a file</a> |
125 |
</fieldset> |
197 |
<div id="messages"></div> |
126 |
|
198 |
</div> |
127 |
<div id="uploadpanel"> |
199 |
|
128 |
<div id="fileuploadstatus" class="progress_panel">Upload progress: |
200 |
<div id="uploadpanel"> |
129 |
<progress max="100" value="0" id="fileuploadprogress"> |
201 |
<div id="fileuploadstatus" class="progress_panel">Upload progress: |
130 |
</progress> |
202 |
<progress max="100" value="0" id="fileuploadprogress"> |
131 |
<span class="fileuploadpercent">0</span>% |
203 |
</progress> |
132 |
</div> |
204 |
<span class="fileuploadpercent">0</span>% |
133 |
<div id="fileuploadfailed"></div> |
205 |
</div> |
134 |
</div> |
206 |
<div id="fileuploadfailed"></div> |
135 |
</form> <!-- /#uploadfile --> |
207 |
</div> |
136 |
|
208 |
</fieldset> |
137 |
<form method="post" id="processfile" action="/cgi-bin/koha/tools/upload-cover-image.pl" enctype="multipart/form-data"> |
209 |
</form> <!-- /#uploadfile --> |
138 |
<input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" /> |
210 |
|
139 |
<input type="hidden" name="runinbackground" id="runinbackground" value="" /> |
211 |
<form method="post" id="processfile" action="/cgi-bin/koha/tools/upload-cover-image.pl" enctype="multipart/form-data"> |
140 |
<input type="hidden" name="completedJobID" id="completedJobID" value="" /> |
212 |
<input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" /> |
141 |
[% UNLESS itemnumber || biblionumber %] |
213 |
<input type="hidden" name="runinbackground" id="runinbackground" value="" /> |
142 |
<fieldset class="rows"> |
214 |
<input type="hidden" name="completedJobID" id="completedJobID" value="" /> |
143 |
<legend>File type</legend> |
215 |
|
144 |
<ol> |
216 |
[% IF itemnumber %] |
145 |
<li class="radio"> |
217 |
<input type="hidden" id="itemnumber" name="itemnumber" value="[% itemnumber | html %]" /> |
146 |
[% IF (filetype != 'image' ) %] |
218 |
<input type="hidden" name="filetype" value="image" /> |
147 |
<input type="radio" id="zipfile" name="filetype" value="zip" checked="checked" /> |
219 |
[% ELSIF biblionumber %] |
148 |
[% ELSE %] |
220 |
<input type="hidden" id="biblionumber" name="biblionumber" value="[% biblionumber | html %]" /> |
149 |
<input type="radio" id="zipfile" name="filetype" value="zip" /> |
221 |
<input type="hidden" name="filetype" value="image" /> |
150 |
[% END %] |
222 |
[% END %] |
151 |
<label for="zipfile">ZIP file</label> |
223 |
|
152 |
</li> |
224 |
|
153 |
<li class="radio"> |
225 |
<fieldset id="upload_options" class="rows"> |
154 |
[% IF (filetype == 'image' ) %] |
226 |
<ol> |
155 |
<input type="radio" id="image" name="filetype" value="image" checked="checked" /> |
227 |
[% UNLESS itemnumber || biblionumber %] |
156 |
[% ELSE %] |
228 |
<li class="radio"> |
157 |
<input type="radio" id="image" name="filetype" value="image" /> |
229 |
[% IF (filetype != 'image' ) %] |
158 |
[% END %] |
230 |
<input type="radio" id="zipfile" name="filetype" value="zip" checked="checked" /> |
159 |
<label for="image">Image file</label> |
231 |
[% ELSE %] |
160 |
</li> |
232 |
<input type="radio" id="zipfile" name="filetype" value="zip" /> |
161 |
<li class="radio"> |
233 |
[% END %] |
162 |
[% IF ( filetype == 'image' ) %] |
234 |
<label for="zipfile">ZIP file</label> |
163 |
<span id="bibnum"> |
235 |
</li> |
164 |
[% ELSE %] |
236 |
<li class="radio"> |
165 |
<span id="bibnum" style="display: none"> |
237 |
[% IF (filetype == 'image' ) %] |
|
|
238 |
<input type="radio" id="image" name="filetype" value="image" checked="checked" /> |
239 |
[% ELSE %] |
240 |
<input type="radio" id="image" name="filetype" value="image" /> |
241 |
[% END %] |
242 |
<label for="image">Image file</label> |
243 |
</li> |
244 |
<li id="biblionumber_entry"> |
245 |
<label for="biblionumber">Bibliographic record number: </label> |
246 |
<input type="text" id="biblionumber" name="biblionumber" value="[% biblionumber | html %]" size="15" /> |
247 |
</li> |
166 |
[% END %] |
248 |
[% END %] |
167 |
<label for="biblionumber">Enter cover biblionumber: </label> |
249 |
<li class="radio"> |
168 |
<input type="text" id="biblionumber" name="biblionumber" value="[% biblionumber | html %]" size="15" /></span> |
250 |
<label for="replace"> |
169 |
</li> |
251 |
[% IF AllowMultipleCovers == 0 %] |
170 |
</ol> |
252 |
<input type="checkbox" id="replace" name="replace" value="" disabled="disabled" checked="checked" /> |
171 |
</fieldset> |
253 |
Existing covers will be replaced |
172 |
[% ELSIF itemnumber %] |
254 |
[% ELSE %] |
173 |
<input type="hidden" id="itemnumber" name="itemnumber" value="[% itemnumber | html %]" /> |
255 |
<input type="checkbox" id="replace" name="replace" value="1" /> |
174 |
<input type="hidden" name="filetype" value="image" /> |
256 |
Replace existing covers |
175 |
[% ELSIF biblionumber %] |
257 |
[% END %] |
176 |
<input type="hidden" id="biblionumber" name="biblionumber" value="[% biblionumber | html %]" /> |
258 |
</li> |
177 |
<input type="hidden" name="filetype" value="image" /> |
259 |
</ol> |
178 |
[% END %] |
260 |
</fieldset> |
179 |
<fieldset class="rows"> |
261 |
|
180 |
<legend>Options</legend> |
262 |
<fieldset id="process_images" class="action"> |
181 |
<ol> |
263 |
<button type="submit" class="btn btn-default btn-sm save_image">Process images</button> |
182 |
<li class="checkbox"> |
264 |
[% IF ( biblionumber ) %] |
183 |
[% IF AllowMultipleCovers == 0 %] |
265 |
<a class="cancel cancel_image" href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblionumber | uri %]">Cancel</a> |
184 |
<input type="checkbox" id="replace" name="replace" checked="checked" disabled="disabled" value="1" /> |
|
|
185 |
[% ELSE %] |
266 |
[% ELSE %] |
186 |
<input type="checkbox" id="replace" name="replace" value="1" /> |
267 |
<a class="cancel cancel_image" href="/cgi-bin/koha/tools/upload-cover-image.pl">Cancel</a> |
187 |
[% END %] |
268 |
[% END %] |
188 |
<label for="replace">Replace existing covers</label> |
269 |
</fieldset> |
189 |
</li> |
270 |
</form> <!-- /#processfile --> |
190 |
</ol> |
271 |
</div> <!-- /.col-sm-9/.col-sm-12 --> |
191 |
</fieldset> |
|
|
192 |
<fieldset class="action"> |
193 |
<button type="submit" class="btn btn-default btn-sm">Process images</button> |
194 |
</fieldset> |
195 |
</form> <!-- /#processfile --> |
196 |
|
272 |
|
|
|
273 |
[% IF ( cover_images.size ) %] |
274 |
<div class="col-sm-3"> |
275 |
<h3>Existing images</h3> |
276 |
<ul class="thumbnails"> |
277 |
[% FOREACH img IN cover_images %] |
278 |
[% IF img %] |
279 |
<li id="imagenumber-[% img.imagenumber | html %]" class="thumbnail"> |
280 |
<a class="show_cover" data-coverimg="[% img.imagenumber | html %]" href="/cgi-bin/koha/catalogue/imageviewer.pl?biblionumber=[% biblionumber | html %]&imagenumber=[% img.imagenumber | html %]"> |
281 |
[% IF ( imagenumber == img.imagenumber ) %] |
282 |
<img class="selected" id="thumbnail_[% img.imagenumber | html %]" src="/cgi-bin/koha/catalogue/image.pl?imagenumber=[% img.imagenumber | html %]&thumbnail=1" alt="Thumbnail" /> |
283 |
[% ELSE %] |
284 |
<img id="thumbnail_[% img.imagenumber | html %]" src="/cgi-bin/koha/catalogue/image.pl?imagenumber=[% img.imagenumber | html %]&thumbnail=1" alt="Thumbnail" /> |
285 |
[% END %] |
286 |
</a> |
287 |
<a href="#" class="remove" data-coverimg="[% img.imagenumber | html %]"><i class="fa fa-trash"></i> Delete image</a> |
288 |
</li> |
289 |
[% END # /IF img %] |
290 |
[% END # /FOREACH img %] |
291 |
</ul> <!-- /ul.thumbnails --> |
292 |
</div> <!-- /.col-sm-3 --> |
293 |
[% END # /IF images.size %] |
294 |
|
295 |
</div> <!-- /.row --> |
197 |
</main> |
296 |
</main> |
198 |
</div> <!-- /.col-sm-10.col-sm-push-2 --> |
297 |
</div> <!-- /.col-sm-10.col-sm-push-2 --> |
199 |
|
298 |
|
Lines 206-225
Link Here
|
206 |
|
305 |
|
207 |
[% MACRO jsinclude BLOCK %] |
306 |
[% MACRO jsinclude BLOCK %] |
208 |
[% Asset.js("js/tools-menu.js") | $raw %] |
307 |
[% Asset.js("js/tools-menu.js") | $raw %] |
209 |
[% Asset.js("js/file-upload.js") | $raw %] |
|
|
210 |
<script> |
308 |
<script> |
211 |
function StartUpload() { |
309 |
var interface = "[% interface | html %]"; |
212 |
if( $('#fileToUpload').prop('files').length == 0 ) return; |
310 |
var theme = "[% theme | html %]"; |
|
|
311 |
var biblionumber = "[% biblionumber | html %]"; |
312 |
$(document).ready(function(){ |
313 |
$("html").on("drop", function(e) { |
314 |
e.preventDefault(); |
315 |
e.stopPropagation(); |
316 |
}); |
317 |
|
318 |
$("#zipfile").click(function(){ |
319 |
$("biblionumber_entry").hide(); |
320 |
}); |
321 |
|
322 |
$("#image").click(function(){ |
323 |
$("#biblionumber_entry").show(); |
324 |
}); |
325 |
|
326 |
$("#uploadfile").validate({ |
327 |
submitHandler: function(form) { |
328 |
StartUpload(); |
329 |
return false; |
330 |
} |
331 |
}); |
332 |
|
333 |
$() |
334 |
|
335 |
$("#filedrag").on("click", ".cancel_image", function(){ |
336 |
$("#click_to_select").show(); |
337 |
$("#messages").html(""); |
338 |
$("#fileToUpload").prop( "disabled", false ); |
339 |
$("#process_images, #fileuploadstatus").hide(); |
340 |
return false; |
341 |
}).on("click", ".save_image", function(e){ |
342 |
e.preventDefault(); |
343 |
$("#processfile").submit(); |
344 |
}); |
345 |
|
346 |
$("html").on("drop", function(e) { |
347 |
/* Prevent the default browser action when image is dropped */ |
348 |
/* i.e. don't navigate to a view of the local image */ |
349 |
e.preventDefault(); |
350 |
e.stopPropagation(); |
351 |
}); |
352 |
|
353 |
$('#filedrag').on('dragenter dragover dragleave', function (e) { |
354 |
/* Handle various drag and drop events in "Drop files" area */ |
355 |
/* If event type is "dragover," add the "hover" class */ |
356 |
/* otherwise set no class name */ |
357 |
e.stopPropagation(); |
358 |
e.preventDefault(); |
359 |
e.target.className = (e.type == "dragover" ? "hover" : ""); |
360 |
}); |
361 |
|
362 |
$("#filedrag").click(function(){ |
363 |
/* Capture a click inside the drag and drop area */ |
364 |
/* Trigger the <input type="file"> action */ |
365 |
$("#fileToUpload").click(); |
366 |
}); |
367 |
|
368 |
// Drop |
369 |
$('#filedrag').on('drop', function (e) { |
370 |
e.stopPropagation(); |
371 |
e.preventDefault(); |
372 |
prepUpLoad(e); |
373 |
}); |
374 |
|
375 |
// file selected |
376 |
$("#fileToUpload").change(function(){ |
377 |
prepUpLoad(); |
378 |
}); |
379 |
|
380 |
$('.thumbnails .remove').on("click", function(e) { |
381 |
e.preventDefault(); |
382 |
var result = confirm(_("Are you sure you want to delete this cover image?")); |
383 |
var imagenumber = $(this).data("coverimg"); |
384 |
if ( result == true ) { |
385 |
removeLocalImage(imagenumber); |
386 |
} |
387 |
}); |
388 |
}); |
389 |
|
390 |
function prepUpLoad( event ){ |
391 |
$("#click_to_select,#upload_results").hide(); |
392 |
$("#messages").html(""); |
393 |
if( event ){ |
394 |
var file = event.originalEvent.dataTransfer.files[0]; |
395 |
} else { |
396 |
var file = $('#fileToUpload')[0].files[0]; |
397 |
} |
398 |
|
399 |
$("#fileuploadstatus, #upload_options").show(); |
400 |
var fd = new FormData(); |
401 |
fd.append('file', file); |
402 |
if( ParseFile( file ) ){ |
403 |
StartUpload( fd ); |
404 |
} |
405 |
} |
406 |
|
407 |
function StartUpload( fd ) { |
213 |
$('#uploadform button.submit').prop('disabled',true); |
408 |
$('#uploadform button.submit').prop('disabled',true); |
214 |
$("#fileuploadstatus").show(); |
|
|
215 |
$("#uploadedfileid").val(''); |
409 |
$("#uploadedfileid").val(''); |
216 |
xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload ); |
410 |
xhr= AjaxUpload( fd, $('#fileuploadprogress'), 'temp=1', cbUpload ); |
217 |
} |
411 |
} |
218 |
function cbUpload( status, fileid, errors ) { |
412 |
function cbUpload( status, fileid, errors ) { |
219 |
if( status=='done' ) { |
413 |
if( status=='done' ) { |
220 |
$("#uploadedfileid").val( fileid ); |
414 |
$("#uploadedfileid").val( fileid ); |
221 |
$('#fileToUpload').prop('disabled',true); |
415 |
$('#fileToUpload').prop('disabled',true); |
222 |
$("#processfile").show(); |
416 |
$("#process_images").show(); |
223 |
} else { |
417 |
} else { |
224 |
var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ]; |
418 |
var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ]; |
225 |
var errCode = errors[$('#fileToUpload').prop('files')[0].name].code; |
419 |
var errCode = errors[$('#fileToUpload').prop('files')[0].name].code; |
Lines 232-252
Link Here
|
232 |
$("#processfile").hide(); |
426 |
$("#processfile").hide(); |
233 |
} |
427 |
} |
234 |
} |
428 |
} |
235 |
$(document).ready(function(){ |
429 |
|
236 |
$("#processfile").hide(); |
430 |
function AjaxUpload ( formData, progressbar, xtra, callback ) { |
237 |
$("#zipfile").click(function(){ |
431 |
var xhr= new XMLHttpRequest(); |
238 |
$("#bibnum").hide(); |
432 |
var url= '/cgi-bin/koha/tools/upload-file.pl?' + xtra; |
239 |
}); |
433 |
progressbar.val( 0 ); |
240 |
$("#image").click(function(){ |
434 |
progressbar.next('.fileuploadpercent').text( '0' ); |
241 |
$("#bibnum").show(); |
435 |
xhr.open('POST', url, true); |
242 |
}); |
436 |
xhr.upload.onprogress = function (e) { |
243 |
$("#uploadfile").validate({ |
437 |
var p = Math.round( (e.loaded/e.total) * 100 ); |
244 |
submitHandler: function(form) { |
438 |
progressbar.val( p ); |
245 |
StartUpload(); |
439 |
progressbar.next('.fileuploadpercent').text( p ); |
246 |
return false; |
440 |
} |
|
|
441 |
xhr.onload = function (e) { |
442 |
var data = JSON.parse( xhr.responseText ); |
443 |
if( data.status == 'done' ) { |
444 |
progressbar.val( 100 ); |
445 |
progressbar.next('.fileuploadpercent').text( '100' ); |
446 |
} |
447 |
callback( data.status, data.fileid, data.errors ); |
448 |
} |
449 |
xhr.onerror = function (e) { |
450 |
// Probably only fires for network failure |
451 |
alert(_("An error occurred while uploading.") ); |
452 |
} |
453 |
xhr.send( formData ); |
454 |
return xhr; |
455 |
} |
456 |
|
457 |
// output file information |
458 |
function ParseFile(file) { |
459 |
var valid = true; |
460 |
if (file.type.indexOf("image") == 0) { |
461 |
/* If the uploaded file is an image, show it */ |
462 |
var reader = new FileReader(); |
463 |
reader.onload = function(e) { |
464 |
Output( |
465 |
'<p><img class="cover_preview" src="' + e.target.result + '" /></p>' |
466 |
); |
467 |
} |
468 |
$("#biblionumber_entry").show().find("input,label").addClass("required").prop("required", true ); |
469 |
$("#image").prop("checked", true ).change(); |
470 |
$("#zipfile").prop("checked", false ); |
471 |
reader.readAsDataURL(file); |
472 |
} else if( file.type.indexOf("zip") > 0) { |
473 |
Output( |
474 |
'<p><i class="fa fa-file-archive-o" aria-hidden="true"></i></p>' |
475 |
); |
476 |
$("#biblionumber_entry").hide(); |
477 |
$("#image").prop("checked", false ); |
478 |
$("#zipfile").prop("checked", true ); |
479 |
} else { |
480 |
Output( |
481 |
'<div class="dialog alert"><strong>' + _("Error:") + ' </strong> ' + _("This tool only accepts ZIP files or GIF, JPEG, PNG, or XPM images.") + '</div>' |
482 |
); |
483 |
valid = false; |
484 |
resetForm(); |
485 |
} |
486 |
|
487 |
Output( |
488 |
"<p>" + _("File name:") + " <strong>" + file.name + "</strong><br />" + |
489 |
_("File type:") + " <strong>" + file.type + "</strong><br />" + |
490 |
_("File size:") + " <strong>" + convertSize( file.size ) + "</strong>" |
491 |
); |
492 |
return valid; |
493 |
} |
494 |
|
495 |
// output information |
496 |
function Output(msg) { |
497 |
var m = document.getElementById("messages"); |
498 |
m.innerHTML = msg + m.innerHTML; |
499 |
} |
500 |
|
501 |
// Bytes conversion |
502 |
function convertSize(size) { |
503 |
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; |
504 |
if (size == 0) return '0 Byte'; |
505 |
var i = parseInt(Math.floor(Math.log(size) / Math.log(1024))); |
506 |
return Math.round(size / Math.pow(1024, i), 2) + ' ' + sizes[i]; |
507 |
} |
508 |
|
509 |
function removeLocalImage(imagenumber) { |
510 |
var thumbnail = $("#imagenumber-" + imagenumber ); |
511 |
var copy = thumbnail.html(); |
512 |
thumbnail.find("img").css("opacity", ".2"); |
513 |
thumbnail.find("a.remove").html("<img style='display:inline-block' src='" + interface + "/" + theme + "/img/spinner-small.gif' alt='' />"); |
514 |
|
515 |
$.ajax({ |
516 |
url: "/cgi-bin/koha/svc/cover_images?action=delete&biblionumber=" + biblionumber + "&imagenumber=" + imagenumber, |
517 |
success: function(data) { |
518 |
$(data).each( function() { |
519 |
if ( this.deleted == 1 ) { |
520 |
location.href="/cgi-bin/koha/tools/upload-cover-image.pl?biblionumber=" + biblionumber; |
521 |
} else { |
522 |
thumbnail.html( copy ); |
523 |
alert(_("An error occurred on deleting this image")); |
524 |
} |
525 |
}); |
526 |
}, |
527 |
error: function(data) { |
528 |
thumbnail.html( copy ); |
529 |
alert(_("An error occurred on deleting this image")); |
247 |
} |
530 |
} |
248 |
}); |
531 |
}); |
249 |
}); |
532 |
} |
|
|
533 |
|
534 |
function resetForm(){ |
535 |
$("#uploadpanel,#upload_options,#process_images").hide(); |
536 |
$("#click_to_select").show(); |
537 |
} |
250 |
</script> |
538 |
</script> |
251 |
[% END %] |
539 |
[% END %] |
252 |
|
540 |
|