mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°1318 - multiple choice in a template - WIP
This commit is contained in:
@@ -75,43 +75,38 @@ $(function()
|
||||
getCurrentValue: function()
|
||||
{
|
||||
var value = null;
|
||||
|
||||
this.element.find(':input').each(function(iIndex, oElem){
|
||||
if($(oElem).is(':hidden') || $(oElem).is(':text') || $(oElem).is(':password') || $(oElem).is('textarea'))
|
||||
{
|
||||
value = $(oElem).val();
|
||||
}
|
||||
else if($(oElem).is('select'))
|
||||
{
|
||||
if($(oElem).is('select[multiple]'))
|
||||
{
|
||||
value = [];
|
||||
$(oElem).find('option:selected').each(function(){
|
||||
value.push($(this).val());
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.element.attr('data-input-type') == 'tagset') {
|
||||
value = [];
|
||||
|
||||
this.element.find('select').find('option:selected').each(function (iIndex, oElem) {
|
||||
value.push($(this).val());
|
||||
});
|
||||
} else {
|
||||
this.element.find(':input').each(function (iIndex, oElem) {
|
||||
if ($(oElem).is(':text') || $(oElem).is(':password') || $(oElem).is('textarea')) {
|
||||
value = $(oElem).val();
|
||||
} else if ($(oElem).is(':hidden') || $(oElem).is('select')) {
|
||||
if ($(oElem).is('select[multiple]')) {
|
||||
value = [];
|
||||
$(oElem).find('option:selected').each(function () {
|
||||
value.push($(this).val());
|
||||
});
|
||||
} else {
|
||||
value = $(oElem).val();
|
||||
}
|
||||
} else if ($(oElem).is(':checkbox') || $(oElem).is(':radio')) {
|
||||
if (value === null) {
|
||||
value = [];
|
||||
}
|
||||
if ($(oElem).is(':checked')) {
|
||||
value.push($(oElem).val());
|
||||
}
|
||||
} else {
|
||||
console.log('Form field : Input type not handle yet.');
|
||||
}
|
||||
}
|
||||
else if($(oElem).is(':checkbox') || $(oElem).is(':radio'))
|
||||
{
|
||||
if(value === null)
|
||||
{
|
||||
value = [];
|
||||
}
|
||||
if($(oElem).is(':checked'))
|
||||
{
|
||||
value.push($(oElem).val());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('Form field : Input type not handle yet.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
validate: function(oEvent, oData)
|
||||
|
||||
@@ -411,6 +411,7 @@ return array(
|
||||
'Combodo\\iTop\\Form\\Field\\StringField' => $baseDir . '/sources/Form/Field/StringField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\SubFormField' => $baseDir . '/sources/Form/Field/SubFormField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TagSetField' => $baseDir . '/sources/Form/Field/TagSetField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TagSetObjectField' => $baseDir . '/sources/Form/Field/TagSetObjectField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TextAreaField' => $baseDir . '/sources/Form/Field/TextAreaField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TextField' => $baseDir . '/sources/Form/Field/TextField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\UrlField' => $baseDir . '/sources/Form/Field/UrlField.php',
|
||||
@@ -2665,7 +2666,6 @@ return array(
|
||||
'TCPDF_STATIC' => $vendorDir . '/combodo/tcpdf/include/tcpdf_static.php',
|
||||
'TabManager' => $baseDir . '/sources/Application/WebPage/TabManager.php',
|
||||
'TabularBulkExport' => $baseDir . '/core/tabularbulkexport.class.inc.php',
|
||||
'TagSet' => $baseDir . '/sources/Application/UI/Base/Component/Input/TagSet.php',
|
||||
'TagSetFieldData' => $baseDir . '/core/tagsetfield.class.inc.php',
|
||||
'TemplateMenuNode' => $baseDir . '/application/menunode.class.inc.php',
|
||||
'TemplateString' => $baseDir . '/core/templatestring.class.inc.php',
|
||||
|
||||
@@ -36,7 +36,7 @@ class ComposerAutoloaderInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->setApcuPrefix('RreWMf6INtOlcXT31V1+d');
|
||||
$loader->setApcuPrefix('CfF4ZRXo3iRuTmM6Ha8Mj');
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f::$files;
|
||||
|
||||
@@ -766,6 +766,7 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'Combodo\\iTop\\Form\\Field\\StringField' => __DIR__ . '/../..' . '/sources/Form/Field/StringField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\SubFormField' => __DIR__ . '/../..' . '/sources/Form/Field/SubFormField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TagSetField' => __DIR__ . '/../..' . '/sources/Form/Field/TagSetField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TagSetObjectField' => __DIR__ . '/../..' . '/sources/Form/Field/TagSetObjectField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TextAreaField' => __DIR__ . '/../..' . '/sources/Form/Field/TextAreaField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\TextField' => __DIR__ . '/../..' . '/sources/Form/Field/TextField.php',
|
||||
'Combodo\\iTop\\Form\\Field\\UrlField' => __DIR__ . '/../..' . '/sources/Form/Field/UrlField.php',
|
||||
@@ -3020,7 +3021,6 @@ class ComposerStaticInit7f81b4a2a468a061c306af5e447a9a9f
|
||||
'TCPDF_STATIC' => __DIR__ . '/..' . '/combodo/tcpdf/include/tcpdf_static.php',
|
||||
'TabManager' => __DIR__ . '/../..' . '/sources/Application/WebPage/TabManager.php',
|
||||
'TabularBulkExport' => __DIR__ . '/../..' . '/core/tabularbulkexport.class.inc.php',
|
||||
'TagSet' => __DIR__ . '/../..' . '/sources/Application/UI/Base/Component/Input/TagSet.php',
|
||||
'TagSetFieldData' => __DIR__ . '/../..' . '/core/tagsetfield.class.inc.php',
|
||||
'TemplateMenuNode' => __DIR__ . '/../..' . '/application/menunode.class.inc.php',
|
||||
'TemplateString' => __DIR__ . '/../..' . '/core/templatestring.class.inc.php',
|
||||
|
||||
@@ -82,16 +82,11 @@ abstract class MultipleChoicesField extends Field
|
||||
*/
|
||||
public function SetCurrentValue($currentValue)
|
||||
{
|
||||
if (is_array($currentValue))
|
||||
{
|
||||
if (is_array($currentValue)) {
|
||||
$this->currentValue = $currentValue;
|
||||
}
|
||||
elseif (is_null($currentValue))
|
||||
{
|
||||
} elseif (is_null($currentValue)) {
|
||||
$this->currentValue = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->currentValue = array($currentValue);
|
||||
}
|
||||
return $this;
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
|
||||
use BinaryExpression;
|
||||
use DBObjectSet;
|
||||
use FieldExpression;
|
||||
use ScalarExpression;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Description of MultipleSelectObjectField
|
||||
*
|
||||
@@ -16,6 +22,8 @@ namespace Combodo\iTop\Form\Field;
|
||||
*/
|
||||
class MultipleSelectObjectField extends SelectObjectField
|
||||
{
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = true;
|
||||
|
||||
function SetCurrentValue($currentValue)
|
||||
{
|
||||
if ($currentValue != null) {
|
||||
@@ -26,4 +34,73 @@ class MultipleSelectObjectField extends SelectObjectField
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function Validate()
|
||||
{
|
||||
$this->SetValid(true);
|
||||
$this->EmptyErrorMessages();
|
||||
|
||||
if ($this->GetReadOnly() === false) {
|
||||
if (count($this->currentValue) > 0) {
|
||||
foreach ($this->currentValue as $sCode => $value) {
|
||||
if (utils::IsNullOrEmptyString($value) || ($value == 0)) {
|
||||
continue;
|
||||
}
|
||||
$oSearchForExistingCurrentValue = $this->oSearch->DeepClone();
|
||||
$oSearchForExistingCurrentValue->AddCondition('id', $value, '=');
|
||||
$oCheckIdAgainstCurrentValueExpression = new BinaryExpression(
|
||||
new FieldExpression('id', $oSearchForExistingCurrentValue->GetClassAlias()), '=', new ScalarExpression($value)
|
||||
);
|
||||
$oSearchForExistingCurrentValue->AddConditionExpression($oCheckIdAgainstCurrentValueExpression);
|
||||
$oSetForExistingCurrentValue = new DBObjectSet($oSearchForExistingCurrentValue);
|
||||
$iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1);
|
||||
|
||||
if ($iObjectsCount === 0) {
|
||||
$this->SetValid(false);
|
||||
$this->AddErrorMessage("Value $value does not match the corresponding filter set");
|
||||
|
||||
return $this->GetValid();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->GetValidators() as $oValidator) {
|
||||
foreach ($this->currentValue as $value) {
|
||||
if (!preg_match($oValidator->GetRegExp(true), $value)) {
|
||||
$this->SetValid(false);
|
||||
$this->AddErrorMessage($oValidator->GetErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->GetValid();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets current value if not among allowed ones.
|
||||
* By default, reset is done ONLY when the field is not read-only.
|
||||
*
|
||||
* @param boolean $bAlways Set to true to verify even when the field is read-only.
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function VerifyCurrentValue(bool $bAlways = false)
|
||||
{
|
||||
if (!$this->GetReadOnly() || $bAlways) {
|
||||
if (count($this->currentValue) > 0) {
|
||||
foreach ($this->currentValue as $sCode => $value) {
|
||||
$oValuesScope = $this->GetSearch()->DeepClone();
|
||||
$oBinaryExp = new BinaryExpression(new FieldExpression('id', $oValuesScope->GetClassAlias()), '=',
|
||||
new ScalarExpression($value));
|
||||
$oValuesScope->AddConditionExpression($oBinaryExp);
|
||||
$oValuesSet = new DBObjectSet($oValuesScope);
|
||||
}
|
||||
} else {
|
||||
$this->currentValue = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ use utils;
|
||||
* @author Romain Quetiez <romain.quetiez@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class SelectObjectField extends Field
|
||||
class SelectObjectField extends MultipleChoicesField
|
||||
{
|
||||
/** @var int CONTROL_SELECT */
|
||||
const CONTROL_SELECT = 1;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Combodo\iTop\Form\Field;
|
||||
*/
|
||||
class TagSetObjectField extends MultipleSelectObjectField
|
||||
{
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = true;
|
||||
|
||||
function SetCurrentValue($currentValue)
|
||||
{
|
||||
|
||||
@@ -185,10 +185,7 @@ EOF
|
||||
* $oPage->add_ready_script($sScript);*/
|
||||
|
||||
$oValue = UIContentBlockUIBlockFactory::MakeStandard("", ["form-field-content"]);
|
||||
$bVertical = true;
|
||||
$idx = 0;
|
||||
$aValues = $this->oField->GetCurrentValue();
|
||||
$sId = $this->oField->GetGlobalId();
|
||||
|
||||
$aFieldsToLoad = [];
|
||||
$aComplementAttributeSpec = MetaModel::GetNameSpec($oAllowedValues->GetClass(), FriendlyNameType::COMPLEMENTARY);
|
||||
@@ -209,49 +206,60 @@ EOF
|
||||
}
|
||||
|
||||
$oAllowedValues->OptimizeColumnLoad($aFieldsToLoad);
|
||||
|
||||
//MAYBE USE INPUT SET ?
|
||||
$oSelect = SelectUIBlockFactory::MakeForSelectWithLabel($this->oField->GetLabel(), $this->oField->GetDescription(), $this->oField->GetGlobalId());
|
||||
$oSelect->SetIsMultiple(true);
|
||||
while ($oObj = $oAllowedValues->Fetch()) {
|
||||
$oSelect->AddSubBlock(SelectOptionUIBlockFactory::MakeForSelectOption(
|
||||
$oObj->GetKey(),
|
||||
$oObj->GetName(),
|
||||
is_null($aValues) ? false : in_array($oObj->GetKey(), $aValues, true) === true)
|
||||
(is_null($aValues) || !is_array($aValues)) ? false : in_array($oObj->GetKey(), $aValues, true) === true)
|
||||
);
|
||||
}
|
||||
$oOutput->AddJs(
|
||||
<<<JS
|
||||
|
||||
$oOutput->AddJs(
|
||||
<<<JS
|
||||
$("#{$this->oField->GetGlobalId()}").selectize({
|
||||
maxItems: null,
|
||||
sortField: 'text',
|
||||
onChange: function(value){
|
||||
|
||||
console.warn('chane');
|
||||
var me = this.\$input;
|
||||
me.trigger("field_change", {
|
||||
id: me.attr("id"),
|
||||
name: me.closest(".form_field").attr("data-field-id"),
|
||||
value: me.val()
|
||||
})
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
console.warn('chane');
|
||||
var me = this.\$input;
|
||||
me.trigger("field_change", {
|
||||
id: me.attr("id"),
|
||||
name: me.closest(".form_field").attr("data-field-id"),
|
||||
value: me.val()
|
||||
})
|
||||
.closest('.form_handler').trigger('change');
|
||||
|
||||
$(me).closest(".field_set").trigger("field_change", {
|
||||
id: $(me).attr("id"),
|
||||
name: $(me).closest(".form_field").attr("data-field-id"),
|
||||
value: $(me).val()
|
||||
})
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
},
|
||||
loadingClass: '',
|
||||
itemClass: 'item attribute-set-item',
|
||||
inputClass: 'attribute-set ibo-input ibo-input-selectize',
|
||||
render: {
|
||||
option: function(option) {
|
||||
return CombodoGlobalToolbox.RenderTemplate('#{$this->oField->GetGlobalId()}_options_template', option, this.settings.optionClass)[0].outerHTML;
|
||||
},
|
||||
item: function (item) {
|
||||
return CombodoGlobalToolbox.RenderTemplate('#{$this->oField->GetGlobalId()}_items_template', item, this.settings.itemClass)[0].outerHTML;
|
||||
},
|
||||
},
|
||||
inputClass: 'ibo-input-vanilla ibo-input ibo-input-selectize',
|
||||
});
|
||||
$("#{$this->oField->GetGlobalId()}").closest('div').addClass('ibo-input-select-wrapper--with-buttons');
|
||||
$("#{$this->oField->GetGlobalId()}").off("change").on("change", function(){
|
||||
var me = this;
|
||||
|
||||
$(this).closest(".field_set").trigger("field_change", {
|
||||
id: $(me).attr("id"),
|
||||
name: $(me).closest(".form_field").attr("data-field-id"),
|
||||
value: $(me).val()
|
||||
})
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
|
||||
});
|
||||
JS
|
||||
);
|
||||
|
||||
|
||||
$oValue->AddSubBlock($oSelect);
|
||||
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
|
||||
$oBlock->AddSubBlock($oValue);
|
||||
break;
|
||||
@@ -387,8 +395,19 @@ EOF
|
||||
value: me.val()
|
||||
})
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
},
|
||||
inputClass: 'ibo-input-vanilla ibo-input ibo-input-selectize',
|
||||
},
|
||||
loadingClass: '',
|
||||
itemClass: 'item attribute-set-item',
|
||||
inputClass: 'ibo-input-vanilla ibo-input ibo-input-selectize',
|
||||
plugins: {
|
||||
'combodo_update_operations' : {
|
||||
initial: ["5"],
|
||||
},
|
||||
'combodo_auto_position' : {
|
||||
maxDropDownHeight: 300,
|
||||
},
|
||||
'remove_button' : {},
|
||||
},
|
||||
});
|
||||
$("#{$this->oField->GetGlobalId()}").closest('div').addClass('ibo-input-select-wrapper--with-buttons');
|
||||
JS
|
||||
@@ -396,6 +415,7 @@ JS
|
||||
}
|
||||
}
|
||||
|
||||
$oBlock->AddDataAttribute("input-type", $sFieldClass);
|
||||
$oOutput->AddHtml((BlockRenderer::RenderBlockTemplates($oBlock)));
|
||||
// JS Form field widget construct
|
||||
$aValidators = array();
|
||||
|
||||
@@ -118,9 +118,11 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer
|
||||
break;
|
||||
|
||||
case 'Combodo\\iTop\\Form\\Field\\LabelField':
|
||||
$oValue = UIContentBlockUIBlockFactory::MakeStandard("",[""]);
|
||||
$oValue = UIContentBlockUIBlockFactory::MakeStandard("", [""]);
|
||||
$oBlock->AddSubBlock($oValue);
|
||||
$oValue->AddSubBlock(new Text($this->oField->GetCurrentValue()));
|
||||
if (utils::IsNotNullOrEmptyString($this->oField->GetCurrentValue())) {
|
||||
$oValue->AddSubBlock(new Text($this->oField->GetCurrentValue()));
|
||||
}
|
||||
$oValue->AddSubBlock(new Html('<span class="form_validation"></span>'));
|
||||
break;
|
||||
|
||||
@@ -241,6 +243,7 @@ EOF
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
console.warn('chanegement');
|
||||
},
|
||||
itemClass: 'attribute-set-item',
|
||||
});
|
||||
$("#{$this->oField->GetGlobalId()}").closest('div').addClass('ibo-input-select-wrapper--with-buttons');
|
||||
JS
|
||||
@@ -485,18 +488,19 @@ EOF
|
||||
$oOutput->AddJs(
|
||||
<<<EOF
|
||||
$("#{$this->oField->GetGlobalId()}").selectize({
|
||||
sortField: 'text',
|
||||
onChange: function(value){
|
||||
sortField: 'text',
|
||||
onChange: function(value){
|
||||
|
||||
console.warn('lala');
|
||||
var me = this.\$input;
|
||||
me.closest(".field_set").trigger("field_change", {
|
||||
id: me.attr("id"),
|
||||
name: me.closest(".form_field").attr("data-field-id"),
|
||||
value: me.val()
|
||||
})
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
}
|
||||
var me = this.\$input;
|
||||
me.closest(".field_set").trigger("field_change", {
|
||||
id: me.attr("id"),
|
||||
name: me.closest(".form_field").attr("data-field-id"),
|
||||
value: me.val()
|
||||
})
|
||||
.closest('.form_handler').trigger('value_change');
|
||||
},
|
||||
itemClass: 'attribute-set-item'
|
||||
});
|
||||
EOF
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user