Support of date and time custom formats... continuing towards the beta !

SVN:trunk[4019]
This commit is contained in:
Denis Flaven
2016-05-03 09:56:02 +00:00
parent 7d4e9ce069
commit 5386662146
32 changed files with 518 additions and 460 deletions

View File

@@ -29,7 +29,6 @@ require_once APPROOT . 'sources/form/field/textfield.class.inc.php';
require_once APPROOT . 'sources/form/field/hiddenfield.class.inc.php';
require_once APPROOT . 'sources/form/field/labelfield.class.inc.php';
require_once APPROOT . 'sources/form/field/stringfield.class.inc.php';
require_once APPROOT . 'sources/form/field/datefield.class.inc.php';
require_once APPROOT . 'sources/form/field/datetimefield.class.inc.php';
require_once APPROOT . 'sources/form/field/durationfield.class.inc.php';
require_once APPROOT . 'sources/form/field/textareafield.class.inc.php';

View File

@@ -22,9 +22,55 @@ namespace Combodo\iTop\Form\Field;
use \Combodo\iTop\Form\Field\StringField;
/**
* Description of StringField
* A field for Dates and Date & Times, supporting custom formats
*/
class DateTimeField extends StringField
{
protected $sJSDateTimeFormat;
protected $sPHPDateTimeFormat;
/**
*
* @return string
*/
public function GetPHPDateTimeFormat()
{
return $this->sPHPDateTimeFormat;
}
/**
*
* @param string $sFormat
* @return \Combodo\iTop\Form\Field\DateTimeField
*/
public function SetPHPDateTimeFormat($sDateTimeFormat)
{
$this->sPHPDateTimeFormat = $sDateTimeFormat;
return $this;
}
/**
*
* @return string
*/
public function GetJSDateTimeFormat()
{
return $this->sDateTimeFormat;
}
/**
*
* @param string $sFormat
* @return \Combodo\iTop\Form\Field\DateTimeField
*/
public function SetJSDateTimeFormat($sDateTimeFormat)
{
$this->sDateTimeFormat = $sDateTimeFormat;
return $this;
}
public function GetDisplayValue()
{
return \AttributeDatetime::Format($this->currentValue, $this->GetPHPDateTimeFormat());
}
}

View File

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

View File

@@ -51,6 +51,25 @@ class BsSimpleFieldRenderer extends FieldRenderer
{
switch ($sFieldClass)
{
case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
$oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
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="help-block"></div>');
$oOutput->AddHtml('<div class="input-group date" id="datepicker_' . $this->oField->GetGlobalId() . '">');
$oOutput->AddHtml('<input type="text" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('" class="form-control" maxlength="255" />');
$oOutput->AddHtml('<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>');
$oOutput->AddHtml('</div>');
$oOutput->AddHtml('</div>');
$sJSFormat = json_encode($this->oField->GetJSDateTimeFormat());
$oOutput->AddJs(
<<<EOF
$('#datepicker_{$this->oField->GetGlobalId()}').datetimepicker({format: $sJSFormat});
EOF
);
break;
case 'Combodo\\iTop\\Form\\Field\\StringField':
$oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
if ($this->oField->GetLabel() !== '')
@@ -230,6 +249,21 @@ EOF
$oOutput->AddHtml('</div>');
break;
case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
$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':
@@ -317,6 +351,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\HiddenField':
case 'Combodo\\iTop\\Form\\Field\\RadioField':
case 'Combodo\\iTop\\Form\\Field\\CheckboxField':
case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
$oOutput->AddJs(
<<<EOF
$("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field($sFormFieldOptions);