View | Details | Raw Unified | Return to bug 25025
Collapse All | Expand All

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

Return to bug 25025