#9073 added control image and fixed bug with language filter

This commit is contained in:
Daniel Cebrian 2023-02-16 16:14:50 +01:00
parent 63a23799a4
commit dce5b07109
4 changed files with 53 additions and 14 deletions

View File

@ -192,7 +192,10 @@ class TipsWindow
{
global $config;
$exclude = get_parameter('exclude', '');
$userInfo = users_get_user_by_id($config['id_user']);
$profilesUser = users_get_user_profile($config['id_user']);
$language = ($userInfo['language'] !== 'default') ? $userInfo['language'] : $config['language'];
$idProfilesFilter = '0';
foreach ($profilesUser as $key => $profile) {
$idProfilesFilter .= ','.$profile['id_perfil'];
@ -211,7 +214,7 @@ class TipsWindow
$sql .= sprintf(' AND id_profile IN (%s)', $idProfilesFilter);
$sql .= ' ORDER BY CASE WHEN id_lang = "'.$config['language'].'" THEN id_lang END DESC, RAND()';
$sql .= ' ORDER BY CASE WHEN id_lang = "'.$language.'" THEN id_lang END DESC, RAND()';
$tip = db_get_row_sql($sql);
@ -419,11 +422,7 @@ class TipsWindow
{
global $config;
// Init data.
$data = [];
// Count of total records.
$count = 0;
// Catch post parameters.
$start = get_parameter('start', 0);
$length = get_parameter('length', $config['block_size']);
$orderDatatable = get_datatable_order(true);
@ -568,6 +567,14 @@ class TipsWindow
$table->data = [];
$table->data[0][0] = __('Images');
$table->data[0][1] .= html_print_div(['id' => 'inputs_images'], true);
$table->data[0][1] .= html_print_div(
[
'id' => 'notices_images',
'class' => 'invisible',
'content' => '<p>'.__('Wrong size, we recommend images of 464x260 px').'</p>',
],
true
);
$table->data[0][1] .= html_print_button(__('Add image'), 'button_add_image', false, '', '', true);
$table->data[1][0] = __('Language');
$table->data[1][1] = html_print_select_from_sql(
@ -637,7 +644,7 @@ class TipsWindow
);
$outputImagesTip .= html_print_div(
[
'class' => 'image-tip',
'class' => 'image_tip',
'content' => $imageTip,
],
true
@ -658,6 +665,14 @@ class TipsWindow
$table->data[0][1] .= $outputImagesTip;
$table->data[0][1] .= html_print_div(['id' => 'inputs_images'], true);
$table->data[0][1] .= html_print_input_hidden('images_to_delete', '{}', true);
$table->data[0][1] .= html_print_div(
[
'id' => 'notices_images',
'class' => 'invisible',
'content' => '<p>'.__('Wrong size, we recommend images of 464x260 px').'</p>',
],
true
);
$table->data[0][1] .= html_print_button(__('Add image'), 'button_add_image', false, '', '', true);
$table->data[1][0] = __('Language');
$table->data[1][1] = html_print_select_from_sql(

View File

@ -6,14 +6,15 @@ $(document).ready(function() {
$(div_image).attr("class", "action_image");
$(div_image).append(
`<input type="file" accept="image/png,image/jpeg,image/gif" name="file_${numberImages +
1}" />`
1}" onchange="checkImage(this)"/>`
);
$(div_image).append(
`<input type="image" src="images/delete.png" onclick="removeImage('file_${numberImages +
`<input type="image" src="images/delete.png" onclick="removeInputImage('file_${numberImages +
1}');" class="remove-image" value="-"/>`
);
$("#inputs_images").append(div_image);
});
$("#image-delete_image_tip1").on("click", function(e) {
e.preventDefault();
});
@ -38,7 +39,24 @@ $("#checkbox_tips_startup").ready(function() {
});
});
});
function checkImage(e) {
var maxWidth = 464;
var maxHeight = 260;
var reader = new FileReader();
reader.readAsDataURL(e.files[0]);
reader.onload = function(e) {
var img = new Image();
img.src = e.target.result;
img.onload = function() {
if (this.width !== maxWidth || this.height !== maxHeight) {
$("#notices_images").removeClass("invisible");
} else {
$("#notices_images").addClass("invisible");
}
};
};
}
function deleteImage(e, id, path) {
var imagesToDelete = JSON.parse($("#hidden-images_to_delete").val());
imagesToDelete[id] = path;
@ -52,10 +70,13 @@ function activeCarousel() {
$(".carousel .images").bxSlider({ controls: true });
}
}
function removeImage(name) {
function removeInputImage(name) {
$(`input[name=${name}]`)
.parent()
.remove();
if ($(".action_image").length === 0) {
$("#notices_images").addClass("invisible");
}
}
function render({ title, text, url, files }) {
$("#title_tip").html(title);

View File

@ -154,7 +154,7 @@ span.count-round-tip.active {
align-items: center;
margin-top: 10px;
}
.arrow-counter {
.arrow_counter {
width: 7px;
margin: 0px 5px;
}
@ -184,11 +184,14 @@ span.disable {
text-align: center;
display: flex;
}
.image-tip {
.image_tip {
display: flex;
align-items: center;
margin: 10px 0px;
}
.image-tip img {
.image_tip img {
max-width: 350px;
}
#notices_images {
color: #e63c52;
}

View File

@ -70,8 +70,8 @@ $output .= '<div class="ui-dialog-buttonset">';
// TODO Delete this buttons and use html_print_button when merge new design
$output .= '<button type="button" class="submit-cancel-tips ui-button ui-corner-all ui-widget" onclick="close_dialog()">Maybe later</button>';
$output .= '<div class="counter-tips">';
$output .= html_print_image('images/arrow-left-grey.png', true, ['class' => 'arrow-counter']);
$output .= html_print_image('images/arrow-right-grey.png', true, ['class' => 'arrow-counter']);
$output .= html_print_image('images/arrow-left-grey.png', true, ['class' => 'arrow_counter']);
$output .= html_print_image('images/arrow-right-grey.png', true, ['class' => 'arrow_counter']);
$output .= '</div>';
$output .= '<button type="button" class="submit-next-tips ui-button ui-corner-all ui-widget" onclick="next_tip()">Ok</button>';
$output .= '</div>';