%--
/******************************************************************************
* Copyright (c) 2000-2009 e-Deal
*
* e-Deal S.A.
* 55 rue Brillat Savarin
* 75013 Paris
* France
*
* T: +33 (0)1 53 80 80 30
* F: +33 (0)1 73 01 69 77
* http://www.e-deal.com
*
* La diffusion de ce code source sous quelque forme que ce soit sans
* l'autorisation de E-DEAL est interdite.
*
* Vous êtes autorisés à modifier ce code source uniquement pour votre usage
* propre et sous réserve que les mentions de copyright demeurent intactes.
*
* Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
* implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
* responsable des dommages pouvant résulter de l'utilisation de ce code
* source.
******************************************************************************/
--%>
<%@ page language="java" contentType="text/plain;charset=UTF-8"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="com.edeal.frontline.Utils" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<%
FlRequest flRequest = new FlRequest(request);
String field = flRequest.getRequestParameterOrAttribute("field");
String formName = flRequest.getRequestParameterOrAttribute("formName");
String city = flRequest.getRequestParameterOrAttribute("cityarg");
if (city == null) {
city = "";
}
String rest[] = city.split(",");
if (formName != null) {
try {
Integer.parseInt(formName);
} catch (NumberFormatException nfe) {
formName = "'" + formName + "'";
}
} else {
formName = "0";
}
%>
var field = window.document.forms[<%= formName %>].<%= field %>;
var arrayOption = [<%= Utils.implodeList(rest, ", ", "\"") %>];
// Do we have multiple choices?
if (arrayOption.length > 1 && arrayOption[0] != 'nothing' && arrayOption[0] != '') {
field.value = '';
var combobox = document.getElementById('CBX');
if (combobox == null) {
var combobox = document.createElement("select");
combobox.setAttribute("id", "CBX");
} else {
while (combobox.options.length > 0) {
combobox.remove(0);
}
}
var parent = field.parentNode;
field.style.display = 'none';
// Indicate that there is more than one choice
var o = document.createElement("option");
o.value = "";
o.appendChild(document.createTextNode(''));
combobox.appendChild(o);
// Add the city choices
for (var i = 0; i < arrayOption.length; i++) {
o = document.createElement("option");
o.value = arrayOption[i];
o.appendChild(document.createTextNode(arrayOption[i]));
combobox.appendChild(o);
}
// Option to select if they don't like the choices
o = document.createElement("option");
o.value = "";
o.appendChild(document.createTextNode("<>"));
combobox.appendChild(o);
// Finally, the script to revert to an input
parent.insertBefore(combobox, field);
combobox.onchange = function() {
var field2 = window.document.forms[<%= formName %>].<%= field %>;
var bc = document.getElementById('CBX');
field2.style.display = 'inline';
field2.value = bc.value;
$("#" + field.id).trigger("change");
field2.parentNode.removeChild(bc);
if (field2.value == '') {
field2.focus();
}
}
}
// If we have just one option, select it and return.
if (arrayOption.length == 1 && arrayOption[0] != 'nothing' && arrayOption[0] != '') {
var bc = document.getElementById('CBX');
if(bc){
field.parentNode.removeChild(bc);
}
field.style.display = 'inline';
field.value = arrayOption[0];
$("#" + field.id).trigger("change");
}