[Cartoweb-users] Plugin search not working

veroh at bluewin.ch veroh at bluewin.ch
Tue Apr 17 04:48:30 EDT 2007


Hello,

I am trying to implement the plugin search in my project but I got 
the following error

--- Action Search.DoIt triggered ---

Calling Search.DoIt onBeforeAjaxCall()

Calling AjaxPlugins.Common.onBeforeAjaxCall()
Initiating AJAX request
Pending actions: 1
GET params:
ajaxActionRequest=Search.DoIt&
POST params:

posted=1&js_folder_idx=5&js_toolbar_idx=&selection_type=&selection_coords=&features=&js_accounting=version=0;
hasJava=true;winInnerWidth=1024;winInnerHeight=578;screenWidth=1024;
screenHeight=768;screenColorDepth=32&outline_label_text=votre 
titre&tool=zoomin&project=n16&recenter_x=&recenter_y=&recenter_doit=0&shortcut_doit=0&openNodes=&layers
[]=OPA&layers[]=OPB&layers[]=OPC&layers[]=OPD&layers[]=OPE&layers[]
=OPF&layers[]=OPG&layers[]=OPH&layers[]=N16&layers[]
=POSTGIS_MAJ&layers[]=EDITPOINT&layers[]=EDITPOLY&layers[]
=EDITLINE&pdfMarginX=20&pdfMarginY=20&pdfA4x=210&pdfA4y=297&pdfA3x=297&pdfA3y=420&pdfOrientation=portrait&pdfMapAngle=&pdfMapCenterX=&pdfMapCenterY=&pdfTitle=&pdfNote=&pdfScalebar=&pdfLegend=0&viewTitle=&author=&handleView=0&locate_MAJ=&locate_MAJ2=&id_recenter_ids=&search_mandat_n16=N2354&search_travaux=&search_date_txt=&search_en_cours=&search_config=&search_sort_column=&search_sort_direction=asc&search_number=&outline_mask=no&outline_point_symbol=circle&outline_point_size=10&outline_line_size=3&outline_line_transparency=100&outline_polygon_transparency=60&edit_validate_all=0&recenter_scale=0&shortcut_id=-
1&mapsize=1&pdfFormat=A4&pdfResolution=96&pdfScale=2500&id_recenter_layer=MAJ&edit_layer=0&
Waiting for response...
Response received!
Error: AjaxHandler.actionRequest(): received response is 
malformed!

I have a search.ini file in my client_conf :

config.POSTGIS_MAJ.provider.type = fulltextTable
config.POSTGIS_MAJ.provider.table = maj2
config.POSTGIS_MAJ.provider.id = gid
config.POSTGIS_MAJ.provider.columns = mandat_n16, travaux, 
date_txt, en_cours
config.POSTGIS_MAJ.provider.fulltextColumns = mandat_n16, travaux, 
date_txt, en_cours
config.POSTGIS_MAJ.provider.sortColumn = date_txt
config.POSTGIS_MAJ.provider.sortDirection = asc
config.POSTGIS_MAJ.provider.sortPriorities = date_txt, mandat_n16, 
travaux, en_cours
config.POSTGIS_MAJ.provider.labels = mandat_n16, travaux, date_txt, 
en_cours

config.POSTGIS_MAJ.formatter.type = smarty
config.POSTGIS_MAJ.formatter.template = search_results

Where POSTGIS is the layer I declared in my MAP file which is a 
POSTGRESQL/POSTGIS table (maj2) and gid is the 'id_attribute_string'

I have also one in the server_side :

dbType = pgsql
dsn = pgsql://postgres:afgan6@localhost:5432/demo_n16

config.POSTGIS_MAJ.provider.type = fulltextTable
config.POSTGIS_MAJ.provider.table = maj2
config.POSTGIS_MAJ.provider.id = gid
config.POSTGIS_MAJ.provider.columns = mandat_n16, travaux, 
date_txt, en_cours
config.POSTGIS_MAJ.provider.fulltextColumns = mandat_n16, travaux, 
date_txt, en_cours
config.POSTGIS_MAJ.provider.sortColumn = date_txt
config.POSTGIS_MAJ.provider.sortDirection = asc
config.POSTGIS_MAJ.provider.sortPriorities = date_txt, mandat_n16, 
travaux, en_cours
config.POSTGIS_MAJ.provider.labels = mandat_n16, travaux, date_txt, 
en_cours

