X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2Fform%2FFloatField.class.php;h=5b939754e453b7482a678e8e18a6fcfed400a570;hb=75a1eedb8977b8f2db459128bab9aaf367e3b58b;hp=370b28b4647d6500279f7fe37c38f9c6225c810d;hpb=9a23a8c0a51b7ec38a96f525484134f3cb85dc7e;p=timetracker.git diff --git a/WEB-INF/lib/form/FloatField.class.php b/WEB-INF/lib/form/FloatField.class.php index 370b28b4..5b939754 100644 --- a/WEB-INF/lib/form/FloatField.class.php +++ b/WEB-INF/lib/form/FloatField.class.php @@ -27,48 +27,47 @@ // +----------------------------------------------------------------------+ import('form.TextField'); - + class FloatField extends TextField { - var $mDelimiter = '.'; - var $mFFormat; - var $cClassName = "FloatField"; + var $mDelimiter = '.'; + var $mFFormat; + + function __construct($name) { + global $user; + + $this->class = 'FloatField'; + $this->name = $name; + $this->mDelimiter = $user->getDecimalMark(); + } + + function localize() { + global $user; + $this->mDelimiter = $user->getDecimalMark(); + } + + function setFormat($format) { + $this->mFFormat = $format; + } + + function setValue($value) { + if (isset($this->mFFormat) && isset($value) && strlen($value)) { + $value = str_replace($this->mDelimiter, '.', $value); + $value = sprintf('%'.$this->mFFormat.'f', $value); + $value = str_replace('.', $this->mDelimiter, $value); + } + $this->value = $value; + } + + function setValueSafe($value) { + // '.' to ',' , apply delimiter + if (strlen($value) > 0) + $this->value = str_replace('.', $this->mDelimiter, $value); + } - function FloatField($name) { - $this->mName = $name; - } - - function setLocalization($i18n) { - FormElement::setLocalization($i18n); - global $user; - $this->mDelimiter = $user->decimal_mark; - } - - function setFormat($format) { - $this->mFFormat = $format; - } - - function setValue($value) { - if (isset($this->mFFormat) && isset($value) && strlen($value)) { - $value = str_replace($this->mDelimiter,".",$value); - $value = sprintf("%".$this->mFFormat."f",$value); - $value = str_replace(".",$this->mDelimiter,$value); - } - $this->mValue = $value; - } - - function setValueSafe($value) { - // '.' to ',' , apply localisation - if (strlen($value)>0) - $this->mValue = str_replace(".",$this->mDelimiter,$value); - } - - function getValueSafe() { - // ',' to '.' - if (strlen($this->mValue)>0) { - return str_replace($this->mDelimiter,".",$this->mValue); - } else { - return null; - } - } + function getValueSafe() { + // ',' to '.' + if (strlen($this->value) > 0) + return str_replace($this->mDelimiter, '.', $this->value); + return null; + } } -?> \ No newline at end of file