Skip to content

Commit 2cb5ff4

Browse files
committed
Change function to event
1 parent 2449972 commit 2cb5ff4

File tree

3 files changed

+101
-77
lines changed

3 files changed

+101
-77
lines changed

imcger/imgupload/adm/style/acp_imgupload.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
Image upload use ImageMagick
33
------------------------------------- */
44

5-
function imcgerImgInlineDisabled() {
5+
$('input[name=img_create_thumbnail]').on('change', function () {
66
if ($('input[name=img_create_thumbnail]:checked').last().val() == 1) {
77
$('input[name=imcger_imgupload_image_inline]').prop('disabled', false);
88
} else {
99
$('input[name=imcger_imgupload_image_inline]').attr('type') == 'radio' ?
1010
$('input[name=imcger_imgupload_image_inline]').last().click() : $('input[name=imcger_imgupload_image_inline]').prop('checked', false);
1111
$('input[name=imcger_imgupload_image_inline]').prop('disabled', true);
1212
}
13-
}
13+
});
14+
15+
$('input[name=imcger_imgupload_image_inline]').trigger('change');
1416

15-
$('input[name=img_create_thumbnail]').on('click', imcgerImgInlineDisabled);
16-
imcgerImgInlineDisabled();

imcger/imgupload/controller/save_rotated_img_controller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public function __construct(
8787
*
8888
* @var int attach_id contain attach id
8989
* @var int img_rotate_deg contain rotate degree
90+
* @var int creation_time creation time of token
91+
* @var string form_token form token
9092
*
9193
* @return array Json arry with status, old and new attach id or error message
9294
*/
@@ -114,11 +116,11 @@ public function save_image()
114116
$this->json_response(5, $ext_display_name, $this->language->lang('FORM_INVALID'));
115117
}
116118

117-
// Get variable
119+
// Get variable, accept only integer
118120
$img_attach_id = intval($this->request->variable('attach_id', ''));
119121
$img_rotate_deg = intval($this->request->variable('img_rotate_deg', ''));
120122

121-
if (!$img_attach_id || !$img_rotate_deg)
123+
if (!$img_attach_id || $img_rotate_deg < 1 || $img_rotate_deg > 360)
122124
{
123125
$this->json_response(5, $ext_display_name, $this->language->lang('IUL_WRONG_PARAM'));
124126
}

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

Lines changed: 93 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{% if S_SHOW_ATTACH_BOX and FILTERS %}
22
{% INCLUDECSS '@imcger_imgupload/imgupload.css' %}
33
<script>
4+
5+
/**
6+
* imcger object for pphpBB.
7+
*/
8+
if (typeof imcger != 'object') {
9+
var imcger = {};
10+
}
11+
412
(function($) { // Avoid conflicts with other libraries
513

614
'use strict';
715

8-
/**
9-
* imcger objects for pphpBB attachment upload.
10-
*/
11-
if (typeof imcger != 'object') {
12-
var imcger = {};
13-
}
14-
16+
// imcger object for pphpBB extension Image upload use ImageMagick
1517
imcger.imgUpload = {};
1618

1719
/**
@@ -99,6 +101,13 @@
99101
imgOrientationIndex: [],
100102
imgOrientationValue: [],
101103

104+
/**
105+
* Subroutine from rotateRight() and rotateLeft()
106+
*
107+
* @param int attach_id attach id from image
108+
* @param int deg angle to rotated
109+
* @param bool clockwise true rotated clockwise
110+
*/
102111
rotate: function(attach_id, deg, clockwise) {
103112
let $image = $('#img-' + attach_id),
104113
deg_start, deg_ziel;
@@ -122,6 +131,11 @@
122131
});
123132
},
124133

134+
/**
135+
* Rotate the image clockwiese
136+
*
137+
* @param int attach_id attach id from attach image
138+
*/
125139
rotateRight: function(attach_id) {
126140
let index = 0;
127141

@@ -140,6 +154,11 @@
140154
this.rotate(attach_id, this.imgOrientationValue[index], true);
141155
},
142156

