Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#796 [JS] fix: use img size instead of canvas size #1006

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions admin/setup.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2022-2023 EVARISK <[email protected]>
/* Copyright (C) 2022-2024 EVARISK <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,7 +18,7 @@
/**
* \file admin/setup.php
* \ingroup saturne
* \brief Saturne setup page.
* \brief Saturne setup page
*/

// Load Saturne environment
Expand All @@ -30,19 +30,22 @@
die('Include of saturne main fails');
}


// Libraries
// Load Dolibarr libraries
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';

// Load Saturne libraries
require_once __DIR__ . '/../lib/saturne.lib.php';

// Global variables definitions
global $db, $langs, $user;
global $conf, $db, $langs, $user;

// Load translation files required by the page
saturne_load_langs(['admin']);

// Parameters
// Initialize view objects
$form = new Form($db);

// Get parameters
$action = GETPOST('action', 'alpha');
$value = GETPOST('value', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
Expand All @@ -51,6 +54,21 @@
$permissiontoread = $user->rights->saturne->adminpage->read;
saturne_check_access($permissiontoread);

/*
* Actions
*/

if ($action == 'update_settings_config') {
$mediaResolution = GETPOST('mediaResolution', 'alpha');
$result = dolibarr_set_const($db, 'SATURNE_MEDIA_RESOLUTION_USED', $mediaResolution, 'chaine', 0, '', $conf->entity);

if ($result > 0) {
setEventMessage($langs->trans('SavedConfig'));
} else {
setEventMessage($langs->trans('ErrorSavedConfig'), 'errors');
}
}

/*
* View
*/
Expand All @@ -71,6 +89,9 @@

print load_fiche_titre($langs->trans('GeneralConfig'), '', '');

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" name="settings_form">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="update_settings_config">';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
Expand Down Expand Up @@ -120,10 +141,18 @@
print $langs->trans('UseFastUploadImprovement');
print '</td><td>';
print $langs->transnoentities('UseFastUploadImprovementDescription');
if (getDolGlobalInt('SATURNE_USE_FAST_UPLOAD_IMPROVEMENT')) {
$mediaResolution = ['sd-720x480' => 'SD (720x480 pixels)', 'hd-1280x720' => 'HD (1280x720 pixels)', 'fullHD-1920x1080' => 'Full HD (1920x1080 pixels)', 'ultraHD4k-3840x2160' => 'Ultra HD 4K (3840x2160 pixels)', 'ultraHD8k-7680x4320' => 'Ultra HD 8K (7680x4320 pixels)'];
print '<span class="marginrightonly">' . $langs->trans('MediaResolutionDescription') . '</span>';
print $form::selectarray('mediaResolution', $mediaResolution, getDolGlobalString('SATURNE_MEDIA_RESOLUTION_USED', 'fullHD-1920x1080'));
print '<input type="submit" class="button" name="save" value="' . $langs->trans('Save') . '">';
}
print '</td><td class="center">';
print ajax_constantonoff('SATURNE_USE_FAST_UPLOAD_IMPROVEMENT');
print '</td></tr>';
print '</table>';
print '</div>';
print '</form>';

// Page end
print dol_get_fiche_end();
Expand Down
1 change: 1 addition & 0 deletions core/modules/modSaturne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public function __construct($db)
$i++ => ['SATURNE_SHOW_COMPANY_LOGO', 'integer', 0, '', 0, 'current'],
$i++ => ['SATURNE_USE_CAPTCHA', 'integer', 0, '', 0, 'current'],
$i++ => ['SATURNE_USE_ALL_EMAIL_MODE', 'integer', 1, '', 0, 'current'],
$i++ => ['SATURNE_MEDIA_RESOLUTION_USED', 'chaine', 'fullHD-1920x1080', '', 0, 'current'],

// CONST DOLIBARR
$i => ['MAIN_ALLOW_SVG_FILES_AS_IMAGES', 'integer', 1, '', 0, 'current']
Expand Down
8 changes: 5 additions & 3 deletions core/tpl/medias/media_editor_modal.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@
<div class="modal-upload-image">
<input type="hidden" name="token" value="<?php echo newToken(); ?>">
<div class="wpeo-modal modal-upload-image" id="modal-upload-image">
<input type="hidden" class="fast-upload-options">
<?php $mediaResolution = explode('-', getDolGlobalString('SATURNE_MEDIA_RESOLUTION_USED'));
$mediaResolution = explode('x', $mediaResolution[1]); ?>
<input type="hidden" class="fast-upload-options" data-image-resolution-width="<?php echo $mediaResolution[0]; ?>" data-image-resolution-height="<?php echo $mediaResolution[1]; ?>">
<div class="modal-container wpeo-modal-event">
<!-- Modal-Header-->
<div class="modal-header">
<h2 class="modal-title"><?php echo $langs->trans('Image'); ?></h2>
<div class="modal-close"><i class="fas fa-2x fa-times"></i></div>
</div>
<!-- Modal-ADD Image Content-->
<div class="modal-content" id="#modalContent" style="height: 75%;">
<div class="modal-content" id="#modalContent">
<div class="canvas-container">
<canvas id="canvas" style="border: #0b419b solid 2px; width: 100%;"></canvas>
<canvas id="canvas" style="border: #0b419b solid 2px;"></canvas>
</div>
</div>
<!-- Modal-Footer-->
Expand Down
11 changes: 7 additions & 4 deletions js/modules/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,13 @@ window.saturne.media.drawImageOnCanvas = function(event) {
img.src = event.target.result;
window.saturne.media.img = event;
img.onload = function() {
let canvasWidth = $(window.saturne.media.canvas).width();
let canvasHeight = $(window.saturne.media.canvas).height();
window.saturne.media.canvas.width = canvasWidth;
window.saturne.media.canvas.height = canvasHeight;
if (img.width >= $('.fast-upload-options').data('image-resolution-width')) {
window.saturne.media.canvas.width = $('.fast-upload-options').data('image-resolution-width');
window.saturne.media.canvas.height = $('.fast-upload-options').data('image-resolution-height');
} else {
window.saturne.media.canvas.width = img.width;
window.saturne.media.canvas.height = img.height;
}
context.drawImage(img, 0, 0, window.saturne.media.canvas.width, window.saturne.media.canvas.height);
};

Expand Down
2 changes: 1 addition & 1 deletion js/saturne.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions langs/en_US/saturne.lang
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ UseAllEmailMode = Use of all email configuration modes
UseAllEmailModeDescription = Allow the use of all email configuration modes by default, only SMTP mode is allowed
UseFastUploadImprovement = Improved fast image loading
UseFastUploadImprovementDescription = Activate this option to improve image loading speed <br> Option available : <ul><li>Image rotation</li><li>Drawing on the image</li><li>Saving the image on a reduced format</li></ul>
MediaResolutionDescription = Selecting image resolution
SignaturePublicInterfaceForbidden = No access to the public signature interface
ShowSpecimen = See signatures on specimen documents
ShowSpecimenDescription = Allows viewing of signatures on specimen documents
Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/saturne.lang
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ UseAllEmailMode = Utilisation de tous les modes de configura
UseAllEmailModeDescription = Autorise l'utilisation de tous les modes de configuration des emails par défaut, seul le mode SMTP est autorisé
UseFastUploadImprovement = Utilisation chargement rapide d'image amélioré
UseFastUploadImprovementDescription = Activez cette option pour améliorer le chargement rapide d'image <br> Option disponible : <ul><li>Rotation d'image</li><li>Dessin sur l'image</li><li>Enregistrement de l'image sur un format réduit</li></ul>
MediaResolutionDescription = Sélection de la résolution des images
SignaturePublicInterfaceForbidden = Accès interdit à l'interface publique de signature
ObjectVisibleDescription = Afficher le champ %s
ShowSignatureSpecimen = Voir les signatures sur les documents specimens
Expand Down