summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-09-20 14:01:42 +0200
committerAleksander Machniak <alec@alec.pl>2013-09-20 14:02:37 +0200
commit69ef0de8ffd1460ebba165fc7210034b3235a791 (patch)
tree2faaa4328083161a59271b9e3470ed8c71247921 /lib
parent6d132a638c03de4e571dace6aaeebaaea8d1c315 (diff)
downloadwebadmin-69ef0de8ffd1460ebba165fc7210034b3235a791.tar.gz
Add possibility to set 'validate' flag for form_fields in object type definition
Diffstat (limited to 'lib')
-rw-r--r--lib/api/kolab_api_service_form_value.php27
-rw-r--r--lib/client/kolab_client_task_settings.php32
-rw-r--r--lib/locale/en_US.php4
3 files changed, 49 insertions, 14 deletions
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index ce72173..1e4b044 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -28,6 +28,10 @@
*/
class kolab_api_service_form_value extends kolab_api_service
{
+ const VALIDATE_DEFAULT = 'default';
+ const VALIDATE_BASIC = 'basic';
+ const VALIDATE_NONE = 'none';
+
/**
* Returns service capabilities.
@@ -223,14 +227,21 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- if ($attribs['form_fields'][$attr_name]['validate'] === false) {
+ $validate = $attribs['form_fields'][$attr_name]['validate'];
+
+ // deprecated value: false = VALIDATE_NONE
+ if ($validate === false) {
+ $validate = self::VALIDATE_NONE;
+ }
+
+ if ($validate == self::VALIDATE_NONE) {
$result[$attr_name] = $attr_value;
}
else if ($attribs['form_fields'][$attr_name]['optional'] && $attr_value === '') {
$result[$attr_name] = $attr_value;
}
else {
- $result[$attr_name] = $this->{$method_name}($attr_value, $postdata);
+ $result[$attr_name] = $this->{$method_name}($attr_value, $postdata, $validate);
}
}
@@ -1079,7 +1090,7 @@ class kolab_api_service_form_value extends kolab_api_service
return $options;
}
- private function validate_alias($value)
+ private function validate_alias($value, $postdata = null, $validation_type = null)
{
$auth = Auth::get_instance();
$conf = Conf::get_instance();
@@ -1103,7 +1114,7 @@ class kolab_api_service_form_value extends kolab_api_service
}
- private function validate_associateddomain($value)
+ private function validate_associateddomain($value, $postdata = array(), $validation_type = null)
{
return $value;
@@ -1119,7 +1130,7 @@ class kolab_api_service_form_value extends kolab_api_service
return $value;
}
- private function validate_astaccountrealmedpassword($value, $postdata)
+ private function validate_astaccountrealmedpassword($value, $postdata = array(), $validation_type = null)
{
if (!array_key_exists('userpassword', $postdata) || empty($postdata['userpassword'])) {
return $value;
@@ -1136,7 +1147,7 @@ class kolab_api_service_form_value extends kolab_api_service
return md5($str);
}
- private function validate_mail($value)
+ private function validate_mail($value, $postdata = array(), $validation_type = null)
{
$auth = Auth::get_instance();
$conf = Conf::get_instance();
@@ -1159,7 +1170,7 @@ class kolab_api_service_form_value extends kolab_api_service
}
}
- private function validate_mailquota($value)
+ private function validate_mailquota($value, $postdata = array(), $validation_type = null)
{
// convert MB/GB into KB
if (preg_match('/^([0-9]+)\s*(KB|MB|GB)$/i', $value, $m)) {
@@ -1173,7 +1184,7 @@ class kolab_api_service_form_value extends kolab_api_service
return (int) $value;
}
- private function validate_mailalternateaddress($value)
+ private function validate_mailalternateaddress($value, $postdata = array(), $validation_type = null)
{
$auth = Auth::get_instance();
$conf = Conf::get_instance();
diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index 2ec463d..019b417 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -584,8 +584,8 @@ class kolab_client_task_settings extends kolab_client_task
'optional' => array(
'body' => $this->translate('attribute.optional'),
),
- 'value' => array(
- 'body' => $this->translate('attribute.value'),
+ 'validate' => array(
+ 'body' => $this->translate('attribute.validate'),
),
);
@@ -624,6 +624,7 @@ class kolab_client_task_settings extends kolab_client_task
$type = $data['attributes']['form_fields'][$attr]['type'];
$optional = $data['attributes']['form_fields'][$attr]['optional'];
$autocomplete = $data['attributes']['form_fields'][$attr]['autocomplete'];
+ $validate = $data['attributes']['form_fields'][$attr]['validate'];
$valtype = 'normal';
$value = '';
@@ -639,13 +640,18 @@ class kolab_client_task_settings extends kolab_client_task
}
else if (isset($data['attributes']['auto_form_fields'][$attr])) {
$valtype = 'auto';
+
if (is_array($data['attributes']['auto_form_fields'][$attr]['data'])) {
$_data = implode(',', $data['attributes']['auto_form_fields'][$attr]['data']);
}
else {
$_data = '';
}
- $value = $this->translate('attribute.value.auto') . ': ' . kolab_html::escape($_data);
+
+ $value = $this->translate('attribute.value.auto');
+ if (!empty($_data)) {
+ $value . ': ' . kolab_html::escape($_data);
+ }
if (empty($data['attributes']['form_fields'][$attr])) {
$valtype = 'auto-readonly';
@@ -656,15 +662,17 @@ class kolab_client_task_settings extends kolab_client_task
}
}
+ $n_validate = $validate === false ? 'none' : $validate ? $validate : 'default';
+
// set cell content
$row['name']['body'] = !empty($available[$attr]) ? $available[$attr] : $attr;
$row['type']['body'] = !empty($type) ? $type : 'text';
- $row['value']['body'] = $value;
$row['readonly']['body'] = $valtype == 'auto-readonly' ? $yes : $no;
$row['optional']['body'] = $optional ? $yes : $no;
+ $row['validate']['body'] = $this->translate('attribute.validate.' . $n_validate);
if (!empty($row['actions'])) {
- $row['actions']['body'] = '';
+ $row['actions']['body'] = '';
if (in_array('delete', $rights)) {
$row['actions']['body'] .= kolab_html::a(array(
@@ -681,6 +689,7 @@ class kolab_client_task_settings extends kolab_client_task
$rows[] = array(
'id' => 'attr_table_row_' . $attr,
+ 'title' => $value,
'cells' => $row,
);
@@ -689,6 +698,7 @@ class kolab_client_task_settings extends kolab_client_task
'type' => !empty($type) ? $type : 'text',
'valtype' => $valtype,
'optional' => $optional,
+ 'validate' => $n_validate,
'maxcount' => $data['attributes']['form_fields'][$attr]['maxcount'],
'data' => $_data,
'values' => $data['attributes']['form_fields'][$attr]['values'],
@@ -716,7 +726,9 @@ class kolab_client_task_settings extends kolab_client_task
$this->output->set_env('yes_label', $yes);
$this->output->set_env('no_label', $no);
$this->output->add_translation('attribute.value.auto', 'attribute.value.static',
- 'attribute.key.invalid', 'attribute.required.error');
+ 'attribute.key.invalid', 'attribute.required.error',
+ 'attribute.validate.default', 'attribute.validate.basic', 'attribute.validate.none'
+ );
// Add attribute link
if (in_array('write', $rights)) {
@@ -765,6 +777,14 @@ class kolab_client_task_settings extends kolab_client_task
),
'onchange' => 'kadm.type_attr_value_change(this)',
),
+ 'validate' => array(
+ 'type' => kolab_form::INPUT_SELECT,
+ 'options' => array(
+ 'default' => $this->translate('attribute.validate.default'),
+ 'basic' => $this->translate('attribute.validate.basic'),
+ 'none' => $this->translate('attribute.validate.none'),
+ ),
+ ),
'optional' => array(
'type' => kolab_form::INPUT_CHECKBOX,
'value' => 1,
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index f10451a..390f150 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -24,6 +24,10 @@ $LANG['attribute.value.static'] = 'Static';
$LANG['attribute.options'] = 'Options';
$LANG['attribute.key.invalid'] = 'Type key contains forbidden characters!';
$LANG['attribute.required.error'] = 'Required attributes missing in attributes list ($1)!';
+$LANG['attribute.validate'] = ' Validation';
+$LANG['attribute.validate.default'] = 'default';
+$LANG['attribute.validate.none'] = 'none';
+$LANG['attribute.validate.basic'] = 'basic';
$LANG['button.cancel'] = 'Cancel';
$LANG['button.delete'] = 'Delete';