summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-10-16 15:01:40 +0200
committerAleksander Machniak <alec@alec.pl>2013-10-16 15:01:40 +0200
commitcc78f666ed3492c2fc4c77b5313f10f0e3fec3a5 (patch)
tree41bd1b4fc0bf5eefa22b6c74949e060ef1fed0a7 /lib
parent11ba7226ecff70357a4b4bab216ef5937565ef82 (diff)
downloadwebadmin-cc78f666ed3492c2fc4c77b5313f10f0e3fec3a5.tar.gz
Implement 'default' value support for form_fields of type text, text-quota and select (Request #2358)
Diffstat (limited to 'lib')
-rw-r--r--lib/client/kolab_client_task_settings.php4
-rw-r--r--lib/kolab_client_task.php32
-rw-r--r--lib/locale/en_US.php1
3 files changed, 26 insertions, 11 deletions
diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index 019b417..5faf53a 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -702,6 +702,7 @@ class kolab_client_task_settings extends kolab_client_task
'maxcount' => $data['attributes']['form_fields'][$attr]['maxcount'],
'data' => $_data,
'values' => $data['attributes']['form_fields'][$attr]['values'],
+ 'default' => $data['attributes']['form_fields'][$attr]['default'],
);
}
@@ -777,6 +778,9 @@ class kolab_client_task_settings extends kolab_client_task
),
'onchange' => 'kadm.type_attr_value_change(this)',
),
+ 'default' => array(
+ 'type' => kolab_form::INPUT_TEXT,
+ ),
'validate' => array(
'type' => kolab_form::INPUT_SELECT,
'options' => array(
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index f6e574c..07864ff 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -839,6 +839,7 @@ class kolab_client_task
$result['type'] = kolab_form::INPUT_SELECT;
$result['options'] = $opts['options'];
$result['value'] = $opts['default'];
+ $result['default'] = $field['default'];
if ($field['type'] == 'multiselect') {
$result['multiple'] = true;
@@ -874,14 +875,17 @@ class kolab_client_task
break;
case 'text-quota':
- $result['type'] = kolab_form::INPUT_TEXTQUOTA;
+ $result['type'] = kolab_form::INPUT_TEXTQUOTA;
+ $result['default'] = $field['default'];
break;
default:
$result['type'] = kolab_form::INPUT_TEXT;
+
if (isset($field['maxlength'])) {
$result['maxlength'] = $field['maxlength'];
}
+
if ($field['type'] && $field['type'] != 'text') {
$result['data-type'] = $field['type'];
if ($field['type'] == 'ldap_url') {
@@ -892,6 +896,9 @@ class kolab_client_task
);
}
}
+ else {
+ $result['default'] = $field['default'];
+ }
}
$result['required'] = empty($field['optional']);
@@ -1228,7 +1235,6 @@ class kolab_client_task
//console("form_create() \$attribs", $attribs);
//console("form_create() \$auto_fields", $auto_fields);
-
//console("Going to walk through sections", $sections);
// Parse elements and add them to the form object
@@ -1249,28 +1255,32 @@ class kolab_client_task
$field['section'] = $section_idx;
if (empty($field['value']) && !empty($data[$idx])) {
-
//console("Using data value", $data[$idx], "for value of field $idx");
-
- $field['value'] = $data[$idx];
+ $value = $data[$idx];
// Convert data for the list field with autocompletion
if ($field['data-type'] == kolab_form::TYPE_LIST) {
- if (!is_array($data[$idx])) {
+ if (!is_array($value)) {
if (!empty($field['data-autocomplete'])) {
- $data[$idx] = array($data[$idx] => $data[$idx]);
+ $value = array($value => $value);
}
else {
- $data[$idx] = (array) $data[$idx];
+ $value = (array) $value;
}
}
- $field['value'] = !empty($field['data-autocomplete']) ? array_keys($data[$idx]) : array_values($data[$idx]);
+ $value = !empty($field['data-autocomplete']) ? array_keys($value) : array_values($value);
}
- if (is_array($field['value'])) {
- $field['value'] = implode("\n", $field['value']);
+ if (is_array($value)) {
+ $value = implode("\n", $value);
}
+
+ $field['value'] = $value;
+ }
+ else if ($add_mode && !isset($field['value']) && isset($field['default'])) {
+ $field['value'] = $field['default'];
+ unset($field['default']);
}
// @TODO: We assume here that all autocompletion lists are associative
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 390f150..bbbea13 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -10,6 +10,7 @@ $LANG['about.warranty'] = 'It comes with absolutely <b>no warranties</b> and is
$LANG['add'] = 'Add';
$LANG['attribute.add'] = 'Add attribute';
+$LANG['attribute.default'] = 'Default value';
$LANG['attribute.static'] = 'Static value';
$LANG['attribute.name'] = 'Attribute';
$LANG['attribute.optional'] = 'Optional';