<!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 trac.web.chrome import add_script

 typename = {1:"フリー入力(１行)", 2:"フリー入力(複数行)", 3:"単一選択(ラジオボタン)", 4:"単一選択(コンボボックス)",5:"日付",6:"式",7:"Template"}
 typedisplay = {0:"表示",1:"非表示"}

?>
  <head>
    <title>リスト構成の編集</title>
	<script type="text/javascript">
		function eventHandler(actionName) {
			f = document.forms['elementlist'];
			document.getElementById('actionName').value = actionName;
			if(actionName == "add"){
				f.action="${href.listmanage('editelementdetail')}";
			} else if(actionName == "edit"){
				f.action="${href.listmanage('editelementdetail')}";
			} else if(actionName == "delete"){
				if(!confirm('削除してもよろしいですか？')){
					return false;
				}
				f.action="${href.listmanage('editelement')}";
			} else if(actionName == "listmanage"){
				location.href="${href.listmanage()}";
				return;
			} else if(actionName == "savesort"){
				var listorder = getListOrder(document.getElementById('orgTable'));
				document.getElementById('listorder').value = listorder;
				f.action="${href.listmanage('editelement')}";
			} else if(actionName == "import"){
				if(document.getElementById('importfile').value==""){
					alert("ファイルが選択されていません。");
					return false;
				} else {
					if(!confirm('リスト構成をインポートします。よろしいですか？')){
						return false;
					}
				}
			}
			f.submit();
		}
	</script>
  </head>
  <body>
	<py:if test="error!=''">
		<div>
			<h2>Error:</h2>
			<p class="error">${error}</p>
		</div>
	</py:if>
	<py:if test="message!=''">
		<div>
			<h2>Result:</h2>
			<p class="message">${message}</p>
		</div>
	</py:if>
	<form name="elementlist" action="" method="post" enctype="multipart/form-data">
	<div>
		<B>タイトル：${title}</B><P/>
		<input type="button" name="add" value="追加"  onclick="javascript:eventHandler('add');" />
		<input type="button" name="edit" value="編集"  onclick="javascript:eventHandler('edit');" />
		<input type="button" name="delete" value="削除"  onclick="javascript:eventHandler('delete');" />
		<input type="button" name="listmanage" value="戻る"  onclick="javascript:eventHandler('listmanage');" />
		<input type="button" name="savesort" value="並べ替え保存"  onclick="javascript:eventHandler('savesort');" />
		<input type="button" name="export" value="エクスポート"  onclick="javascript:eventHandler('export');" />
		<input type="hidden" name="idx"/>
		<input type="hidden" id="listorder"  name="listorder"/>
		<input type="hidden" id="actionName"  name="actionName"/>
		<input type="hidden" name="list_id" value="${list_id}" />
		<br/>
		インポート(xml)：<input type="file" size="60" id="importfile" name="importfile"/><input type="button" name="import" value="インポート"  onclick="javascript:eventHandler('import');" />
	</div>
	<div  id="targetEl">
		<table class="list" id="orgTable">
			<thead>
				<tr>
				<!-- element_id, list_id, element_name, element_type, element_detail,default_value,column_no -->
					<th>No.</th>
					<th>削除</th>
					<th>要素ID</th>
					<th>名前</th>
					<th>タイプ</th>
					<th>明細</th>
					<th>デフォルト値</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"><input type="radio"  name="element_id"  value="${element['element_id']}" checked="${idx==0 or None}"/>${idx+1}</td>
						<td><input type="checkbox"  name="delete_id"  value="${element['element_id']}" /></td>
						<td>${element['element_id']}</td>
						<td>${element['element_name']}</td>
						<td>${typename[element['element_type']]}</td>
						<td><pre>${element['element_detail']}</pre></td>
						<td>${element['default_value']}</td>
						<td>${element['length']}</td>
						<td>${typedisplay[element['hidden']]}</td>
					</tr>
				</py:for>
			</tbody>
		</table>
	</div>
	</form>
<?python
add_script(req,'listmanage/js/DDTableRow.js')
add_script(req,'listmanage/js/DDSortTable.js')
?>
<script type="text/javascript">
(function(){
		var orgTable;
		var targetEl;
       window.ddsort = function(){
           if (!orgTable) orgTable = document.getElementById('orgTable');
           if (!targetEl) targetEl = document.getElementById('targetEl');
           var sortTable = new DDSortTable(orgTable,targetEl);
       }
}
)()
YAHOO.util.Event.onDOMReady(ddsort);
</script>
  </body>
</html>
