summaryrefslogtreecommitdiffstats
path: root/lib/kolab_client_task.php
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/kolab_client_task.php
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/kolab_client_task.php')
-rw-r--r--lib/kolab_client_task.php32
1 files changed, 21 insertions, 11 deletions
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