瀏覽代碼

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3988 a333f486-631f-4898-b8df-5754b55c2be0
romainq 9 年之前
父節點
當前提交
7733d8c718

+ 3 - 0
sources/autoload.php

@@ -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';

+ 30 - 0
sources/form/field/datefield.class.inc.php

@@ -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
+{
+
+}

+ 30 - 0
sources/form/field/datetimefield.class.inc.php

@@ -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
+{
+
+}

+ 30 - 0
sources/form/field/durationfield.class.inc.php

@@ -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
+{
+
+}

+ 1 - 0
sources/renderer/console/consoleformrenderer.class.inc.php

@@ -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');
 	}

+ 32 - 0
sources/renderer/console/fieldrenderer/consolesimplefieldrenderer.class.inc.php

@@ -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(){