ソースを参照

Portal : Finished integration of Date & DateTime attributes in forms

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4029 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 9 年 前
コミット
c1b5d9f83a

+ 1 - 0
core/attributedef.class.inc.php

@@ -3646,6 +3646,7 @@ class AttributeDateTime extends AttributeDBField
 		$oFormField = parent::MakeFormField($oObject, $oFormField);
 		$oFormField->SetPHPDateTimeFormat((string) $this->GetFormat());
 		$oFormField->SetJSDateTimeFormat($this->GetFormat()->ToMomentJS());
+		$oFormField->SetCurrentValue($this->GetFormat()->Format($oObject->Get($this->GetCode())));
 
 		return $oFormField;
 	}

+ 2 - 1
sources/form/field/datetimefield.class.inc.php

@@ -84,7 +84,7 @@ class DateTimeField extends StringField
 	
 	public function GetDisplayValue()
 	{
-		return AttributeDatetime::GetFormat()->Format($this->currentValue);
+		return $this->currentValue;
 	}
 	
 	/**
@@ -103,4 +103,5 @@ class DateTimeField extends StringField
 	{
 		return $this->bDateOnly;
 	}
+
 }

+ 17 - 1
sources/renderer/bootstrap/fieldrenderer/bssimplefieldrenderer.class.inc.php

@@ -260,7 +260,7 @@ EOF
 							}
 							$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('<input type="hidden" id="' . $this->oField->GetGlobalId() . '" name="' . $this->oField->GetId() . '" value="')->AddHtml($this->oField->GetDisplayValue(), true)->AddHtml('" class="form-control" />');
 						$oOutput->AddHtml('</div>');
 						break;
 
@@ -310,6 +310,22 @@ EOF
 EOF
 				);
 				break;
+			case 'Combodo\\iTop\\Form\\Field\\DateTimeField':
+				// We need the focusout event has the datepicker widget seems to override the change event
+				$oOutput->AddJs(
+<<<EOF
+					$("#{$this->oField->GetGlobalId()}").off("change keyup focusout").on("change keyup focusout", 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()
+						});
+					});
+EOF
+				);
+				break;
 
 			case 'Combodo\\iTop\\Form\\Field\\RadioField':
 			case 'Combodo\\iTop\\Form\\Field\\CheckboxField':