<%
/******************************************************************************
 * Copyright (c) 2000-2005 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 session="true" import="com.edeal.frontline.*"%>
<%@ page import="java.util.*" %>
<%@ page import="com.edeal.frontline.grid.GridData" %>
<%@ page import="java.util.Vector" %>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@ page import="java.lang.reflect.Method" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="com.edeal.frontline.controller.actions.SelectAction" %>
<%@ page import="com.edeal.frontline.helper.custom.EventHelper" %>
<%@ page import="com.edeal.frontline.helper.EventBaseHelper.StatusType" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.edeal.frontline.initializers.ScriptEventInitializer" %> 
<%@ page import="com.edeal.frontline.helper.EventBaseHelper.EventCategory" %> 
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.ScriptBean" id="Script" scope="request"/>
<%
	final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
	FlRequest flRequest = new FlRequest(request);
	FlContext context = flRequest.getContext();

	String action = flRequest.getRequestParameterOrAttribute("action");
	String label = null;
	String newScriptID = null;
	
	String id = null;
	try {
		id = Script.getID();
	}catch (FieldNotInitializedException fnie) {
	}
	

	String scrEventID = null;
	try {
		scrEventID = Script.getScrEventID();
	} catch (FieldNotInitializedException fnie) {
		scrEventID = "";
	}

	String dispEvent = null;

	DecimalFormat df = FlLocale.getInstance(session).getDecimalFormat("0000");
	String eLabel = "";
	
	String commentaireEvt = Utils.getMessage(session, "M6111", "Les événements déjà attachées à une questionnaire ne seront pas disponibles");
	
	
	//get sequence number
	int seqNum = 0;
	
	try {
		seqNum = Script.getScrSeqNum();
	} catch (FieldNotInitializedException fnie) {
		seqNum = CounterFactory.getCounter(context , "ScriptNum");
	}
	
	LinkedHashMap<String, String> listParticipationStatusIDAndDisplay = (LinkedHashMap<String, String>) flRequest.getAttribute(ScriptEventInitializer.LIST_PARTICIPATION_STATUS);
	if (listParticipationStatusIDAndDisplay == null) {
		listParticipationStatusIDAndDisplay = new LinkedHashMap<String, String>();
	}
	
	String scrParStatus = null;
	try {
		scrParStatus = Script.getScrParStatus();
	} catch (FieldNotInitializedException fnie) {
	}
%>
<script type="text/javascript" language="javascript">

	function doSubmit() {
		var mf = document.forms[0];
		if (mf.ScrLabel.value == '') {
			window.alert('<fl:getMessage code="M2002" alt="Veuillez spécifier un libellé." js="true"/>');
			mf.ScrLabel.focus();
			return false;
		}
		return true;
	}
	function clearEvent(){
		var f = window.document.forms[0];
		f.lblScrEventID.value='';
		f.ScrEventID.value='';
	}	
	function doScrEventIDChange() {		
		var f = document.forms[0];
		f.action = "<fl:webapp/>/refresh_script.fl";
		f.submit();
	}
	
</script>
<fl:form action="/save_script.fl" bean="Script">
<input type="hidden" name="ScrSeqNum" value="<%=seqNum %>"/>
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"L63F9\", false, true, \"Script\") %>" ou="<%= \"/edit_script.fl\" + ( id != null ? \"?id=\" + id : \"\") %>" listTitle="<%= Utils.getMessage(session, \"L61ED\", false, true, \"Liste des scripts\") %>">	
		<table class="container" cellpadding="0">
			<tr>
				<td colspan="3">
					<table class="container" cellpadding="0">
						<tr class="fieldline">
							<td class="labelTitreFiche">
								<fl:label field="ScrLabel" labelClassName="titreFiche"/>
							</td>
							<td class="fieldTitreFiche">
								<fl:input property="ScrLabel" mandatoryMsgCode="M6059"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr><td colspan="3" class="ligne_separation"/></tr>
		</table>
		<table class="autodisplay_table">
			<tr>
				<td class="column2">
					<table class="container" cellpadding="0">
					<fl:fieldEdit property="ScrSeqNum" readOnly="true"/>
					<fl:fieldEdit property="ScrLanguage"/>
					<fl:fieldEdit property="ScrHasNotes"/>
					</table>
				</td>
				<td class="separation"><div class="separation"></div></td>
				<td class="column2">
					<table class="container" cellpadding="0">
						<fl:fieldEdit property="ScrCategory"/>
						<fl:fieldEdit property="ScrJSPPage" mandatoryMsgCode="M6077"/>
						<fl:fieldEdit property="ScrAverageDuration"/>
					</table>
				</td>				
			</tr>
		</table>
		<table class="container" cellpadding="0">
			<tr class="ligne_separation"><td></td></tr>
			<tr>
				<td class="titrePartie"><fl:getMessage code="L2007" alt="Description"/></td>
			</tr>
			<tr>
				<td class="dataValue noPaddingLeft"><fl:input property="ScrDetails" nodiv="false"/></td>
			</tr>
			<tr class="ligne_separation"><td></td></tr>
			<tr class="ligne_separation_couleur"><td></td></tr>
			<tr class="ligne_separation"><td></td></tr>
		</table>
		<link href="<fl:webapp/>/css/smalltabs_css.jsp" rel="stylesheet" type="text/css">
		<fl:smallTabs name="ScriptTabs">
		<fl:sTab id="LISTEREP" title="<%= Utils.getMessage(session, \"L305F\", \"Evénement\") %>">
			<table class="container" cellpadding="0">
				<tr>
					<td class="column2">
						<table class="container" cellpadding="0">		
							<fl:fieldEdit property="ScrEventID"  comment="<%= commentaireEvt %>" mandatoryMsgCode="M6068" />
						</table>
					</td>
				</tr>	
				<tr class="ligne_separation"><td></td></tr>
				<tr>
					<td class="column2">
						<table class="container" cellpadding="0">																												
							<tr class="fieldline">
						  		<td class="dataLabel" id="ScrParStatus_label"><div><label title="Participation" for="ScrParStatus"><fl:getMessage code="L8186" alt="Participation"/></label></div></td>
								<td class="dataValue">
									<div>
										<select name="ScrParStatus" class="input select">
											<option value=""></option>
<%
										Iterator iter = listParticipationStatusIDAndDisplay.keySet().iterator();
										while (iter.hasNext()) {
											String statusID = (String) iter.next();
											String statusDisplay = (String) listParticipationStatusIDAndDisplay.get(statusID);
%> 
											<option value="<%= Utils.formatToWeb(statusID, true) %>" <%= statusID.equals(scrParStatus) ? "selected" : "" %>><%= Utils.formatToWeb(statusDisplay, true) %></option> 
<%
										}
%>										
										</select>
									</div>
								</td>
							</tr>									
						</table>
					</td>
					<td class="separation"><div class="separation"></div></td>
					<td class="column2">
						<table class="data_column" cellpadding="0">								
							<fl:fieldEdit property="ScrParStatusRule"/>	
						</table>			
					</td>
				</tr>
			</table>
		</fl:sTab>
		</fl:smallTabs>
		
</fl:bigTabs>
</fl:form>