From 4c56f3e678c50671fc19cf3a1680761fd02311c4 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 19 Aug 2009 21:20:51 +1000 Subject: [PATCH] Fix AJAX rendering of query results --- lib/Query.php | 2 + lib/QueryRender.php | 138 ++++++++++++++++++----------------------- lib/TemplateRender.php | 2 +- 3 files changed, 63 insertions(+), 79 deletions(-) diff --git a/lib/Query.php b/lib/Query.php index 18b02bf..f311f99 100644 --- a/lib/Query.php +++ b/lib/Query.php @@ -135,6 +135,8 @@ class Query extends xmlTemplate { $bases = get_request('base','REQUEST',false,null); $query['filter'] = get_request('filter','REQUEST',false,'objectClass=*'); $query['scope'] = get_request('scope','REQUEST',false,'sub'); + $query['size_limit'] = get_request('size_limit','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','size_limit')); + $query['format'] = get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')); $attrs = get_request('display_attrs','REQUEST'); $attrs = preg_replace('/\s+/','',$attrs); diff --git a/lib/QueryRender.php b/lib/QueryRender.php index aeeaf4c..70e951d 100644 --- a/lib/QueryRender.php +++ b/lib/QueryRender.php @@ -262,30 +262,29 @@ function hideall(key,except) { $this->drawBaseTabs(); $ado = $this->template->getAttrDisplayOrder(); + $counter = 0; - switch(get_request('format','REQUEST',false,'table')) { - case 'list': + foreach ($this->template->results as $base => $results) { + $counter++; - $counter = 0; + if (! $show = get_request('show','REQUEST')) + $show = ($counter === 1 ? $this->getAjaxRef($base) : null); - foreach ($this->template->results as $base => $results) { - if (! $show = get_request('show','REQUEST')) - $show = ($counter++ === 0 ? $this->getAjaxRef($base) : null); + printf('
', + $this->getAjaxRef($base), ($show == $this->getAjaxRef($base) ? '' : 'none')); - printf('
', - $this->getAjaxRef($base), - ($show == $this->getAjaxRef($base) ? '' : 'none')); + echo ''; + echo ''; - $counter = 0; + $j = 0; foreach ($results as $dn => $dndetails) { - $counter++; + $j++; $dndetails = array_change_key_case($dndetails); # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) $this->template->setDN($dn); - printf('', - $counter%2 ? 'odd' : 'even',$counter,$counter); + printf('', + $j%2 ? 'even' : 'odd',$j,$counter,$j,$counter); # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) - printf('',$counter,$dn); + printf('',$j,$counter,$dn); $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($dn)); printf('', @@ -454,12 +425,14 @@ function hideall(key,except) { # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) { - printf('',++$counter%2 ? 'odd' : 'even',$counter); - echo ''; + printf('',++$j%2 ? 'odd' : 'even'); + printf('',$counter); printf(''; echo ''; @@ -468,19 +441,30 @@ function hideall(key,except) { echo ''; echo '
'; + echo '
'; + echo '
'; - echo ''; - echo ''; - echo '
'; - echo '
'; - echo '
'; + $this->drawResultsTable($base,count($results)); - $this->drawResultsTable($base,count($results)); - - echo '
'; - echo '
'; + echo '
'; + echo '
'; + switch(get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display'))) { + case 'list': foreach ($results as $dn => $dndetails) { $dndetails = array_change_key_case($dndetails); @@ -338,45 +337,17 @@ function hideall(key,except) { echo '
'; } - echo '
'; - echo ''; - - echo "\n\n"; - } - - break; - - case 'table': + break; # Display the results. - $counter = 0; - foreach ($this->template->results as $base => $results) { - if (! $show = get_request('show','REQUEST')) - $show = ($counter++ === 0 ? $this->getAjaxRef($base) : null); - - printf('
', - $this->getAjaxRef($base), - ($show == $this->getAjaxRef($base) ? '' : 'none')); - - echo ''; - echo '
'; - echo '
'; - echo '
'; - - $this->drawResultsTable($base,count($results)); - - echo '
'; - echo '
'; - + case 'table': if (! $results) { echo _('Search returned no results'); - echo '
'; - echo '
'; + continue; } - echo '
'; + printf('',$counter); printf('',$server->getIndex()); foreach ($this->template->resultsdata[$base]['attrs'] as $attr) @@ -399,20 +370,20 @@ function hideall(key,except) { echo ''; echo '
icon
',2+count(explode(',',$ado))); echo ''; echo '
'; echo ''; - echo ''; - echo ''; - echo '
'; echo "\n\n"; - echo ''; - } - - break; - - default: - printf('Have ID [%s], run this query for page [%s]',$this->template_id,$this->page); - } + echo ''; + } } public function drawSubTitle($subtitle=null) { @@ -596,13 +574,17 @@ var deon=0; foreach (array('list','table') as $f) { echo ' '; - if (get_request('format','REQUEST') == $f) { + if (get_request('format','REQUEST',false,$_SESSION[APPCONFIG]->getValue('search','display')) == $f) { printf('%s',_($f)); } else { - $query_string = array_to_query_string($_GET,array('format','cmd')); - $query_string .= sprintf('&format=%s&show=%s',$f,$this->getAjaxRef($base)); - printf('%s',htmlspecialchars($query_string),_($f)); + $query_string = htmlspecialchars(sprintf('%s&format=%s&show=%s&focusbase=%s',array_to_query_string($_GET,array('format','meth')),$f,$this->getAjaxRef($base),$base)); + + if (isAjaxEnabled()) + printf('%s', + $query_string,$query_string,_('Loading Search'),_($f)); + else + printf('%s',$query_string,_($f)); } } diff --git a/lib/TemplateRender.php b/lib/TemplateRender.php index 65144f2..e780aad 100644 --- a/lib/TemplateRender.php +++ b/lib/TemplateRender.php @@ -1327,7 +1327,7 @@ class TemplateRender extends PageRender { if (DEBUGTMP) printf('%s
',__METHOD__); - $href = sprintf('cmd=query_engine&server_id=%s&filter=%s&base=%s&scope=one&query=none', + $href = sprintf('cmd=query_engine&server_id=%s&filter=%s&base=%s&scope=one&query=none&size_limit=0', $this->getServerID(),rawurlencode('objectClass=*'),rawurlencode($this->template->getDN())); if (isAjaxEnabled())