CustomFields: support of DurationField (started devs for DateField and DateTimeField)

SVN:trunk[3988]
This commit is contained in:
Romain Quetiez
2016-04-06 10:25:11 +00:00
parent fd124ef53b
commit e9f57fd9e2
6 changed files with 126 additions and 0 deletions

View File

@@ -28,6 +28,9 @@ 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';
require_once APPROOT . 'sources/form/field/multiplechoicesfield.class.inc.php';
require_once APPROOT . 'sources/form/field/selectfield.class.inc.php';

View File

@@ -0,0 +1,30 @@
<?php
// Copyright (C) 2010-2016 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
namespace Combodo\iTop\Form\Field;
use \Combodo\iTop\Form\Field\StringField;
/**
* Description of StringField
*/
class DateField extends StringField
{
}

View File

@@ -0,0 +1,30 @@
<?php
// Copyright (C) 2010-2016 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
namespace Combodo\iTop\Form\Field;
use \Combodo\iTop\Form\Field\StringField;
/**
* Description of StringField
*/
class DateTimeField extends StringField
{
}

View File

@@ -0,0 +1,30 @@
<?php
// Copyright (C) 2010-2016 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
namespace Combodo\iTop\Form\Field;
use \Combodo\iTop\Form\Field\Field;
/**
* Description of StringField
*/
class DurationField extends Field
{
}

View File

@@ -38,6 +38,7 @@ class ConsoleFormRenderer extends FormRenderer
$this->AddSupportedField('SelectField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('TextAreaField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('RadioField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('DurationField', 'ConsoleSimpleFieldRenderer');
$this->AddSupportedField('SelectObjectField', 'ConsoleSelectObjectFieldRenderer');
$this->AddSupportedField('SubFormField', 'ConsoleSubFormFieldRenderer');
}

View File

@@ -24,6 +24,7 @@ use Combodo\iTop\Renderer\RenderingOutput;
use Combodo\iTop\Form\Field\TextAreaField;
use \InlineImage;
use \UserRights;
use \AttributeDuration;
class ConsoleSimpleFieldRenderer extends FieldRenderer
{
@@ -158,6 +159,36 @@ EOF
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
break;
case 'Combodo\\iTop\\Form\\Field\\DurationField':
$oOutput->AddHtml('<td class="form-field-content">');
$value = $this->oField->GetCurrentValue();
if ($this->oField->GetReadOnly())
{
$oOutput->AddHtml('<input type="hidden" id="'.$this->oField->GetGlobalId().'" value="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '"/>');
$oOutput->AddHtml('<span class="form-field-data">'.htmlentities(\AttributeDuration::FormatDuration($value), ENT_QUOTES, 'UTF-8').'</span>');
}
else
{
$sId = $this->oField->GetGlobalId();
$aVal = AttributeDuration::SplitDuration($value);
$sDays = "<input type=\"text\" size=\"3\" name=\"{$sId}[d]\" value=\"{$aVal['days']}\" id=\"{$sId}_d\"/>";
$sHours = "<input type=\"text\" size=\"2\" name=\"{$sId}[h]\" value=\"{$aVal['hours']}\" id=\"{$sId}_h\"/>";
$sMinutes = "<input type=\"text\" size=\"2\" name=\"{$sId}[m]\" value=\"{$aVal['minutes']}\" id=\"{$sId}_m\"/>";
$sSeconds = "<input type=\"text\" size=\"2\" name=\"{$sId}[s]\" value=\"{$aVal['seconds']}\" id=\"{$sId}_s\"/>";
$oOutput->AddHtml(Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds));
$oOutput->AddHtml("<input type=\"hidden\" id=\"{$sId}\" value=\"".htmlentities($value, ENT_QUOTES, 'UTF-8')."\"/>");
$oOutput->AddJs("$('#{$sId}_d').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}_h').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}_m').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}_s').bind('keyup change', function(evt, sFormId) { return UpdateDuration('$sId'); });");
$oOutput->AddJs("$('#{$sId}').bind('update', function(evt, sFormId) { return ToggleDurationField('$sId'); });");
}
$oOutput->AddHtml('<span class="form_validation"></span>');
$oOutput->AddHtml('</td>');
break;
}
$oOutput->AddHtml('</tr>');
$oOutput->AddHtml('</table>');
@@ -185,6 +216,7 @@ EOF
case 'Combodo\\iTop\\Form\\Field\\SelectField':
case 'Combodo\\iTop\\Form\\Field\\RadioField':
case 'Combodo\\iTop\\Form\\Field\\DurationField':
$oOutput->AddJs(
<<<EOF
$("#{$this->oField->GetGlobalId()}").off("change").on("change", function(){