<!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
?>
  <head>
    <title>リストの編集</title>
	<script type="text/javascript">
		function eventHandler(actionName) {
			f = document.forms['list'];
			document.getElementById('actionName').value = actionName;
			if(actionName == "add"){
				f.action="${href.listmanage('editdetail')}";
			} else if(actionName == "edit"){
				f.action="${href.listmanage('editdetail')}";
			} else if(actionName == "delete"){
				if(!validateCheckBox('delete_id')){
					alert('削除する行を選択してください。');
					return false;
				}
				if(!confirm('削除してもよろしいですか？')){
					return false;
				}
				f.action="${href.listmanage('edit')}";
			} 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('edit')}";
			}
			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="list" action="" method="post">
	<div>
		<B>タイトル：${title}<input type="hidden" id="title"  name="title" value="${title}"/></B><P/>
		<py:if test="req.perm.has_permission('LIST_MANAGE_EDIT')">
		<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="savesort" value="並べ替え保存"  onclick="javascript:eventHandler('savesort');" />
		</py:if>
		<input type="button" name="excel" value="Excel出力"  onclick="javascript:eventHandler('excel');" />
		<input type="button" name="listmanage" value="戻る"  onclick="javascript:eventHandler('listmanage');" />
		<input type="hidden" name="idx"/>
		<input type="hidden" id="actionName"  name="actionName"/>
		<input type="hidden" id="listorder"  name="listorder"/>
		<input type="hidden" name="list_id" value="${list_id}" />
		<input type="hidden" name="id" value="${list_id}" />
	</div>
	<div id="targetEl">
		<table class="list" id="orgTable">
			<thead>
				<tr>
				<!-- value_id, list_id, element_id, value, parent_value_id,row_no,update_user,update_date -->
					<py:if test="req.perm.has_permission('LIST_MANAGE_EDIT')">
					<th>No.</th>
					<th>削除 <input type="checkbox" name="delete_all" onclick="javascript:checkAll('delete_id',this.checked);" /></th>
					</py:if>
					<py:for each="idx, element in enumerate(element_list)">
						<py:if test="element_list[idx]['hidden']!=1">
							<th>${element['element_name']}</th>
						</py:if>
					</py:for>
					<th>更新者</th>
					<th>更新日時</th>
				</tr>
			</thead>
			<tbody>
				<py:for each="idx2, v in enumerate(value_list)">
<?python
mod = idx2 % 2
style = ''
if mod==0:
	style = 'even'
else:
	style = 'odd'
?>
					<tr class="${style}">
						<py:if test="req.perm.has_permission('LIST_MANAGE_EDIT')">
						<td><input type="radio"  name="row_id"  value="${v['row_id']}" checked="${idx2==0 or None}"/>${idx2+1}</td>
						<td><input type="checkbox"  name="delete_id"  value="${v['row_id']}" /></td>
						</py:if>
						<py:for each="idx3 in range(len(element_list))">
							<py:if test="element_list[idx3]['element_type']==7 and element_list[idx3]['hidden']!=1">
								<td>${wiki_to_html(context, v['value%d'%(idx3)])}</td>
							</py:if>
							<py:if test="element_list[idx3]['element_type']!=7 and element_list[idx3]['hidden']!=1">
								<td>${v['value%d'%(idx3)]}</td>
							</py:if>
						</py:for>
						<td>${v['update_user']}</td>
						<td>${v['update_date']}</td>
					</tr>
				</py:for>
			</tbody>
		</table>
	</div>
	<p/>
	</form>
<?python
add_script(req,'listmanage/js/DDTableRow.js')
add_script(req,'listmanage/js/DDSortTable.js')
?>
<py:if test="req.perm.has_permission('LIST_MANAGE_EDIT')">
<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>
</py:if>
  </body>
</html>