config.POSTGIS_MAJ.formatter.type = smarty
config.POSTGIS_MAJ.formatter.template = search_results

I modified my cartoclient.tpl by adding two lines

{if $search_active|default:''}<script type="text/javascript" src="
{r type=js plugin=search}Search.ajax.js{/r}"></script>{/if}
which is just after the one for the Ajax ({if $ajaxOn|default:''} 
etc..)
and in the div="container", I added in one of my div=folder : 
{if $search_active|default:''} {$search} {/if}

I got in templates, two files :

search.tpl:

<div id="search_div">
	<fieldset>
		<legend>{t}Search{/t}
		</legend>
		<br/>
		<table width="100%">
			<tr>
			<td>
				{t}Mandat: {/t}
			</td>
			
			<td>
				<input type="text" id="search_mandat_n16" name="
search_mandat_n16" size="13"/>
			</td>
			</tr>
			
			<tr>
			<td>
				{t}Type de travaux: {/t}
			</td>
			
			<td>
				<input type="text" id="search_travaux" name="search_travaux" 
size="13"/>
			</td>
			</tr>

			<tr>
			<td>
				{t}Date: {/t}
			</td>
			
			<td>
				<input type="text" id="search_date_txt" name="search_date_txt" 
size="13"/>
			</td>
			</tr>			
			
			<tr>
			<td>
				{t}En cours ou non: {/t}
			</td>
			
			<td>
				<input type="text" id="search_en_cours" name="search_en_cours" 
size="13"/>
			</td>
			</tr>
		</table>
		
		<p>
			<input type="submit" value="{t}Search{/t}" class="form_button" 
onclick="Javascript: CartoWeb.trigger('Search.DoIt'); return false;" 
/>
			<input type="hidden" id="search_config" name="search_config" />
			<input type="hidden" id="search_sort_column" name="
search_sort_column" />
			<input type="hidden" id="search_sort_direction" name="
search_sort_direction" value="asc" />
			<input type="hidden" id="search_number" name="search_number" />
					
			<div id="search_results_div">
			</div>
		</p>
	</fieldset>
</div>

and search_results.tpl

{if $table->numRows > 0}
	<table class="n16table">
		<tr>
			<th>
				{t}Id{/t}
			</th>
			{foreach from=$table->columnIds item=column}
				<th>
					<a href="Javascript: order('{$column}');">{t}{$column}{/t}
</a>
				</th>
			{/foreach}
		</tr>
		
		{foreach from=$table->rows item=row}
		<tr>
		{foreach from=$row->cells item=value}
		<td>
			<a href="Javascript: recenter('{$row->rowId}');">{$value}</a>
		</td>
		{/foreach}
		</tr>
		{/foreach}
	</table>
{else}
{t}No results{/t}
{/if}


Last but not least, I got the js ! Namely Search.ajax.js

AjaxPlugins.Search = {
  
    handleResponse: function(pluginOutput) {
        
        if (pluginOutput.htmlCode.POSTGIS_MAJ)
            $('search_results').innerHTML = pluginOutput.htmlCode.
POSTGIS_MAJ;
			}
			};


/*
 * Search plugin's Actions
 */
 
AjaxPlugins.Search.Actions = {};

AjaxPlugins.Search.Actions.DoIt = {

    buildPostRequest: function(argObject) {
        return AjaxHandler.buildPostRequest();
    }
};

function order(column) {
    
    if (column != $('search_sort_column').value){
	$('search_sort_column').value = column;
	$('search_sort_direction').value = 'asc';
	} else {
	if ($('search_sort_direction').value == 'asc') {
	$('search_sort_direction').value = 'desc';
	} else {
	$('search_sort_direction').value = 'asc';
	}
	}
    
    CartoWeb.trigger('Search.DoIt');
}

function recenter(id) {
	if ($('search_config').value == 'POSTGIS_MAJ') {
    $('id_recenter_ids').value = gid; //id to recenter
	$('recenter_scale').value = 1000; //scale for recentering
	$('recenter_doit').value = '1';
    
    CartoWeb.trigger('Location.Recenter');
}

I guess you now know all I did. Could someone please tell me what 
is wrong.

Apparently, someone else asked the same thing last month but no 
final answer was given on the mail list.

PS : Yes, I did clean all the file before trying

Véronique



More information about the Cartoweb-users mailing list