28require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
37require_once __DIR__ .
'/../lib/quickmemo.lib.php';
38require_once __DIR__ .
'/../class/memo.class.php';
42$langs->loadLangs(array(
"admin",
"quickmemo"));
46$hookmanager->initHooks(array(
'quickmemosetup',
'globalsetup'));
49$action =
GETPOST(
'action',
'aZ09');
50$backtopage =
GETPOST(
'backtopage',
'alpha');
51$modulepart =
GETPOST(
'modulepart',
'aZ09');
53$value =
GETPOST(
'value',
'alpha');
54$label =
GETPOST(
'label',
'alpha');
55$scandir =
GETPOST(
'scan_dir',
'alpha');
70if (!class_exists(
'FormSetup')) {
71 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
75$item = $formSetup->newItem(
'QUICKMEMO_COLORS_PRESET');
82$item->fieldInputCallBack =
function ($item) {
85 $item->fieldInputOverride =
'
86 <div class="color-manager">
87 <div class="controls">
88 <input type="color" id="colorPicker" list="predefinedColors">
89 <datalist id="predefinedColors">
90 <option value="#fff8a6">
91 <option value="#ffd6d6">
92 <option value="#d6ffd9">
93 <option value="#d6e6ff">
94 <option value="#f3d6ff">
95 <option value="#ffffff">
96 <option value="#f5f5f5">
98 <button title="'.$langs->trans(
'Add').
'" class="btn-low-emphasis --btn-icon" type="button" id="addColor"><span class="fa fa-plus"></span></button>
101 <div class="palette" id="palette"></div>
103 <div class="colors-container" id="colorsContainer"></div>
105 <input type="hidden" name="QUICKMEMO_COLORS_PRESET" id="colorsInput">
107 return $item->fieldInputOverride;
112$formSetup->newItem(
'QUICKMEMO_AUTO_RESIZE_FONT_SIZE_SECTION')->setAsTitle();
114$formSetup->newItem(
'QUICKMEMO_DISABLE_AUTO_RESIZE_FONT_SIZE')->setAsYesNo();
115$item = $formSetup->newItem(
'QUICKMEMO_AUTO_RESIZE_MIN_FONT_SIZE');
116$item->defaultFieldValue =
'1';
123$item->fieldInputCallBack =
function ($item) {
124 $item->fieldInputOverride =
'
127 class="quickmemo-fontsize-config"
128 id="autoResizeFontMin"
129 name="QUICKMEMO_AUTO_RESIZE_MIN_FONT_SIZE"
130 min="0.5" max="3" step="0.05"
133 <div id="previewMinText" class="example-of-memo-text-size">Lorem ipsum dolor sit amet</div>
135 return $item->fieldInputOverride;
138$item = $formSetup->newItem(
'QUICKMEMO_AUTO_RESIZE_MAX_FONT_SIZE');
139$item->defaultFieldValue =
'1.4';
146$item->fieldInputCallBack =
function ($item) {
147 $item->fieldInputOverride =
'
150 id="autoResizeFontMax"
151 name="QUICKMEMO_AUTO_RESIZE_MAX_FONT_SIZE"
152 class="quickmemo-fontsize-config"
153 min="0.5" max="3" step="0.05"
157 <div id="previewMaxText" class="example-of-memo-text-size">Lorem ipsum dolor sit amet</div>
161 return $item->fieldInputOverride;
165$setupnotempty += count($formSetup->items);
174if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
175 $formSetup->saveConfFromPost();
178include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
193$title =
"QuickMemoSetup";
195llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'', [
'quickmemo/css/setup.css'],
'',
'mod-quickmemo page-admin');
200<script nonce=
"<?php print getNonce(); ?>">
201document.addEventListener(
'DOMContentLoaded',
function () {
208 const colorPicker = document.getElementById(
'colorPicker');
209 const addColorBtn = document.getElementById(
'addColor');
210 const colorsContainer = document.getElementById(
'colorsContainer');
211 const colorsInput = document.getElementById(
'colorsInput');
213 if (!colorPicker || !addColorBtn || !colorsContainer || !colorsInput) {
219 let draggedElement =
null;
221 const placeholder = document.createElement(
'div');
222 placeholder.className =
'color-placeholder';
224 function updateHiddenInput() {
225 colorsInput.value = colors.join(
',');
228 function normalize(color) {
229 return color.toLowerCase();
232 function rebuildColorsFromDOM() {
233 colors = Array.from(colorsContainer.querySelectorAll(
'.color-badge'))
234 .map(el => el.dataset.color);
238 function addColor(color) {
239 color = normalize(color);
240 if (colors.includes(color))
return;
244 const badge = document.createElement(
'div');
245 badge.className =
'color-badge';
246 badge.style.backgroundColor = color;
247 badge.dataset.color = color;
248 badge.draggable =
true;
250 const removeBtn = document.createElement(
'span');
251 removeBtn.textContent =
'×';
253 removeBtn.addEventListener(
'click',
function(e) {
256 rebuildColorsFromDOM();
259 badge.addEventListener(
'dragstart',
function () {
260 draggedElement = badge;
261 badge.classList.add(
'dragging');
263 placeholder.style.width = badge.offsetWidth +
'px';
264 placeholder.style.height = badge.offsetHeight +
'px';
267 badge.style.display =
'none';
271 badge.addEventListener(
'dragend',
function () {
272 badge.classList.remove(
'dragging');
273 badge.style.display =
'';
274 placeholder.remove();
275 draggedElement =
null;
278 colorsContainer.addEventListener(
'dragover',
function (e) {
281 const afterElement = getDragAfterElement(colorsContainer, e.clientX);
282 if (afterElement ==
null) {
283 colorsContainer.appendChild(placeholder);
285 colorsContainer.insertBefore(placeholder, afterElement);
289 colorsContainer.addEventListener(
'drop',
function (e) {
291 if (!draggedElement)
return;
293 colorsContainer.insertBefore(draggedElement, placeholder);
294 rebuildColorsFromDOM();
297 badge.appendChild(removeBtn);
298 colorsContainer.appendChild(badge);
303 function getDragAfterElement(container, x) {
304 const elements = [...container.querySelectorAll(
'.color-badge:not(.dragging)')];
306 return elements.reduce((closest, child) => {
307 const box = child.getBoundingClientRect();
308 const offset = x - box.left - box.width / 2;
310 if (offset < 0 && offset > closest.offset) {
311 return { offset: offset, element: child };
315 }, { offset: Number.NEGATIVE_INFINITY }).element;
318 addColorBtn.addEventListener(
'click',
function () {
319 addColor(colorPicker.value);
322 PRELOADED_COLORS.forEach(color => {
331 const QUICKMEMO_DISABLE_AUTO_RESIZE_FONT_SIZE = <?php print json_encode(
getDolGlobalInt(
'QUICKMEMO_DISABLE_AUTO_RESIZE_FONT_SIZE')); ?>;
334 const minInput = document.getElementById(
'autoResizeFontMin');
335 const maxInput = document.getElementById(
'autoResizeFontMax');
338 const previewMinText = document.getElementById(
'previewMinText');
339 const previewMaxText = document.getElementById(
'previewMaxText');
341 function updatePreview(changed) {
343 let min = parseFloat(minInput.value);
344 let max = parseFloat(maxInput.value);
346 if (changed ===
'min' && min > max) {
348 maxInput.value = max.toFixed(1);
351 if (changed ===
'max' && max < min) {
353 minInput.value = min.toFixed(1);
356 previewMinText.style.fontSize = min +
'em';
357 previewMaxText.style.fontSize = max +
'em';
360 minInput.addEventListener(
'input', () => updatePreview(
'min'));
361 maxInput.addEventListener(
'input', () => updatePreview(
'max'));
367 const toggleDisplayLineSize =
function (display =
true) {
369 'setup-line-item_QUICKMEMO_AUTO_RESIZE_MIN_FONT_SIZE',
370 'setup-line-item_QUICKMEMO_AUTO_RESIZE_MAX_FONT_SIZE'
374 const el = document.getElementById(
id);
375 if (el) el.style.display = display ?
'' :
'none';
379 toggleDisplayLineSize(!QUICKMEMO_DISABLE_AUTO_RESIZE_FONT_SIZE);
381 Dolibarr.on(
'delConstant', (data) => {
382 if(data.code ===
'QUICKMEMO_DISABLE_AUTO_RESIZE_FONT_SIZE'){
383 toggleDisplayLineSize(true);
387 Dolibarr.on(
'setConstant', (data) => {
388 if(data.code ===
'QUICKMEMO_DISABLE_AUTO_RESIZE_FONT_SIZE'){
389 toggleDisplayLineSize(false);
397$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.
img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"BackToModuleList").
'</span></a>';
403print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"fa-sticky-note_fa");
406echo
'<span class="opacitymedium">'.$langs->trans(
"QuickMemoSetupPage").
'</span><br><br>';
409if (!empty($formSetup->items)) {
410 print $formSetup->generateOutput(
true);
416if (empty($setupnotempty)) {
417 print
'<br>'.$langs->trans(
"NothingToSetup");
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
static getColorPreset()
Get color preset.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
quickmemoAdminPrepareHead()
Prepare admin pages header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.