mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Update ChoiceImageFormBlock and add feature to ValueTypeClass.php
This commit is contained in:
@@ -76,6 +76,7 @@ $ibo-input-select-icon--menu--icon--margin-right: 10px !default;
|
||||
|
||||
display: flex;
|
||||
column-gap: 5px;
|
||||
align-items: center;
|
||||
|
||||
> img{
|
||||
width: 32px;
|
||||
|
||||
@@ -469,6 +469,7 @@ Dict::Add('EN US', 'English', 'English', [
|
||||
'UI:UserPref:DoNotShowAgain' => 'Do not show again',
|
||||
'UI:InputFile:NoFileSelected' => 'No File Selected',
|
||||
'UI:InputFile:SelectFile' => 'Select a file',
|
||||
'UI:InputFile:SelectImage' => 'Select an image',
|
||||
|
||||
'UI:SearchToggle' => 'Search',
|
||||
'UI:ClickToCreateNew' => 'Create a %1$s',
|
||||
|
||||
@@ -3,13 +3,21 @@
|
||||
*/
|
||||
TomSelect.define('image_renderer', function(options) {
|
||||
this.settings.render.option = function(data, escape) {
|
||||
return `<div class="ibo-input-select-icon--menu--item">
|
||||
<img src="${options['images_resource_path']+escape(data.value)}" alt="${data.text}" />${escape(data.text)}
|
||||
const image = data['$option'].dataset['image'];
|
||||
if(image === ''){
|
||||
return `<div style="padding-left: 46px;">${escape(data.text)}</div>`;
|
||||
}
|
||||
else return `<div class="ibo-input-select-icon--menu--item">
|
||||
<img src="${image}" alt="${escape(data.text)}" />${escape(data.text)}
|
||||
</div>`;
|
||||
};
|
||||
this.settings.render.item = function(data, escape) {
|
||||
return `<div class="ibo-input-select-icon--menu--item">
|
||||
<img src="${options['images_resource_path']+escape(data.value)}" alt="${data.text}"/>${escape(data.text)}
|
||||
const image = data['$option'].dataset['image'];
|
||||
if(image === ''){
|
||||
return `<div>${escape(data.text)}</div>`;
|
||||
}
|
||||
else return `<div class="ibo-input-select-icon--menu--item">
|
||||
<img src="${image}" alt="${escape(data.text)}"/>${escape(data.text)}
|
||||
</div>`;
|
||||
};
|
||||
});
|
||||
@@ -53,7 +61,7 @@ class ChoicesElement extends HTMLSelectElement {
|
||||
};
|
||||
|
||||
if (this.getAttribute('data-tom-select-disable-auto-complete')) {
|
||||
options.controlInput = null;
|
||||
// options.controlInput = null;
|
||||
}
|
||||
if (this.getAttribute('data-tom-select-max-items-selected') && this.getAttribute('data-tom-select-max-items-selected') !== '') {
|
||||
options.maxItems = parseInt(this.getAttribute('data-tom-select-max-items-selected'));
|
||||
|
||||
@@ -29,10 +29,12 @@ class ChoiceImageFormBlock extends ChoiceFormBlock
|
||||
[
|
||||
'name' => 'image_renderer',
|
||||
'options' => [
|
||||
'images_resource_path' => utils::GetAbsoluteUrlAppRoot().'/env-production/',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$oOptionsRegister->SetOption('choice_attr');
|
||||
$oOptionsRegister->SetOption('placeholder', 'UI:InputFile:SelectImage');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
namespace Combodo\iTop\PropertyType\ValueType\Leaf;
|
||||
|
||||
use Combodo\iTop\DesignElement;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceImageFormBlock;
|
||||
use Combodo\iTop\PropertyType\ValueType\Branch\AbstractBranchValueType;
|
||||
use Combodo\iTop\PropertyType\ValueType\Branch\ValueTypePropertyTree;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use utils;
|
||||
|
||||
@@ -23,7 +22,7 @@ class ValueTypeClass extends AbstractLeafValueType
|
||||
|
||||
public function GetFormBlockClass(): string
|
||||
{
|
||||
return ChoiceFormBlock::class;
|
||||
return ChoiceImageFormBlock::class;
|
||||
}
|
||||
|
||||
public function InitFromDomNode(DesignElement $oDomNode, ?AbstractBranchValueType $oParent = null): void
|
||||
@@ -35,18 +34,25 @@ class ValueTypeClass extends AbstractLeafValueType
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
|
||||
$sChoices = "[\n";
|
||||
$sChoicesAttImages = "[\n";
|
||||
$aClasses = $oModelReflection->GetClasses($sCategories, true);
|
||||
sort($aClasses);
|
||||
foreach ($aClasses as $sClass) {
|
||||
$sValue = utils::QuoteForPHP($sClass);
|
||||
$sClassIcon = utils::QuoteForPHP($oModelReflection->GetClassIcon($sClass, false));
|
||||
$sChoices .= <<<PHP
|
||||
\Dict::S('Class:$sClass') => $sValue,
|
||||
|
||||
PHP;
|
||||
$sChoicesAttImages .= <<<PHP
|
||||
\Dict::S('Class:$sClass') => ["data-image" => $sClassIcon],
|
||||
PHP;
|
||||
}
|
||||
$sChoices .= "\t\t\t]";
|
||||
$sChoicesAttImages .= "\t\t\t]";
|
||||
|
||||
$this->aFormBlockOptionsForPHP['choices'] = $sChoices;
|
||||
|
||||
$this->aFormBlockOptionsForPHP['choice_attr'] = $sChoicesAttImages;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,16 +33,26 @@ class ValueTypeIcon extends AbstractLeafValueType
|
||||
$oModelReflection = ServiceLocator::GetInstance()->get('ModelReflection');
|
||||
|
||||
$sChoices = "[\n";
|
||||
$sChoicesAttImages = "[\n";
|
||||
$aIcons = $oModelReflection->GetAvailableIcons();
|
||||
foreach ($aIcons as $aIcon) {
|
||||
$sValue = utils::QuoteForPHP($aIcon['label']);
|
||||
$sLabel = utils::QuoteForPHP($aIcon['label']);
|
||||
$sIcon = utils::QuoteForPHP($aIcon['icon']);
|
||||
$sCode = utils::QuoteForPHP($aIcon['value']);
|
||||
$sChoices .= <<<PHP
|
||||
\t\t\t\t$sValue => $sCode,\n
|
||||
$sLabel => $sCode,\n
|
||||
PHP;
|
||||
$sChoicesAttImages .= <<<PHP
|
||||
$sLabel => ["data-image" => $sIcon],
|
||||
PHP;
|
||||
}
|
||||
$sChoices .= "\t\t\t]";
|
||||
$sChoicesAttImages .= "\t\t\t]";
|
||||
|
||||
$this->aFormBlockOptionsForPHP['choices'] = $sChoices;
|
||||
|
||||
$this->aFormBlockOptionsForPHP['choice_attr'] = $sChoicesAttImages;
|
||||
|
||||
$this->aFormBlockOptionsForPHP['required'] = 'false';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user