157+
/**
158+
* Rotate the image anticlockwiese
159+
*
160+
* @param int attach_id attach id from attach image
161+
*/
143162
rotateLeft: function(attach_id) {
144163
let index = 0;
145164

@@ -158,76 +177,79 @@
158177

159178
this.rotate(attach_id, this.imgOrientationValue[index], false);
160179
},
161-
}
162-
163-
/**
164-
* Send a request to the Server to save the rotate image
165-
*
166-
* @param int attach_id attach id from attach image
167-
* @param element button submit button
168-
*/
169-
imcger.imgUpload.saveImg = function(attach_id, button) {
170-
let index = 0;
171-
172-
if (imcger.imgUpload.image.imgOrientationIndex.includes(attach_id)) {
173-
index = imcger.imgUpload.image.imgOrientationIndex.indexOf(attach_id);
174-
} else {
175-
return;
176-
}
177-
178-
if (!imcger.imgUpload.image.imgOrientationValue[index]) {
179-
return;
180-
}
181-
182-
const url = '{{ U_IUL_SAVE_IMAGE }}',
183-
requestData = 'attach_id=' + attach_id +
184-
'&img_rotate_deg=' + imcger.imgUpload.image.imgOrientationValue[index] +
185-
'&creation_time=' + $('input[name="creation_time"]').val() +
186-
'&form_token=' + $('input[name="form_token"]').val();
187180

188-
let ajaxReq = $.ajax(url, {
189-
// The data to send
190-
data: requestData,
191-
192-
// Whether this is a POST or GET request
193-
type: 'POST',
181+
/**
182+
* Send a request to the Server to save the rotate image
183+
*
184+
* @param int attach_id attach id from attach image
185+
* @param element button submit button
186+
*/
187+
saveImg: function(attach_id, button) {
188+
let index = 0;
194189

195-
// The type of data we expect back
196-
dataType: "json",
190+
if (this.imgOrientationIndex.includes(attach_id)) {
191+
index = this.imgOrientationIndex.indexOf(attach_id);
192+
} else {
193+
return;
194+
}
197195

198-
// Set a timeout (in milliseconds) for the request
199-
timeout: 5000,
196+
if (!this.imgOrientationValue[index]) {
197+
return;
198+
}
200199

201-
// Code to run before the request is send
202-
beforeSend: function(xhr, settings) {
203-
$(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw');
204-
$('.imcger-iupl-button button').attr('disabled', true).css('cursor','not-allowed');
205-
},
206-
});
200+
const url = '{{ U_IUL_SAVE_IMAGE }}',
201+
requestData = 'attach_id=' + attach_id +
202+
'&img_rotate_deg=' + this.imgOrientationValue[index] +
203+
'&creation_time=' + $('input[name="creation_time"]').val() +
204+
'&form_token=' + $('input[name="form_token"]').val();
205+
206+
let ajaxReq = $.ajax({
207+
// The url of the request
208+
url: url,
209+
210+
// The data to send
211+
data: requestData,
212+
213+
// Whether this is a POST or GET request
214+
type: 'POST',
215+
216+
// The type of data we expect back
217+
dataType: "json",
218+
219+
// Set a timeout (in milliseconds) for the request
220+
timeout: 10000,
221+
222+
// Code to run before the request is send
223+
beforeSend: function(xhr, settings) {
224+
$(button).find('>:first-child').attr('class', 'icon fa-refresh fa-spin fa-fw');
225+
$('.imcger-iupl-button button').attr('disabled', true).css('cursor','not-allowed');
226+
},
227+
});
207228

208-
// Code to run if the request succeeds (is done);
209-
ajaxReq.done(function(json) {
210-
if (json.status < 3) {
211-
imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId);
212-
imcger.imgUpload.image.imgOrientationValue[index] = 0;
213-
} else if (json.status == 3) {
214-
window.location.assign(window.location.href.replace(window.location.hash, ''));
215-
} else {
216-
phpbb.alert(json.title, json.message);
217-
}
218-
});
229+
// Code to run if the request succeeds (is done);
230+
ajaxReq.done(function(json) {
231+
if (json.status < 3) {
232+
imcger.imgUpload.updateAttId(json.oldAttachId, json.newAttachId);
233+
imcger.imgUpload.image.imgOrientationValue[index] = 0;
234+
} else if (json.status == 3) {
235+
window.location.assign(window.location.href.replace(window.location.hash, ''));
236+
} else {
237+
phpbb.alert(json.title, json.message);
238+
}
239+
});
219240

220-
// Code to run if the request fails
221-
ajaxReq.fail(function(xhr, status, errorThrown) {
222-
phpbb.alert('{{ IMGUPLOAD_TITLE }}', '{{ lang("IUL_REQUEST_ERROR")|e("js") }}<br>' +
223-
' Status: ' + status + 'Error: ' + errorThrown);
224-
});
241+
// Code to run if the request fails
242+
ajaxReq.fail(function(xhr, status, errorThrown) {
243+
phpbb.alert('{{ IMGUPLOAD_TITLE }}', '{{ lang("IUL_REQUEST_ERROR")|e("js") }}<br>' +
244+
' Status: ' + status + 'Error: ' + errorThrown);
245+
});
225246

226-
// Code to run regardless of success or failure;
227-
ajaxReq.always(function(xhr, status) {
228-
$(button).find('>:first-child').attr('class', 'icon fa-save fa-fw');
229-
$('.imcger-iupl-button button').attr('disabled', false).css('cursor','auto');
230-
});
247+
// Code to run regardless of success or failure;
248+
ajaxReq.always(function(xhr, status) {
249+
$(button).find('>:first-child').attr('class', 'icon fa-save fa-fw');
250+
$('.imcger-iupl-button button').attr('disabled', false).css('cursor','auto');
251+
});
252+
}
231253
}
232254

233255
/**
@@ -290,7 +312,7 @@
290312
$('#file-list').on('click', '.save-image', function(e) {
291313
let attachId = $(this).parents('.attach-row').attr('data-attach-id');
292314

293-
imcger.imgUpload.saveImg(attachId, this);
315+
imcger.imgUpload.image.saveImg(attachId, this);
294316
e.preventDefault();
295317
});
296318

0 commit comments

Comments
 (0)