improved advanced search:

- fixed not working paging (lost advanced search)
- uses now a named window and gives it focus
- disabled for org-views
- can be unset via clicking on the addressbook icon (index.php)
- last search can always be restored from session
This commit is contained in:
Ralf Becker 2006-10-31 07:56:34 +00:00
parent ba311860b0
commit 25055b8603
4 changed files with 62 additions and 44 deletions

View File

@ -54,7 +54,7 @@ class contacts_admin_prefs
array(
'text' => '<a class="textSidebox" href="'.$GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'addressbook.uicontacts.search',)).
'" onclick="window.open(this.href,\'_blank\',\'dependent=yes,width=850,height=480,scrollbars=yes,status=yes\');
'" onclick="window.open(this.href,\'advanced_search\',\'dependent=yes,width=850,height=480,scrollbars=yes,status=yes\');
return false;">'.lang('Advanced search').'</a>',
'no_lang' => true,
'link' => false

View File

@ -489,6 +489,28 @@ class uicontacts extends bocontacts
*/
function get_rows(&$query,&$rows,&$readonlys,$id_only=false)
{
$old_state = $GLOBALS['egw']->session->appsession('index','addressbook');
if (isset($this->org_views[(string) $query['org_view']])) // we have an org view, reset the advanced search
{
if (is_array($query['search'])) unset($query['search']);
unset($query['advanced_search']);
}
elseif (is_array($query['search'])) // new advanced search, store it in the session
{
$query['advanced_search'] = array_intersect_key($query['search'],array_flip(array_merge($this->get_contact_columns(),array('operator','meth_select'))));
foreach ($query['advanced_search'] as $key => $value)
{
if(!$value) unset($query['advanced_search'][$key]);
}
$query['start'] = 0;
$query['search'] = '';
// store the advanced search in the session to call it again
$GLOBALS['egw']->session->appsession('advanced_search','addressbook',$query['advanced_search']);
}
elseif(!$query['search'] && $old_state['advanced_search']) // eg. paging in an advanced search
{
$query['advanced_search'] = $old_state['advanced_search'];
}
if (($do_email=$query['do_email']) && $GLOBALS['egw_info']['etemplate']['loop'] && is_object($GLOBALS['egw']->js))
{ // remove previous addEmail() calls, otherwise they will be run again
$GLOBALS['egw']->js->body['onLoad'] = preg_replace('/addEmail\([^)]+\);/','',$GLOBALS['egw']->js->body['onLoad']);
@ -496,7 +518,6 @@ class uicontacts extends bocontacts
//echo "<p>uicontacts::get_rows(".print_r($query,true).")</p>\n";
if (!$id_only)
{
$old_state = $GLOBALS['egw']->session->appsession('index','addressbook');
// check if accounts are stored in ldap, which does NOT yet support the org-views
if ($this->so_accounts && $query['filter'] === '0' && $query['org_view'])
{
@ -513,7 +534,6 @@ class uicontacts extends bocontacts
{
$query['searchletter'] = ''; // reset lettersearch if viewing the contacts of one organisation
}
unset($old_state);
$GLOBALS['egw']->session->appsession($do_email ? 'email' : 'index','addressbook',$query);
// save the state of the index in the user prefs
$state = serialize(array(
@ -531,6 +551,8 @@ class uicontacts extends bocontacts
$GLOBALS['egw']->preferences->save_repository(false,'user',false);
}
}
unset($old_state);
if ((string)$query['cat_id'] != '')
{
$query['col_filter']['cat_id'] = $query['cat_id'] ? $query['cat_id'] : null;
@ -596,25 +618,17 @@ class uicontacts extends bocontacts
}
$wildcard = '%';
$op = 'OR';
if (is_array($query['search'])) // Advanced Search
if ($query['advanced_search'])
{
$op = $query['search']['operator'];
$wildcard = $query['search']['meth_select'];
$advanced_search = $query['search'];
$query['search'] = array_intersect_key($query['search'],array_flip($this->get_contact_columns()));
foreach ($query['search'] as $key => $value) {
if(!$value) unset($query['search'][$key]);
}
if (empty($query['search'])) {
$query['search'] = '';
unset($advanced_search);
}
$op = $query['advanced_search']['operator'];
unset($query['advanced_search']['operator']);
$wildcard = $query['advanced_search']['meth_select'];
unset($query['advanced_search']['meth_select']);
}
$rows = parent::search($query['search'],$id_only ? array('id','org_name','n_family','n_given','n_fileas') : false,
$rows = parent::search($query['advanced_search'] ? $query['advanced_search'] : $query['search'],
$id_only ? array('id','org_name','n_family','n_given','n_fileas') : false,
$order,'',$wildcard,false,$op,array((int)$query['start'],(int) $query['num_rows']),$query['col_filter']);
if( is_array($advanced_search) ) {
$query['search'] = '';
}
// do we need the custom fields
if (!$id_only && $this->prefs['custom_colum'] != 'never' && $rows && $this->customfields)
{
@ -749,6 +763,10 @@ class uicontacts extends bocontacts
{
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.$query['org_view_label'];
}
if($query['advanced_search'])
{
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang('Advanced search');
}
if ($query['cat_id'])
{
if (!is_object($GLOBALS['egw']->categories))
@ -757,19 +775,16 @@ class uicontacts extends bocontacts
}
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.lang('Category').' '.$GLOBALS['egw']->categories->id2name($query['cat_id']);
}
if ($query['searchletter'])
if ($query['searchletter'])
{
$order = $order == 'org_name' ? lang('company name') : ($order == 'n_given' ? lang('first name') : lang('last name'));
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("%1 starts with '%2'",$order,$query['searchletter']);
}
if ($query['search'])
if ($query['search'])
{
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("Search for '%1'",$query['search']);
}
if(is_array($advanced_search)) {
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.lang("Advanced search");
}
return $this->total;
return $this->total;
}
/**
@ -1295,10 +1310,12 @@ $readonlys['button[vcard]'] = true;
}
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
$GLOBALS['egw_info']['flags']['java_script'] .= $this->js();
$GLOBALS['egw_info']['flags']['java_script'] .= "<script>window.focus()</script>";
$GLOBALS['egw_info']['etemplate']['advanced_search'] = true;
// initialize etemplate arrays
$content = $sel_options = $readonlys = $preserv = array();
$sel_options = $readonlys = $preserv = array();
$content = $GLOBALS['egw']->session->appsession('advanced_search','addressbook');
for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
$sel_options['tz'] = $tz + array('' => lang('doesn\'t matter'));
@ -1315,11 +1332,6 @@ $readonlys['button[vcard]'] = true;
'%' => lang('contains'),
false => lang('exact'),
);
$index_nm = $GLOBALS['egw']->session->appsession($do_email ? 'email' : 'index','addressbook');
if (array_key_exists('meth_select',$index_nm['search'])) {
$content = $index_nm['search'];
}
// configure edit template as search dialog
$readonlys['change_photo'] = true;
$readonlys['fileas_type'] = true;
@ -1328,7 +1340,8 @@ $readonlys['button[vcard]'] = true;
$readonlys['personal|organisation|home|details|links']['links'] = true;
$content['hidebuttons'] = true;
$content['no_tid'] = true;
$content['disable_change_org'] = true;
$this->tmpl->read('addressbook.search');
return $this->tmpl->exec('addressbook.uicontacts.search',$content,$sel_options,$readonlys,$preserv,2);
}

View File

@ -19,6 +19,11 @@
));
include('../header.inc.php');
ExecMethod('addressbook.uicontacts.index');
$GLOBALS['egw']->common->egw_footer();
// check if we have an advanced search and reset it in case
$old_state = $GLOBALS['egw']->session->appsession('index','addressbook');
if ($old_state['advanced_search'])
{
unset($old_state['advanced_search']);
$GLOBALS['egw']->session->appsession('index','addressbook',$old_state);
}
$GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uicontacts.index');

View File

@ -58,7 +58,7 @@
<row>
<image src="private.png"/>
<description value="Addressbook" options=",,,owner"/>
<menulist span=",owner">
<menulist class="owner">
<menupopup id="owner" statustext="Addressbook the contact should be saved to" no_lang="1"/>
</menulist>
</row>
@ -83,7 +83,7 @@
<row>
<description/>
<description options=",,,role" value="Role"/>
<hbox orient=",0,0">
<hbox options="0,0">
<textbox id="role" size="25" maxlength="64"/>
<textbox size="8" maxlength="64" label="Room" align="right" id="room"/>
</hbox>
@ -128,7 +128,7 @@
<row>
<description/>
<description value="country" options=",,,adr_one_countryname"/>
<menulist span=",fullWidth">
<menulist class="fullWidth">
<menupopup type="select-country" options="Select one,1" id="adr_one_countryname"/>
</menulist>
<description/>
@ -177,14 +177,14 @@
<row>
<description/>
<description value="country" options=",,,adr_two_countryname"/>
<menulist span=",fullWidth">
<menulist class="fullWidth">
<menupopup type="select-country" options="Select one,1" id="adr_two_countryname"/>
</menulist>
</row>
<row height="30">
<image src="gear"/>
<description options=",,,bday" value="Birthday"/>
<hbox id="bday" orient=",0,0">
<hbox id="bday" options="0,0">
<date options="Y-m-d" id="bday"/>
<menulist>
<menupopup id="tz" no_lang="1" label="Timezone" align="right"/>
@ -340,7 +340,7 @@
<description/>
</row>
<row>
<menulist span=",fileas">
<menulist class="fileas">
<menupopup data="" rows="1" cols="3" id="fileas_type" no_lang="1"/>
</menulist>
<grid>
@ -350,7 +350,7 @@
</columns>
<rows>
<row disabled="@no_tid">
<menulist span=",leftPad5">
<menulist class="leftPad5">
<menupopup no_lang="1" id="tid" onchange="1" label="Type"/>
</menulist>
<html class="space" needed="1" label=" " no_lang="1" id="typegfx" readonly="true"/>
@ -449,8 +449,8 @@
</vbox>
</row>
<row>
<hbox orient=",0,0">
<menulist span=",leftPad5">
<hbox options="0,0">
<menulist class="leftPad5">
<menupopup type="select-account" id="creator" readonly="true" label="Created"/>
</menulist>
<date-time id="created" class="leftPad5" readonly="true"/>