From d59493596e650a2c728394aa856d56166b683467 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 9 Sep 2014 08:43:54 +0000 Subject: [PATCH] * Addressbook: fixed diverse problem with advanced search r48511: Fix missed case of really --- addressbook/inc/class.addressbook_ui.inc.php | 24 ++++++++++----- addressbook/js/app.js | 30 ++++++++++++++----- ...lass.etemplate_widget_customfields.inc.php | 16 +++++++++- etemplate/inc/class.so_sql_cf.inc.php | 5 +++- etemplate/js/et2_widget_selectAccount.js | 2 +- 5 files changed, 58 insertions(+), 19 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 1d1dc4fa6d..21550737a6 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -1444,9 +1444,10 @@ window.egw_LAB.wait(function() { $op = 'OR'; if ($query['advanced_search']) { - $op = $query['advanced_search']['operator']; + // Make sure op & wildcard are only valid options + $op = $query['advanced_search']['operator'] == $op ? $op : 'AND'; unset($query['advanced_search']['operator']); - $wildcard = $query['advanced_search']['meth_select']; + $wildcard = $query['advanced_search']['meth_select'] == $wildcard ? $wildcard : false; unset($query['advanced_search']['meth_select']); } //if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home'); @@ -2628,20 +2629,27 @@ window.egw_LAB.wait(function() { { if(!$value) unset($query['advanced_search'][$key]); } + // Skip n_fn, it causes problems in sql + unset($query['advanced_search']['n_fn']); } - $query['start'] = 0; $query['search'] = ''; // store the index state in the session egw_session::appsession('index','addressbook',$query); // store the advanced search in the session to call it again egw_session::appsession('advanced_search','addressbook',$query['advanced_search']); - if ($_content['button']['search']) $response->call("app.addressbook.adv_search"); - if ($_content['button']['cancelsearch']) egw_framework::window_close (); //$response->addScript('this.close();'); + + // Update client / nextmatch with filters, or clear + $response->call("app.addressbook.adv_search", array('advanced_search' => $_content['button']['search'] ? $query['advanced_search'] : '')); + if ($_content['button']['cancelsearch']) + { + egw_framework::window_close (); //$response->addScript('this.close();'); + + // No need to reload popup + return; + } } - //$GLOBALS['egw_info']['flags']['include_xajax'] = true; - //$GLOBALS['egw_info']['flags']['java_script'] .= ""; $GLOBALS['egw_info']['etemplate']['advanced_search'] = true; // initialize etemplate arrays @@ -2668,7 +2676,7 @@ window.egw_LAB.wait(function() { { foreach($this->customfields as $name => $data) { - if ($data['type'] == 'select') + if (substr($data['type'], 0, 6) == 'select' && !($data['rows'] > 1)) { if (!isset($content['#'.$name])) $content['#'.$name] = ''; if(!isset($data['values'][''])) $sel_options['#'.$name][''] = lang('Select one'); diff --git a/addressbook/js/app.js b/addressbook/js/app.js index dff7f0acc1..75a96e6517 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -34,7 +34,6 @@ app.classes.addressbook = AppJS.extend( */ destroy: function() { - //delete this.et2; // call parent this._super.apply(this, arguments); }, @@ -492,14 +491,29 @@ app.classes.addressbook = AppJS.extend( }, /** - * + * Apply advanced search filters to index nextmatch */ - adv_search: function() - { - var link = opener.location.href; - link = link.replace(/#/,''); - opener.location.href=link.replace(/\#/,''); - }, + adv_search: function(filters) + { + var index = window.opener.etemplate2.getById('addressbook-index'); + if(!index) + { + alert('Could not find index'); + window.close(); + return false; + } + var nm = index.widgetContainer.getWidgetById('nm'); + if(!index) + { + window.opener.egw.message('Could not find list', 'error'); + window.close(); + return false; + } + // Reset filters first + nm.activeFilters = {}; + nm.applyFilters(filters); + return false; + }, /** * Mail vCard diff --git a/etemplate/inc/class.etemplate_widget_customfields.inc.php b/etemplate/inc/class.etemplate_widget_customfields.inc.php index 46d9104aef..126a45136b 100644 --- a/etemplate/inc/class.etemplate_widget_customfields.inc.php +++ b/etemplate/inc/class.etemplate_widget_customfields.inc.php @@ -262,6 +262,12 @@ class etemplate_widget_customfields extends etemplate_widget_transformer $widget->attrs['only_app'] = $field['type']; break; + case 'text': + break; + + default: + if (substr($type, 0, 7) !== 'select-') break; + // fall-through for all select-* widgets case 'select': $this->attrs['multiple'] = $field['rows'] > 1; // fall through @@ -270,7 +276,15 @@ class etemplate_widget_customfields extends etemplate_widget_transformer { $field['values'] = self::_get_options_from_file($field['values']['@']); } - self::$request->sel_options[self::$prefix.$fname] = $field['values']; + // keep extra values set by app code, eg. addressbook advanced search + if (is_array(self::$request->sel_options[self::$prefix.$fname])) + { + self::$request->sel_options[self::$prefix.$fname] += (array)$field['values']; + } + else + { + self::$request->sel_options[self::$prefix.$fname] = $field['values']; + } //error_log(__METHOD__."('$fname', ".array2string($field).") request->sel_options['".self::$prefix.$fname."']=".array2string(self::$request->sel_options[$this->id])); break; } diff --git a/etemplate/inc/class.so_sql_cf.inc.php b/etemplate/inc/class.so_sql_cf.inc.php index 3e923dbbc2..c8dc570af5 100644 --- a/etemplate/inc/class.so_sql_cf.inc.php +++ b/etemplate/inc/class.so_sql_cf.inc.php @@ -464,7 +464,10 @@ class so_sql_cf extends so_sql foreach($criteria as $name => $val) { // only add extra_join, if we really need it - if (!$extra_join_added && is_int($name) && strpos($val, $this->extra_value) !== false) + if (!$extra_join_added && ( + is_int($name) && strpos($val, $this->extra_value) !== false || + is_string($name) && $this->is_cf($name) + )) { $join .= $this->extra_join; $extra_join_added = true; diff --git a/etemplate/js/et2_widget_selectAccount.js b/etemplate/js/et2_widget_selectAccount.js index e56f9c0a16..a6d88c39c2 100644 --- a/etemplate/js/et2_widget_selectAccount.js +++ b/etemplate/js/et2_widget_selectAccount.js @@ -370,7 +370,7 @@ var et2_selectAccount = et2_selectbox.extend( } else { - this.options.select_options.push({value: key, label: options}); + this.options.select_options.push({value: key, label: options[key]}); } } }