<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="layout.html" />
  <xi:include href="macros.html" />
<?python
from listmanage.listedit import *
?>
<?python
#getComp
# idx:テーブル表示行のインデックス
# row_id:行ID(list_rowのID)
# e_id:要素ID
# type:コンポーネントタイプ
# length:項目長
# detaillist:明細(値)一覧
# v_map:値のマッピング(行単位)
# default_value:デフォルト値
# num:項目数
?>
<py:def function="getComp(idx,row_id,e_id,type,length,detaillist,v_map,default_value,num)">
<?python

	linefeed = False
	if len("".join(detaillist)) > 40:
		linefeed =True
?>
	<py:choose>
	  <py:when test="int(type) == 1">
	  	<input type="text" size="${length}" maxlength="${length}" name="value${idx}" value="${getValue(e_id,v_map,default_value,num)}"/>
	  </py:when>
	  <py:when test="int(type) == 2">
	  	<textarea name="value${idx}" cols="80" rows="4" >${getValue(e_id,v_map,default_value,num)}</textarea>
	  </py:when>
	  <py:when test="int(type) == 3">
	  	<py:for each="detail in detaillist">
	  		<input type="radio" name="value${idx}" value="${detail}" checked="${isSelected(row_id,type,e_id,v_map,detail,default_value,num)}" />${detail}
	  		<py:if test="linefeed">
		  		<br/>
	  		</py:if>
	  	</py:for>
	  </py:when>
	  <py:when test="int(type) == 4">
	  	<select name="value${idx}">
	  	<py:for each="detail in detaillist">
	  		<option value="${detail}" selected="${isSelected(row_id,type,e_id,v_map,detail,default_value,num)}" >${detail}</option>
	  	</py:for>
	  	</select>
	  </py:when>
	  <py:when test="int(type) == 5">
	  	<table><tr><td><div class="date_text" id="datediv_${idx}">${getValue(e_id,v_map,default_value,num)}</div>
	  	<div id="datediv_${idx}_container"></div><input type="hidden" id="datetext_${idx}" name="value${idx}"  value="${getValue(e_id,v_map,default_value,num)}"/></td>
	  	<td><input type="button" name="clear" value="クリア"  onclick="clearCalendar('datediv_${idx}','datetext_${idx}');" /></td></tr></table>
	  </py:when>
	  </py:choose>
</py:def>

  <head>
    <title>明細データ</title>
	<script type="text/javascript">
		function eventHandler(actionName) {
			f = document.forms['detaillist'];
			document.getElementById('actionName').value = actionName;
			if(actionName == "update"){
				if(!confirm('登録します。よろしいですか？')){
					return false;
				}
				f.action="${href.listmanage('editdetail')}";
			} else if(actionName == "cancel"){
				f.action = "${href.listmanage('edit')}";
			}
			f.submit();
		}

		function clearCalendar(div_id,text_id){
			var txtDate1 = document.getElementById(text_id);
			var txtDate2 = document.getElementById(div_id);
			txtDate1.value = "";
			if (typeof txtDate2.textContent != "undefined") {
				txtDate2.textContent = "";
			} else {
				txtDate2.innerText = "";
			}
		}
	</script>
  </head>
  <body>
	<form name="detaillist" action="" method="post">
	<div>
		<B>タイトル：${title}</B><P/>
		<input type="hidden" id="actionName"  name="actionName"/>
	</div>
	<div>
		<div id="cal1Container" style="position:absolute"></div>
		<table width="90%"  class="list">
			<thead>
				<tr>
					<th>No.</th>
					<th>名称</th>
					<th>値</th>
				</tr>
			</thead>
			<tbody>
				<py:for each="idx, element in enumerate(element_list)">
<?python
mod = idx % 2
style = ''
if mod==0:
	style = 'even'
else:
	style = 'odd'
?>
					<tr class="${style}">
						<td width="40">${idx+1}</td>
						<td>${element['element_name']}</td>
						<td>${getComp(idx,value['row_id'],element['element_id'],element['element_type'],element['length'],element['element_detail'].splitlines(),value,element['default_value'],num_element)}</td>
						<input type="hidden" name="element_id${'%d'%(idx)}" value="${element['element_id']}" />
						<input type="hidden" name="value_id${'%d'%(idx)}" value="${value['value_id%d'%(idx)]}" />
					</tr>
				</py:for>
			</tbody>
		</table>
		<input type="hidden" name="list_id" value="${list_id}" />
		<input type="hidden" name="id" value="${list_id}" />
		<input type="hidden" name="row_id" value="${value['row_id']}" />
        <input type="hidden" name="num_element" value="${num_element}" />
		<input type="hidden" name="update_date" value="${value['update_date']}" />
		<input type="button" name="send" value="登録"  onclick="eventHandler('update');" />
		<input type="button" name="cancel" value="キャンセル"  onclick="eventHandler('cancel');" />

	</div>
	</form>
  </body>
<script type="text/javascript">
window.onload = function(){
	<py:for each="idx, element in enumerate(element_list)">
		<py:choose>
			<py:when test="int(element['element_type']) == 5">
			addCalendar('datediv_${idx}','datetext_${idx}');
			</py:when>
		</py:choose>
	</py:for>
}
</script>
</html>
