[Cartoweb-users] Plugin Search - Guided Search
veroh at bluewin.ch
veroh at bluewin.ch
Mon Apr 23 15:38:35 EDT 2007
Hello,
I tried and succedded doing the basic sample for the plugin Search
and also a guided search on only one table and column but with a
clause where.
I am now trying to do the guided search with combining the result
from two column with the dropdown menu for choosing the first column
(in my case the type of work and not the town as in the exemple) and
the second column (with already a selection on the first column, in
my case a date of execution).
Well, it does not work... yet but who knows ....
So basically, here is my search.ini file
config.Travaux_POSTGIS_MAJ.provider.type = table
config.Travaux_POSTGIS_MAJ.provider.table = maj2
config.Travaux_POSTGIS_MAJ.provider.id = travaux
config.Travaux_POSTGIS_MAJ.provider.columns = travaux
config.Travaux_POSTGIS_MAJ.provider.sortColumn = travaux
config.Travaux_POSTGIS_MAJ.provider.sortDirection = asc
config.Travaux_POSTGIS_MAJ.formatter.type = smarty
config.Travaux_POSTGIS_MAJ.formatter.template =
init_travaux_select
config.Date_POSTGIS_MAJ.provider.type = table
config.Date_POSTGIS_MAJ.provider.table = maj2
config.Date_POSTGIS_MAJ.provider.id = date
config.Date_POSTGIS_MAJ.provider.columns = date
config.Date_POSTGIS_MAJ.provider.sortColumn = date
config.Date_POSTGIS_MAJ.provider.sortDirection = asc
config.Date_POSTGIS_MAJ.provider.where = "date like '@init_date@'"
config.Date_POSTGIS_MAJ.formatter.type = smarty
config.Date_POSTGIS_MAJ.formatter.template = init_date_select
config.POSTGIS_MAJ.provider.type = table
config.POSTGIS_MAJ.provider.table = maj2
config.POSTGIS_MAJ.provider.id = gid
config.POSTGIS_MAJ.provider.columns = mandat_n16, travaux,
en_cours, date, test
config.POSTGIS_MAJ.provider.sortColumn = mandat_n16
config.POSTGIS_MAJ.provider.sortDirection = asc
config.POSTGIS_MAJ.provider.sortPriorities = mandat_n16, date,
travaux, en_cours, test
config.POSTGIS_MAJ.formatter.type = smarty
config.POSTGIS_MAJ.formatter.template = search_results
config.POSTGIS_MAJ.provider.where = "date like '@init_date@' and
travaux like '@init_travaux@'"
With Travaux and Date being the nam eof the two columns.
I did then a init_travaux_select.tpl
{t}Type of work :{/t}
<br />
<select name="init_date" id="travaux_init" onchange="javascript:
initializeDate()">
<option value="">
 
</option>
{foreach from=$table->rows item=row}
<option value="{$row->rowId}">
{foreach from=$row->cells item=value}
{$value}
{/foreach}
</option>
{/foreach}
</select>
and a init_date.tpl
{t}Date :{/t}
<br />
<select name="guided_POSTGIS_MAJ_date" id="init_date" onchange="
search()" >
<option value="">  </option>
{foreach from=$table->rows item=row}
<option value="{$row->rowId}">
{foreach from=$row->cells item=value}
{$value}
{/foreach}
</option>
{/foreach}
</select>
I did not modify my search.tpl (which is something strange but then
no mention of it in the doc), so it goes like that
<div id="search_div">
<fieldset>
<legend>{t}Search{/t}
</legend>
<br/>
<table width="100%">
<tr>
<td>
{t}Type of work
{/t}
</td>
<td>
<input type="text" id="travaux" name="travaux" size="13"/>
</td>
</tr>
<tr>
<td>
{t}Date
{/t}
</td>
<td>
<input type="text" id="date" name="date" 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"
value="POSTGIS_MAJ"/>
<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" />
</p>
</fieldset>
</div>
<div id="search_results">
</div>
And I modified the Search.Ajax.js
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 initializeTravaux() {
$('travaux_select_div').innerHTML = '';
var myinput = $('search_config');
myinput.value = 'Travaux_POSTGIS_MAJ';
CartoWeb.trigger('Search.DoIt');
}
function initializeDate() {
$('date_select_div').innerHTML = '';
var myinput = $('search_config');
myinput.value = 'Date_POSTGIS_MAJ';
CartoWeb.trigger('Search.DoIt');
}
function search() {
var myinput = $('search_config');
myinput.value = 'POSTGIS_MAJ';
CartoWeb.trigger('Search.DoIt');
}
function recenter(id) {
if ($('search_config').value == 'POSTGIS_MAJ') {
$('id_recenter_ids').value = id; //id to recenter
$('recenter_scale').value = 2000; //scale for recentering
$('recenter_doit').value = '0';
CartoWeb.trigger('Location.Recenter');
}
Event.observe(window, 'load', initializeTravaux, true);
}
I did not modify anything else and .. it does not work.
What did I forger ? Well I don't see how it call the new two tpl.
In one word as in one hundred, can anyone help ?
V.
More information about the Cartoweb-users
mailing list