From a4d1c5627c3958245ea7e2e573267e34f5872471 Mon Sep 17 00:00:00 2001 From: anuko Date: Wed, 1 Mar 2017 19:30:28 +0000 Subject: [PATCH] Further refactoring of the FormElement class. --- WEB-INF/lib/form/ActionForm.class.php | 2 +- WEB-INF/lib/form/Calendar.class.php | 5 ++- WEB-INF/lib/form/CheckboxGroup.class.php | 3 +- WEB-INF/lib/form/DateField.class.php | 7 ++-- WEB-INF/lib/form/FloatField.class.php | 3 +- WEB-INF/lib/form/Form.class.php | 4 +-- WEB-INF/lib/form/FormElement.class.php | 46 ++++++++++++++---------- WEB-INF/templates/footer.tpl | 2 +- mobile/user_add.php | 2 +- mobile/user_edit.php | 2 +- user_add.php | 2 +- user_edit.php | 2 +- 12 files changed, 43 insertions(+), 37 deletions(-) diff --git a/WEB-INF/lib/form/ActionForm.class.php b/WEB-INF/lib/form/ActionForm.class.php index ee30f7d1..edc15708 100644 --- a/WEB-INF/lib/form/ActionForm.class.php +++ b/WEB-INF/lib/form/ActionForm.class.php @@ -186,7 +186,7 @@ class ActionForm { import('form.'.$ref_el["class"]); $class_name = $ref_el["class"]; $el = new $class_name($ref_el["name"]); - if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]); + if (isset($GLOBALS["I18N"])) $el->localize($GLOBALS["I18N"]); $el->setValueSafe(@$_SESSION[$this->mSessionCell . "_" .$el->getName()]); if ($this->mForm && !isset($this->mForm->elements[$ref_el["name"]])) { diff --git a/WEB-INF/lib/form/Calendar.class.php b/WEB-INF/lib/form/Calendar.class.php index 01bd354b..f4a50a81 100644 --- a/WEB-INF/lib/form/Calendar.class.php +++ b/WEB-INF/lib/form/Calendar.class.php @@ -58,11 +58,10 @@ class Calendar extends FormElement { $this->highlight = $highlight; } - function setLocalization($i18n) { + function localize($i18n) { global $user; - FormElement::setLocalization($i18n); - $this->mMonthNames = $i18n->monthNames; + $this->mMonthNames = $i18n->monthNames; $this->mWeekDayShortNames = $i18n->weekdayShortNames; if (is_array($i18n->holidays)) { foreach ($i18n->holidays as $fday) { diff --git a/WEB-INF/lib/form/CheckboxGroup.class.php b/WEB-INF/lib/form/CheckboxGroup.class.php index 9f5cc053..136cc069 100644 --- a/WEB-INF/lib/form/CheckboxGroup.class.php +++ b/WEB-INF/lib/form/CheckboxGroup.class.php @@ -60,8 +60,7 @@ class CheckboxGroup extends FormElement { function setGroupIn($value) { $this->mGroupIn = $value; if ($this->mGroupIn<1) $this->mGroupIn = 1;} function getGroupIn() { return $this->mGroupIn; } - function setLocalization($i18n) { - FormElement::setLocalization($i18n); + function localize($i18n) { $this->lSelAll = $i18n->getKey('label.select_all'); $this->lSelNone = $i18n->getKey('label.select_none'); } diff --git a/WEB-INF/lib/form/DateField.class.php b/WEB-INF/lib/form/DateField.class.php index 46ff7b83..320d5240 100644 --- a/WEB-INF/lib/form/DateField.class.php +++ b/WEB-INF/lib/form/DateField.class.php @@ -44,14 +44,13 @@ class DateField extends TextField { $this->mDateObj = new DateAndTime(); if (isset($GLOBALS["I18N"])) { - $this->setLocalization($GLOBALS["I18N"]); + $this->localize($GLOBALS["I18N"]); } } - function setLocalization($i18n) { - global $user; + function localize($i18n) { + global $user; - FormElement::setLocalization($i18n); $this->mDateObj->setFormat($user->date_format); $this->mMonthNames = $i18n->monthNames; diff --git a/WEB-INF/lib/form/FloatField.class.php b/WEB-INF/lib/form/FloatField.class.php index c4e9d9ef..6bbfd64c 100644 --- a/WEB-INF/lib/form/FloatField.class.php +++ b/WEB-INF/lib/form/FloatField.class.php @@ -38,8 +38,7 @@ class FloatField extends TextField { $this->name = $name; } - function setLocalization($i18n) { - FormElement::setLocalization($i18n); + function localize($i18n) { global $user; $this->mDelimiter = $user->decimal_mark; } diff --git a/WEB-INF/lib/form/Form.class.php b/WEB-INF/lib/form/Form.class.php index ceaed430..cd506aed 100644 --- a/WEB-INF/lib/form/Form.class.php +++ b/WEB-INF/lib/form/Form.class.php @@ -141,7 +141,7 @@ class Form { if ($el!=null) { $el->setFormName($this->name); if (isset($arguments["id"])) $el->setId($arguments["id"]); - if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]); + if (isset($GLOBALS["I18N"])) $el->localize($GLOBALS["I18N"]); if (isset($arguments["enable"])) $el->setEnabled($arguments["enable"]); if (isset($arguments["style"])) $el->setStyle($arguments["style"]); @@ -159,7 +159,7 @@ class Form { function addInputElement(&$el) { if ($el && is_object($el)) { - if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]); + if (isset($GLOBALS["I18N"])) $el->localize($GLOBALS["I18N"]); $el->setFormName($this->name); $this->elements[$el->name] = &$el; diff --git a/WEB-INF/lib/form/FormElement.class.php b/WEB-INF/lib/form/FormElement.class.php index cf43b8d0..f3d26a4d 100644 --- a/WEB-INF/lib/form/FormElement.class.php +++ b/WEB-INF/lib/form/FormElement.class.php @@ -60,30 +60,40 @@ class FormElement { function setValueSafe($value) { $this->value = $value;} function getValueSafe() { return $this->value; } + function setId($id) { $this->id = $id; } + function getId() { return $this->id; } + + function setSize($value) { $this->size = $value; } + function getSize() { return $this->size; } + + function setLabel($label) { $this->label = $label; } + function getLabel() { return $this->label; } + + function setMaxLength($value) { $this->max_length = $value; } + function getMaxLength() { return $this->max_length; } + + function setStyle($value) { $this->style = $value; } + function getStyle() { return $this->style; } + + function setEnabled($flag) { $this->enabled = $flag; } + function isEnabled() { return $this->enabled; } + + function setOnChange($str) { $this->on_change = $str; } + function setOnClick($str) { $this->on_click = $str; } + + function localize($i18n) {} // Localization occurs in derived classes and is dependent on control type. + // For example, in calendar control we need to localize day and month names. + // TODO: refactoring ongoing down from here. - function setId($id) { $this->id = $id; } - function getId() { return $this->id; } - - function setSize($value) { $this->size = $value; } - function getSize() { return $this->size; } - function setLabel($label) { $this->label = $label; } - function getLabel() { return $this->label; } - - function setMaxLength($value) { $this->max_length = $value; } - function getMaxLength() { return $this->max_length; } - function setStyle($value) { $this->style = $value; } - function getStyle() { return $this->style; } - function setEnabled($flag) { $this->enabled = $flag; } - function isEnabled() { return $this->enabled; } + + - function setOnChange($str) { $this->on_change = $str; } - function setOnClick($str) { $this->on_click = $str; } - function setLocalization($i18n) { - } + + function toStringControl() { return ""; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 06b606c7..14dadd5a 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.10.38.3611 | Copyright © Anuko | +  Anuko Time Tracker 1.10.38.3612 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/user_add.php b/mobile/user_add.php index 34c48222..eec9662d 100644 --- a/mobile/user_add.php +++ b/mobile/user_add.php @@ -107,7 +107,7 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row, 'id')); $field->setFormName($table->getFormName()); - $field->setLocalization($GLOBALS['I18N']); + $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { diff --git a/mobile/user_edit.php b/mobile/user_edit.php index 4f3b9aaa..96532d90 100644 --- a/mobile/user_edit.php +++ b/mobile/user_edit.php @@ -137,7 +137,7 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row,'id')); $field->setFormName($table->getFormName()); - $field->setLocalization($GLOBALS['I18N']); + $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { diff --git a/user_add.php b/user_add.php index 08d66a7e..6b5befe9 100644 --- a/user_add.php +++ b/user_add.php @@ -107,7 +107,7 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row, 'id')); $field->setFormName($table->getFormName()); - $field->setLocalization($GLOBALS['I18N']); + $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { diff --git a/user_edit.php b/user_edit.php index 8f71e55f..b3f41116 100644 --- a/user_edit.php +++ b/user_edit.php @@ -137,7 +137,7 @@ class RateCellRenderer extends DefaultCellRenderer { global $assigned_projects; $field = new FloatField('rate_'.$table->getValueAtName($row,'id')); $field->setFormName($table->getFormName()); - $field->setLocalization($GLOBALS['I18N']); + $field->localize($GLOBALS['I18N']); $field->setSize(5); $field->setFormat('.2'); foreach ($assigned_projects as $p) { -- 2.20.1