AjaxPlugins.Search = {
handleResponse: function(pluginOutput) {
//we inject the select input in the HTML
if (pluginOutput.htmlCode.communes_init_dep) {
//should be the same value as the input search_config
$('departement_select_div').innerHTML = pluginOutput.htmlCode.communes_init_dep;
}
if (pluginOutput.htmlCode.communes_init_com) {
//should be the same value as the input search_config
$('ville_select_div').innerHTML = pluginOutput.htmlCode.communes_init_com;
}
if (pluginOutput.htmlCode.communes) {
//should be the same value as the input search_config
$('search_results_div').innerHTML = pluginOutput.htmlCode.communes;
}
}
};
/*
* 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')
}
//we empty the old selects and reinsert the new ones instead
//Please do not forget to modify the search_config input value
function initializeTown() {
$('departement_select_div').innerHTML = '';
var myinput = $('search_config');
myinput.value = 'communes_init_dep';
CartoWeb.trigger('Search.DoIt');
}
function initializeStreet() {
$('ville_select_div').innerHTML = '';
var myinput = $('search_config');
myinput.value = 'communes_init_com';
CartoWeb.trigger('Search.DoIt');
}
function search() {
var myinput = $('search_config');
myinput.value = 'communes';
CartoWeb.trigger('Search.DoIt');
}
function recenter(id){
if ($('search_config').value == 'communes') {
//id to recenter, be sure there is a hidden input
//with that name and id in your template! if not, add it
$('id_recenter_ids').value = id;
/* if the search database table name is the same
as the related layer to recenter on, you can set it as below
be sure there is a hidden input with that name and id in your template! if not, add it */
$('id_recenter_layer').value = $('search_config').value;
/* do not use the recenter_scale parameter
if you recenter on ids, only use it with recenter on x,y.
you can set the recenter scale in location.ini on server side */
/* do not use the recenter_doit parameter
if you recenter on ids, only use it with recenter on x,y. */
CartoWeb.trigger('Location.Recenter');
}
}
Event.observe(window, 'load', initializeTown, true);


