lib/client lib/kolab_api_service.php lib/kolab_client_task.php public_html/js public_html/skins
Aleksander Machniak
machniak at kolabsys.com
Mon Dec 22 13:34:25 CET 2014
lib/client/kolab_client_task_settings.php | 13 +++++++++----
lib/kolab_api_service.php | 4 ++++
lib/kolab_client_task.php | 16 ++++++++++++----
public_html/js/kolab_admin.js | 21 +++++++++++++++++++++
public_html/skins/default/style.css | 3 ++-
5 files changed, 48 insertions(+), 9 deletions(-)
New commits:
commit 47b1217a1c494dc428f4ff16e026f44abd3f3ed3
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Mon Dec 22 07:10:39 2014 -0500
Add support for autocompletion on text fields (#3885)
- to enable that define field as 'text-autocompletion' in settings
or just add 'autocomplete' = true to the form_field params.
diff --git a/lib/client/kolab_client_task_settings.php b/lib/client/kolab_client_task_settings.php
index ca9fb72..19b23e6 100644
--- a/lib/client/kolab_client_task_settings.php
+++ b/lib/client/kolab_client_task_settings.php
@@ -32,8 +32,10 @@ class kolab_client_task_settings extends kolab_client_task
);
protected $form_element_types = array(
- 'text', 'text-separated', 'select', 'multiselect', 'list', 'list-autocomplete', 'checkbox', 'password', 'ldap_url',
- 'text-quota', 'aci', 'imap_acl',
+ 'text', 'text-separated', 'text-quota', 'text-autocomplete',
+ 'select', 'multiselect',
+ 'list', 'list-autocomplete', 'checkbox', 'password', 'ldap_url',
+ 'aci', 'imap_acl',
);
protected $special_attributes = array('ou');
@@ -624,7 +626,7 @@ class kolab_client_task_settings extends kolab_client_task
// defined attributes
foreach ($attributes as $attr) {
$row = $cells;
- $type = $data['attributes']['form_fields'][$attr]['type'];
+ $type = $data['attributes']['form_fields'][$attr]['type'] ?: 'text';
$optional = $data['attributes']['form_fields'][$attr]['optional'];
$autocomplete = $data['attributes']['form_fields'][$attr]['autocomplete'];
$validate = $data['attributes']['form_fields'][$attr]['validate'];
@@ -634,6 +636,9 @@ class kolab_client_task_settings extends kolab_client_task
if ($type == 'list' && $autocomplete) {
$type = 'list-autocomplete';
}
+ else if ($type == 'text' && $autocomplete) {
+ $type = 'text-autocomplete';
+ }
if ($data['attributes']['fields'][$attr]) {
$valtype = 'static';
@@ -669,7 +674,7 @@ class kolab_client_task_settings extends kolab_client_task
// set cell content
$row['name']['body'] = !empty($available[$attr]) ? $available[$attr] : $attr;
- $row['type']['body'] = !empty($type) ? $type : 'text';
+ $row['type']['body'] = $type;
$row['readonly']['body'] = $valtype == 'auto-readonly' ? $yes : $no;
$row['optional']['body'] = $optional ? $yes : $no;
$row['validate']['body'] = $this->translate('attribute.validate.' . $n_validate);
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 9cd37de..6809bd5 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -311,6 +311,10 @@ abstract class kolab_api_service
foreach ($type_attrs['form_fields'] as $key => $value) {
Log::trace("Running parse input attributes for key $key");
+ if (($value['type'] == 'text' || empty($value['type'])) && is_array($attribs[$key])) {
+ $attribs[$key] = array_shift($attribs[$key]);
+ }
+
if (empty($attribs[$key]) && empty($value['optional'])) {
Log::error("\$attribs['" . $key . "'] is empty, and the field is not optional");
throw new Exception("Missing input value for $key", 345);
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index b784856..5dce5bb 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -921,10 +921,14 @@ class kolab_client_task
break;
default:
- $result['type'] = kolab_form::INPUT_TEXT;
-
- if (isset($field['maxlength'])) {
- $result['maxlength'] = $field['maxlength'];
+ if (!empty($field['autocomplete'])) {
+ $result['type'] = kolab_form::INPUT_TEXTAREA;
+ $result['data-type'] = 'list';
+ $result['data-maxcount'] = 1;
+ $result['data-autocomplete'] = true;
+ }
+ else {
+ $result['type'] = kolab_form::INPUT_TEXT;
}
if ($field['type'] && $field['type'] != 'text') {
@@ -940,6 +944,10 @@ class kolab_client_task
else {
$result['default'] = $field['default'];
}
+
+ if (isset($field['maxlength'])) {
+ $result['maxlength'] = $field['maxlength'];
+ }
}
$result['required'] = empty($field['optional']);
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 59dfc35..007c45c 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -852,6 +852,7 @@ function kolab_admin()
readonly = e.attr('readonly'),
autocomplete = e.attr('data-autocomplete'),
maxlength = e.attr('data-maxlength'),
+ maxcount = e.attr('data-maxcount'),
area = $('<span class="listarea"></span>');
e.hide();
@@ -902,6 +903,16 @@ function kolab_admin()
oninsert: this.form_element_oninsert
});
+ // when max=1 we use only one input
+ if (maxcount == 1) {
+ $.each(list, function(i, v) {
+ $('input', elem).val(v);
+ return false;
+ });
+
+ list = [];
+ }
+
elem.appendTo(area);
area.addClass('autocomplete');
}
@@ -1009,6 +1020,13 @@ function kolab_admin()
af = kadm.env.assoc_fields,
maxcount = $('textarea[name="'+name+'"]').attr('data-maxcount');
+ if (maxcount == 1) {
+ $(input).val(val);
+ af[name] = {};
+ af[name][key] = val;
+ return;
+ }
+
// reset autocomplete input
input.value = '';
@@ -2653,6 +2671,9 @@ function kolab_admin()
data.type = 'list';
data.autocomplete = true;
}
+ else if (attr.type == 'text-autocomplete') {
+ data.autocomplete = true;
+ }
else if (attr.type != 'text')
data.type = attr.type;
diff --git a/public_html/skins/default/style.css b/public_html/skins/default/style.css
index 1897b7c..5a8c598 100644
--- a/public_html/skins/default/style.css
+++ b/public_html/skins/default/style.css
@@ -723,7 +723,8 @@ span.listarea.autocomplete span.listelement input.autocomplete {
}
.autocomplete > span.listelement input {
- width: 346px;
+ width: 348px;
+ border-radius: 0;
}
.autocomplete > span.listelement span.actions {
More information about the commits
mailing list