N.481: Portal: Impossible to submit a form with a duration attribute. Also fixed the displayed value in tables (ManageBrick and BrowseBrick)

SVN:trunk[4504]
This commit is contained in:
Guillaume Lajarige
2016-12-08 11:36:54 +00:00
parent 4ec3aeec92
commit ffbd666aca
6 changed files with 40 additions and 6 deletions

View File

@@ -4049,7 +4049,7 @@ class AttributeDuration extends AttributeInteger
static public function GetFormFieldClass()
{
return '\\Combodo\\iTop\\Form\\Field\\LabelField';
return '\\Combodo\\iTop\\Form\\Field\\DurationField';
}
public function MakeFormField(DBObject $oObject, $oFormField = null)
@@ -4063,7 +4063,7 @@ class AttributeDuration extends AttributeInteger
// Note : As of today, this attribute is -by nature- only supported in readonly mode, not edition
$sAttCode = $this->GetCode();
$oFormField->SetCurrentValue(html_entity_decode($oObject->GetAsHTML($sAttCode), ENT_QUOTES, 'UTF-8'));
$oFormField->SetCurrentValue($oObject->Get($sAttCode));
$oFormField->SetReadOnly(true);
return $oFormField;

View File

@@ -601,7 +601,14 @@ class BrowseBrickController extends BrickController
foreach ($aLevelsProperties[$key]['fields'] as $aField)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($value), $aField['code']);
$aRow[$key]['fields'][$aField['code']] = $oAttDef->GetValueLabel($value->Get($aField['code']));
if ($oAttDef->GetEditClass() === 'Duration')
{
$aRow[$key]['fields'][$aField['code']] = $oAttDef->GetAsHTML($value->Get($aField['code']));
}
else
{
$aRow[$key]['fields'][$aField['code']] = $oAttDef->GetValueLabel($value->Get($aField['code']));
}
}
}
}

View File

@@ -28,6 +28,7 @@ use \MetaModel;
use \AttributeDefinition;
use \AttributeDate;
use \AttributeDateTime;
use \AttributeDuration;
use \AttributeSubItem;
use \DBSearch;
use \DBObjectSearch;
@@ -410,7 +411,7 @@ class ManageBrickController extends BrickController
}
}
}
elseif ($oAttDef instanceof AttributeSubItem)
elseif ($oAttDef instanceof AttributeSubItem || $oAttDef instanceof AttributeDuration)
{
$sValue = $oAttDef->GetAsHTML($oCurrentRow->Get($sItemAttr));
}
@@ -473,5 +474,3 @@ class ManageBrickController extends BrickController
}
}
?>

View File

@@ -20,6 +20,8 @@
namespace Combodo\iTop\Form\Field;
use \Combodo\iTop\Form\Field\Field;
use \Str;
use \AttributeDuration;
/**
* Description of StringField
@@ -27,4 +29,14 @@ use \Combodo\iTop\Form\Field\Field;
class DurationField extends Field
{
/**
* Note: This is inspired by AttributeDuration::GetAsHTML()
*
* @return string
*/
public function GetDisplayValue()
{
return Str::pure2html(AttributeDuration::FormatDuration($this->currentValue));
}
}

View File

@@ -54,6 +54,7 @@ class BsFormRenderer extends FormRenderer
$this->AddSupportedField('SelectObjectField', 'BsSelectObjectFieldRenderer');
$this->AddSupportedField('LinkedSetField', 'BsLinkedSetFieldRenderer');
$this->AddSupportedField('DateTimeField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('DurationField', 'BsSimpleFieldRenderer');
$this->AddSupportedField('FileUploadField', 'BsFileUploadFieldRenderer');
}

View File

@@ -269,6 +269,21 @@ EOF
$oOutput->AddHtml('</div>');
break;
case 'Combodo\\iTop\\Form\\Field\\DurationField':
$oOutput->AddHtml('<div class="form-group">');
// Showing label / value only if read-only but not hidden
if (!$this->oField->GetHidden())
{
if ($this->oField->GetLabel() !== '')
{
$oOutput->AddHtml('<label for="' . $this->oField->GetGlobalId() . '" class="control-label">')->AddHtml($this->oField->GetLabel(), true)->AddHtml('</label>');
}
$oOutput->AddHtml('<div class="form-control-static">')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('</div>');
}
$oOutput->AddHtml('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetCurrentValue(), true)->AddHtml('" class="form-control" />');
$oOutput->AddHtml('</div>');
break;
case 'Combodo\\iTop\\Form\\Field\\RadioField':
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':