diff --git a/etemplate/inc/class.ajax_select_widget.inc.php b/etemplate/inc/class.ajax_select_widget.inc.php
index 495dc7c947..18393c836e 100644
--- a/etemplate/inc/class.ajax_select_widget.inc.php
+++ b/etemplate/inc/class.ajax_select_widget.inc.php
@@ -10,7 +10,7 @@
* @version $Id$
*/
- /**
+ /**
* AJAX Select Widget
*
* Using AJAX, this widget allows a type-ahead find similar to a ComboBox, where as the user enters information,
@@ -25,10 +25,13 @@
{
var $public_functions = array(
'pre_process' => True,
- 'post_process' => True
+ 'post_process' => True,
+ 'ajax_search' => True,
);
var $human_name = 'AJAX Select'; // this is the name for the editor
+ private $debug = false;
+
function ajax_select_widget($ui='')
{
@@ -59,7 +62,21 @@
*/
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
{
- //echo "
ajax_select_widget::pre_process('$name',$value," . print_r($cell, true) . "," . print_r($extension_data, true) . ")
\n";
+ if($this->debug) {
+ echo __METHOD__ . '
';
+ printf("Name:%20s
", $name);
+ echo 'Value:';
+ _debug_array($value);
+ echo 'Cell:';
+ _debug_array($cell);
+
+ echo 'Readonlys:';
+ _debug_array($readonlys);
+
+ echo 'Extension_data:';
+ _debug_array($extension_data);
+
+ }
// Get Options
if(!is_array($cell['size'])) {
@@ -69,7 +86,9 @@
$options['id_field'],
$options['template'],
$options['filter'],
- $options['filter2']
+ $options['filter2'],
+ $options['link'],
+ $options['icon']
) = explode(',', $cell['size']);
} else {
$options = $cell['size'];
@@ -128,6 +147,21 @@
$widget =& new etemplate('etemplate.ajax_select_widget');
$widget->no_onclick = True;
+ // Link if readonly & link is set
+ $search =& $widget->get_widget_by_name('search');
+ if(($cell['readonly'] || $readonlys['search']) && $options['link']) {
+ $search['type'] = 'label';
+ $search['no_lang'] = 1;
+ $search['size'] = ',' . $options['link'];
+ } else {
+ $search['type'] = 'text';
+ $search['size'] = '';
+ }
+
+ // Icon
+ $icon =& $widget->get_widget_by_path('/0/1A');
+ $icon['name'] = $options['icon'];
+
$cell['obj'] = &$widget;
// Save options for post_processing
@@ -173,27 +207,29 @@
if($count == 1) {
$value = $results[0][$extension_data['id_field']];
- echo 'Match found';
return true;
- } else {
+ } elseif ($count > 1) {
$GLOBALS['egw_info']['etemplate']['validation_errors'][$name] = lang("More than 1 match for '%1'",$value_in['search']);
$loop = true;
return false;
+ } else {
+ $value = $value_in['search'];
+ return true;
}
}
}
} elseif (!$value_in['value'] && !$value_in['search']) {
$value = null;
- $loop = $extension_data['required'];
+ $loop = $GLOBALS['egw_info']['etemplate']['loop'] || $extension_data['required'];
return !$extension_data['required'];
} else {
$value = $value_in['value'];
- $loop = false;
+ $loop = $GLOBALS['egw_info']['etemplate']['loop'] || false;
return true;
}
}
- function change($id, $value, $set_id, $query) {
+ function ajax_search($id, $value, $set_id, $query) {
$base_id = substr($id, 0, strrpos($id, '['));
$result_id = ($set_id ? $set_id : $base_id . '[results]');
$response = new xajaxResponse();
@@ -233,8 +269,7 @@
if(!$query['template'] || $query['template'] == 'etemplate.ajax_select_widget.row') {
$query['template'] = 'etemplate.ajax_select_widget.row';
}
- foreach($result_list as $key => $nul) {
- $row =& $result_list[$key]; // $key => &$row is php5!
+ foreach($result_list as $key => &$row) {
if(!is_array($row)) {
continue;
}
diff --git a/etemplate/js/ajax_select.js b/etemplate/js/ajax_select.js
index bd6c97f1a4..9be64e1f64 100644
--- a/etemplate/js/ajax_select.js
+++ b/etemplate/js/ajax_select.js
@@ -4,15 +4,15 @@
* Javascript file for AJAX select widget
*
* @author Nathan Gray
-*
+*
* @param widget_id the id of the ajax_select_widget
* @param onchange function to call if the value of the select widget is changed
* @param options the query object containing callback and settings
-*
-* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
-* @package etemplate
-* @subpackage extensions
-* @link http://www.egroupware.org
+*
+* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
+* @package etemplate
+* @subpackage extensions
+* @link http://www.egroupware.org
*
* @version $Id$
*/
@@ -44,8 +44,7 @@ function ajax_select_widget_setup(widget_id, onchange, options) {
var widget = document.getElementById(widget_id + '[search]');
if(widget) {
- widget.form.disableautocomplete = true;
- widget.form.autocomplete = 'off';
+ widget.setAttribute('autocomplete', 'off');
if(widget.addEventListener) {
widget.addEventListener('keyup', change, true);
@@ -118,7 +117,7 @@ function change(e, value) {
selects[i].style.visibility = 'hidden';
}
}
- xajax_doXMLHTTP("etemplate.ajax_select_widget.change", id, value, set_id, query);
+ xajax_doXMLHTTP("etemplate.ajax_select_widget.ajax_search.etemplate", id, value, set_id, query);
}
diff --git a/etemplate/templates/default/ajax_select_widget.row.xet b/etemplate/templates/default/ajax_select_widget.row.xet
new file mode 100644
index 0000000000..25972af3a4
--- /dev/null
+++ b/etemplate/templates/default/ajax_select_widget.row.xet
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etemplate/templates/default/ajax_select_widget.xet b/etemplate/templates/default/ajax_select_widget.xet
new file mode 100644
index 0000000000..fcf06378b0
--- /dev/null
+++ b/etemplate/templates/default/ajax_select_widget.xet
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ .select_value {
+ display: none;
+}
+
+.resultBox {
+ background-color: white;
+}
+
+.resultBox div:hover {
+ background-color: #D3DCE3;
+}
+
+
+
\ No newline at end of file