summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-03-21 14:56:31 +0100
committerAleksander Machniak <alec@alec.pl>2012-03-21 14:56:31 +0100
commit9117d4f73fe8daf847864ce422df93c3c1e4a0e8 (patch)
tree737e99f49296d2e1adc1c582018928b11f4413d2 /lib
parent5246c66ba6a80334d9d0c8860cf89b204fe92e48 (diff)
downloadwebadmin-9117d4f73fe8daf847864ce422df93c3c1e4a0e8.tar.gz
Autocompletion list widget
Diffstat (limited to 'lib')
-rw-r--r--lib/client/kolab_client_task_group.php34
-rw-r--r--lib/client/kolab_client_task_main.php3
-rw-r--r--lib/kolab_client_task.php23
-rw-r--r--lib/kolab_form.php4
-rw-r--r--lib/kolab_html.php7
-rw-r--r--lib/kolab_utils.php9
-rw-r--r--lib/locale/en_US.php3
7 files changed, 74 insertions, 9 deletions
diff --git a/lib/client/kolab_client_task_group.php b/lib/client/kolab_client_task_group.php
index 3d8c876..821d438 100644
--- a/lib/client/kolab_client_task_group.php
+++ b/lib/client/kolab_client_task_group.php
@@ -261,6 +261,27 @@ class kolab_client_task_group extends kolab_client_task
);
}
+ // Members (get member names)
+ if (!empty($data['group'])) {
+ // find members attribute name
+ foreach (array('member', 'uniquemember') as $attr) {
+ if (isset($fields[$attr]) && isset($data[$attr])) {
+ $attr_name = $attr;
+ }
+ }
+ if (!empty($attr_name)) {
+ $result = $this->api->get('group.members_list', array('group' => $data['group']));
+ $list = (array) $result->get('list');
+ $data[$attr_name] = $this->parse_members($list);
+ }
+ }
+
+$fields['debug'] = array(
+ 'label' => 'debug',
+ 'section' => 'system',
+ 'value' => '<pre>'.kolab_html::escape(print_r($data, true)).'</pre>',
+);
+
// Create form object and populate with fields
$form = $this->form_create('group', $attribs, $sections, $fields, $fields_map, $data);
@@ -271,6 +292,19 @@ class kolab_client_task_group extends kolab_client_task
return $form->output();
}
+ private function parse_members($list)
+ {
+ // convert to key=>value array, see kolab_api_service_form_value::list_options_uniquemember()
+ foreach ($list as $idx => $value) {
+ $list[$idx] = $value['displayname'];
+ if (!empty($value['mail'])) {
+ $list[$idx] .= ' <' . $value['mail'] . '>';
+ }
+ }
+
+ return $list;
+ }
+
/**
* Returns list of group types.
*
diff --git a/lib/client/kolab_client_task_main.php b/lib/client/kolab_client_task_main.php
index 9996526..b7b4621 100644
--- a/lib/client/kolab_client_task_main.php
+++ b/lib/client/kolab_client_task_main.php
@@ -40,7 +40,8 @@ class kolab_client_task_main extends kolab_client_task
$this->output->set_env('watermark', $this->output->get_template('watermark'));
// assign default set of translations
- $this->output->add_translation('loading', 'saving', 'deleting', 'servererror', 'search');
+ $this->output->add_translation('loading', 'saving', 'deleting', 'servererror',
+ 'search', 'search.loading', 'search.acchars');
// Create list of tasks for dashboard
// @TODO: check capabilities
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index bd49cd3..6ee696f 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -618,6 +618,9 @@ class kolab_client_task
if (!empty($field['maxlength'])) {
$result['data-maxlength'] = $field['maxlength'];
}
+ if (!empty($field['autocomplete'])) {
+ $result['data-autocomplete'] = true;
+ }
break;
default:
@@ -781,6 +784,7 @@ class kolab_client_task
}
$form = new kolab_form($attribs);
+ $assoc_fields = array();
// Parse elements and add them to the form object
foreach ($sections as $section_idx => $section) {
@@ -792,20 +796,24 @@ class kolab_client_task
}
if (empty($field['label'])) {
- $field['label'] = "user.$idx";
+ $field['label'] = "$name.$idx";
}
$field['label'] = kolab_html::escape($this->translate($field['label']));
- $field['description'] = "user.$idx.desc";
+ $field['description'] = "$name.$idx.desc";
$field['section'] = $section_idx;
if (!empty($data[$idx])) {
- if (is_array($data[$idx])) {
- $field['value'] = array_map(array('kolab_html', 'escape'), $data[$idx]);
- $field['value'] = implode("\n", $field['value']);
+ $field['value'] = $data[$idx];
+
+ // Convert data for the list field with autocompletion
+ if ($field['data-type'] == kolab_form::TYPE_LIST && kolab_utils::is_assoc($data[$idx])) {
+ $assoc_fields[$idx] = $data[$idx];
+ $field['value'] = array_keys($data[$idx]);
}
- else {
- $field['value'] = kolab_html::escape($data[$idx]);
+
+ if (is_array($field['value'])) {
+ $field['value'] = implode("\n", $field['value']);
}
}
/*
@@ -858,6 +866,7 @@ class kolab_client_task
}
$this->output->set_env('form_id', $attribs['id']);
+ $this->output->set_env('assoc_fields', $assoc_fields);
return $form;
}
diff --git a/lib/kolab_form.php b/lib/kolab_form.php
index c78486f..850ca8f 100644
--- a/lib/kolab_form.php
+++ b/lib/kolab_form.php
@@ -34,6 +34,7 @@ class kolab_form
const INPUT_SUBMIT = 7;
const INPUT_SELECT = 8;
const INPUT_HIDDEN = 9;
+ const INPUT_CUSTOM = 10;
const TYPE_LIST = 1;
@@ -279,9 +280,10 @@ class kolab_form
break;
case self::INPUT_SELECT:
- $content = kolab_html::select($attribs);
+ $content = kolab_html::select($attribs, true);
break;
+ case self::INPUT_CUSTOM:
default:
if (is_array($attribs)) {
$content = isset($attribs['value']) ? $attribs['value'] : '';
diff --git a/lib/kolab_html.php b/lib/kolab_html.php
index afce918..9680ef5 100644
--- a/lib/kolab_html.php
+++ b/lib/kolab_html.php
@@ -316,6 +316,13 @@ class kolab_html
public static function escape($value)
{
+ if (is_array($value)) {
+ foreach ($value as $idx => $val) {
+ $value[$idx] = self::escape($val);
+ }
+ return $value;
+ }
+
return htmlspecialchars($value, ENT_COMPAT, KADM_CHARSET);
}
}
diff --git a/lib/kolab_utils.php b/lib/kolab_utils.php
index 2694f71..b80bc6a 100644
--- a/lib/kolab_utils.php
+++ b/lib/kolab_utils.php
@@ -142,4 +142,13 @@ class kolab_utils
return false;
}
+
+ /**
+ * Finds wether an array is associative or not.
+ */
+ public static function is_assoc ($arr)
+ {
+ return is_array($arr) && count(array_filter(array_keys($arr), 'is_string')) == count($arr);
+ }
+
}
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index efd7439..c0bbbf1 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -25,6 +25,8 @@ $LANG['search.prefix'] = 'begins with';
$LANG['search.name'] = 'name';
$LANG['search.email'] = 'email';
$LANG['search.uid'] = 'UID';
+$LANG['search.loading'] = 'Searching...';
+$LANG['search.acchars'] = 'At least $min characters required for autocompletion';
$LANG['menu.users'] = 'Users';
$LANG['menu.groups'] = 'Groups';
@@ -98,6 +100,7 @@ $LANG['group.group_type_id'] = 'Group type';
$LANG['group.add.success'] = 'Group created successfully.';
$LANG['group.delete.success'] = 'Group deleted successfully.';
$LANG['group.gidnumber'] = 'Primary group number';
+$LANG['group.uniquemember'] = 'Members';
$LANG['group.system'] = 'System';
$LANG['group.other'] = 'Other';