summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-12-22 12:10:39 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-12-22 12:10:39 (GMT)
commit47b1217a1c494dc428f4ff16e026f44abd3f3ed3 (patch)
tree63e50a0756e70beaff0e4fdc2c14817a2ae0c704
parentd1f86621d0ffdbdb536fb352d9b3a74397aa04c2 (diff)
downloadkolab-wap-47b1217a1c494dc428f4ff16e026f44abd3f3ed3.tar.gz
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.
-rw-r--r--lib/client/kolab_client_task_settings.php13
-rw-r--r--lib/kolab_api_service.php4
-rw-r--r--lib/kolab_client_task.php16
-rw-r--r--public_html/js/kolab_admin.js21
-rw-r--r--public_html/skins/default/style.css3
5 files changed, 48 insertions, 9 deletions
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 {