Skip to content

Commit d27e356

Browse files
committed
Update new files size
1 parent 1f8cb1d commit d27e356

File tree

2 files changed

+25
-41
lines changed

2 files changed

+25
-41
lines changed

imcger/imgupload/controller/save_rotated_img_controller.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class save_rotated_img_controller
4646
protected $php_ext;
4747

4848
/**
49+
* Constructor for ajax controller
50+
*
4951
* @param \phpbb\config\config $config
5052
* @param \phpbb\user $user
5153
* @param \phpbb\request\request $request
@@ -93,7 +95,7 @@ public function __construct(
9395
* @var int creation_time creation time of token
9496
* @var string form_token form token
9597
*
96-
* @return array Json arry with status, old and new attach id or error message
98+
* @return array Json arry with status, old and new attach id, new file size or error message
9799
*/
98100
public function save_image()
99101
{
@@ -215,6 +217,7 @@ private function rotate_image($path, $deg)
215217
* @param string $message Messagebox message
216218
* @param int $old_attach_id Previous attachment id
217219
* @param int $new_attach_id New attachment id
220+
* @param int $file_size New file size
218221
*
219222
* @return string $json
220223
*/

imcger/imgupload/styles/all/template/event/overall_footer_body_after.html

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,17 @@
141141
},
142142

143143
/**
144-
* Subroutine for converting the file size into a string
144+
* Converting the file size into a string and update the row
145145
*
146+
* @param int attach_id attach id from image
146147
* @param int fileSize file size in byte
147-
*
148-
* @return string strFileSize file size as byte, KiB or MiB
149148
*/
150-
sizeToString: function(fileSize) {
149+
updateImgFileSize: function(attach_id, fileSize) {
151150
let strFileSize = '';
152151

153-
fileSize = parseInt(fileSize);
152+
if (isNaN(fileSize)) {
153+
return;
154+
}
154155

155156
if (fileSize < 1024) {
156157
strFileSize = fileSize + ' {{ lang("BYTES_SHORT")|e("js") }}';
@@ -160,7 +161,9 @@
160161
strFileSize = Math.round(fileSize / 10485.76) / 100 + ' {{ lang("MIB")|e("js") }}';
161162
}
162163

163-
return(strFileSize);
164+
if (strFileSize) {
165+
$('.attach-row[data-attach-id="' + attach_id + '"] .file-size').html(strFileSize);
166+
}
164167
},
165168

166169
/**
@@ -236,22 +239,11 @@
236239
'&form_token=' + $('input[name="form_token"]').val();
237240

238241
let ajaxReq = $.ajax({
239-
// The url of the request
240242
url: url,
241-
242-
// The data to send
243243
data: requestData,
244-
245-
// Whether this is a POST or GET request
246244
type: 'POST',
247-
248-
// The type of data we expect back
249245
dataType: "json",
250-
251-
// Set a timeout (in milliseconds) for the request
252246
timeout: 10000,
253-
254-
// Code to run before the request is send
255247
beforeSend: function(xhr, settings) {
256248
$(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw');
257249
$('.imcger-iupl-button button').prop('disabled', true).css('cursor','not-allowed');
@@ -269,15 +261,7 @@
269261
if (response.status < 3) {
270262
imcger.imgUpload.updateAttId(response.oldAttachId, response.newAttachId);
271263
imcger.imgUpload.image.imgOrientationValue[index] = 0;
272-
273-
// Update row with new image size
274-
if (response.fileSize) {
275-
let strFileSize = imcger.imgUpload.image.sizeToString(response.fileSize);
276-
277-
if (strFileSize) {
278-
$('.attach-row[data-attach-id="' + response.newAttachId + '"] .file-size').html(strFileSize);
279-
}
280-
}
264+
imcger.imgUpload.image.updateImgFileSize(response.newAttachId, response.fileSize);
281265

282266
// Display a message when a warning occurs
283267
if (response.message) {
@@ -322,24 +306,19 @@
322306
});
323307

324308
ajaxReq.done(function(response, status, xhr) {
325-
let strFileSize = imcger.imgUpload.image.sizeToString(xhr.getResponseHeader('Content-Length'));
326-
327-
if (strFileSize) {
328-
$('.attach-row[data-attach-id="' + attach_id + '"] .file-size').html(strFileSize);
329-
}
309+
imcger.imgUpload.image.updateImgFileSize(attach_id, xhr.getResponseHeader('Content-Length'));
330310
});
331311
},
332312
}
333313

334314
/**
335315
* Remove attachment in preview when insert as img BBcode in message
336316
* AddOn for editor.js
337-
*
338-
* @var array notDisplayedAttachments Attachments that insert in the message
339-
* @var bool notDisplayAttachmentBox Don't show any attachment
340317
*/
341318
imcger.imgUpload.showAttachImage = function() {
319+
// Attachments that insert in the message
342320
const notDisplayedAttachments = {{ IUL_NOT_DISPLAYED_ATTACHMENTS }},
321+
// If true don't show the attachment box
343322
notDisplayAttachmentBox = {{ IUL_NOT_DISPLAY_ATTACHMENTBOX }};
344323

345324
// Return when no attachments present
@@ -449,8 +428,6 @@
449428
/**
450429
* Update the relevant elements and hidden data for
451430
* an attachment when page load.
452-
*
453-
* @param void
454431
*/
455432
imcger.imgUpload.updateRow = function() {
456433
$('.file-name.ellipsis-text a').each(function() {
@@ -513,8 +490,10 @@
513490
$('#img-' + attach_id).on('load', function(e) {
514491
let imgHeight = maxImgHeight;
515492

516-
// The $(this) element work not all time
517-
if (e.target.height < e.target.width) {
493+
// $(this).height() don't work all time
494+
if (e.target.height < maxImgHeight) {
495+
imgHeight = e.target.height;
496+
} else if (e.target.height < e.target.width) {
518497
imgHeight = maxImgHeight / e.target.width * e.target.height;
519498
}
520499

@@ -598,8 +577,10 @@
598577
$('#img-' + attach.attach_id).on('load', function(e) {
599578
let imgHeight = maxImgHeight;
600579

601-
// The $(this) element work not all time
602-
if (e.target.height < e.target.width) {
580+
// $(this).height() don't work all time
581+
if (e.target.height < maxImgHeight) {
582+
imgHeight = e.target.height;
583+
} else if (e.target.height < e.target.width) {
603584
imgHeight = maxImgHeight / e.target.width * e.target.height;
604585
}
605586

0 commit comments

Comments
 (0)