summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-10-16 13:01:40 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-10-16 13:01:40 (GMT)
commitcc78f666ed3492c2fc4c77b5313f10f0e3fec3a5 (patch)
tree41bd1b4fc0bf5eefa22b6c74949e060ef1fed0a7
parent11ba7226ecff70357a4b4bab216ef5937565ef82 (diff)
downloadkolab-wap-cc78f666ed3492c2fc4c77b5313f10f0e3fec3a5.tar.gz
Implement 'default' value support for form_fields of type text, text-quota and select (Request #2358)
-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
-rw-r--r--public_html/js/kolab_admin.js29
4 files changed, 47 insertions, 19 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';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 983ae8c..9eda881 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -1813,6 +1813,9 @@ function kolab_admin()
if (attr.validate != 'default')
data.validate = attr.validate;
+ if (attr['default'] && attr.valtype == 'normal' && attr.type.match(/^(text|select)/))
+ data['default'] = attr['default'];
+
if (attr.valtype == 'normal' || attr.valtype == 'auto')
request.attributes.form_fields[i] = data;
if (attr.valtype == 'auto' || attr.valtype == 'auto-readonly') {
@@ -1962,6 +1965,10 @@ function kolab_admin()
row.attr('title', this.t('attribute.value.' + (data.valtype == 'static' ? 'static' : 'auto')) + ': ' + data.data);
}
+ if (form_data.attr_default && data.valtype == 'normal' && data.type.match(/^(text|select)/)) {
+ data['default'] = form_data.attr_default;
+ }
+
// Update table row
$('td.name', row).text(this.env.attributes[attr]);
$('td.type', row).text(data.type);
@@ -1989,10 +1996,11 @@ function kolab_admin()
$('select[name="attr_type"]').val(type);
$('select[name="attr_value"]').val(attr ? data.valtype : 'normal');
- $('select[name="attr_validate"]').val(attr ? data.validate : '');
+ $('select[name="attr_validate"]').val(data.validate || '');
+ $('input[name="attr_default"]').val(data['default'] || '');
$('input[name="attr_optional"]').attr('checked', attr ? data.optional : false);
- $('input[name="attr_data"]').val(attr ? data.data : '');
- $('input[name="attr_maxcount"]').val(data.maxcount ? data.maxcount : '');
+ $('input[name="attr_data"]').val(data.data || '');
+ $('input[name="attr_maxcount"]').val(data.maxcount || '');
$('textarea[name="attr_options"]').val(data.values ? data.values.join("\n") : '');
$('span', name_select.parent()).remove();
@@ -2007,8 +2015,8 @@ function kolab_admin()
}
this.form_element_update({name: 'attr_options'});
- this.type_attr_type_change('select[name="attr_type"]');
- this.type_attr_value_change('select[name="attr_value"]');
+ this.type_attr_type_change();
+ this.type_attr_value_change();
};
// Initialize attribute name selector
@@ -2027,13 +2035,14 @@ function kolab_admin()
// Update attribute form on attribute name change
this.type_attr_name_change = function(elem)
{
- this.type_attr_value_change('select[name="attr_value"]');
+ this.type_attr_value_change();
};
// Update attribute form on value type change
this.type_attr_value_change = function(elem)
{
- var type = $(elem).val(),
+ var type = $(elem || 'select[name="attr_value"]').val(),
+ field_type = $('select[name="attr_type"]').val(),
optional = $('#attr_form_row_optional'),
select = $('select[name="attr_name"]').val(),
attr_name = this.env.attributes[select],
@@ -2042,6 +2051,7 @@ function kolab_admin()
$('input[name="attr_data"]')[type != 'normal' ? 'show' : 'hide']();
$('#attr_form_row_readonly')[type != 'static' ? 'show' : 'hide']();
+ $('#attr_form_row_default')[type == 'normal' && field_type.match(/^(text|select)/) ? 'show' : 'hide']();
optional[opt ? 'show' : 'hide']();
if (!opt)
@@ -2051,9 +2061,12 @@ function kolab_admin()
// Update attribute form on type change
this.type_attr_type_change = function(elem)
{
- var type = $(elem).val();
+ var type = $(elem || 'select[name="attr_type"]').val(),
+ val_type = $('select[name="attr_value"]').val();
+
$('#attr_form_row_maxcount')[type == 'list' || type == 'list-autocomplete' ? 'show' : 'hide']();
$('#attr_form_row_options')[type == 'select' || type == 'multiselect' ? 'show' : 'hide']();
+ $('#attr_form_row_default')[val_type == 'normal' && type.match(/^(text|select)/) ? 'show' : 'hide']();
};
// Update attributes list on object classes change