<!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_stylesheet,add_script
 statusname = {0:"非公開", 1:"公開/受付中", 2:"終了"}
?>
  <head>
    <title>リスト管理</title>
  </head>

  <body>

  	<py:if test="error!=''">
	<div>
		<h2>Error:</h2>
		<div class="error">${error}</div>
	</div>
	</py:if>
	<form name="listmanage"  method="post"  enctype="multipart/form-data">
	<py:if test="req.perm.has_permission('LIST_MANAGE_EDIT')">
	<div>
		<input type="button" name="add" value="タイトル追加"  onclick="eventHandler('add');" />
		<input type="button" name="update" value="タイトル編集"  onclick="eventHandler('update');" />
		<input type="button" name="edit" value="リスト構成編集"  onclick="eventHandler('editelement');" />
		<input type="button" name="delete" value="削除"  onclick="eventHandler('delete');" />
		<input type="button" name="publish" id="publish" value="公開"  onclick="eventHandler('publish');" />
		<input type="hidden" id="idx"  name="idx"/><br/>
		インポート(csv)：<input type="file" size="60" id="importfile" name="importfile"/><input type="button" name="import" value="インポート"  onclick="javascript:eventHandler('import');" />
	</div>
	</py:if>
	<input type="hidden" id="list_id"  name="list_id"/>
	<input type="hidden" id="actionName"  name="actionName"/>
	<input type="hidden" id="comment"  name="comment"/>
	<div>
		<table class="list">
				<tr>
					<th widht="40">No.</th>
					<th>タイトル</th>
					<th>説明</th>
					<th width="70">更新日時</th>
					<th>行数</th>
					<th width="80">ステータス</th>
					<th width="70">リリース日</th>
					<th width="80">Wiki:Version</th>
				</tr>
				<py:for each="idx, list in enumerate(list_title)">
<?python
mod = idx % 2
style = ''
if mod==0:
	style = 'even'
else:
	style = 'odd'
?>
					<tr class="${style}">
						<td>
						<py:if test="req.perm.has_permission('LIST_MANAGE_EDIT')">
						<input type="radio"  name="id" id="id" value="${list['list_id']}"  checked="${idx==0 or None}"/>
						</py:if>
						${idx+1}
						</td>
						<td nowrap="nowrap"><a href="javascript:eventHandler('edit','${list['list_id']}')">${list['title']}</a></td>
						<td nowrap="nowrap">${list['description']}</td>
						<td nowrap="nowrap">${list['update_date']}</td>
						<td nowrap="nowrap" align="right">${list['cnt']}</td>
						<td nowrap="nowrap">${list['status']}</td>
						<td nowrap="nowrap">${list['release_date']}</td>
						<td nowrap="nowrap"><a href="${href.wiki(list['wiki_name'])}">${list['wiki_name']}:${list['wiki_version']}</a></td>
					</tr>
				</py:for>
		</table>
	</div>

	<p/>
	</form>

<script type="text/javascript">
function eventHandler(actionName,id) {
	var f = document.forms['listmanage'];
	if(id == undefined){
		document.getElementById('list_id').value = getRadioButtonValue(f.id);
	} else {
		document.getElementById('list_id').value = id;
	}

	document.getElementById('actionName').value = actionName;
	if(actionName == "add" || actionName == "update"){
		f.action = "${href.listmanage('edittitle')}";
	} else if(actionName == 'editelement'){
		f.action = "${href.listmanage('editelement')}";
	} else if(actionName == 'edit'){
		f.action = "${href.listmanage('edit')}";
	} else if(actionName == 'delete'){
		if(!confirm('削除してもよろしいですか？')){
			return false;
		}
		f.action = "${href.listmanage()}";
	} else if(actionName == 'publish' ){
		f.action = "${href.listmanage('edit')}";
		showDialog();
		return false;
	}
	f.submit();
}
</script>

<?python
add_script(req,'listmanage/js/container.js')
add_script(req,'listmanage/js/util.js')
?>

<script>
var commentdialog = null;
function init() {

	// Define various event handlers for Dialog
	var handleSubmit = function() {
		document.getElementById("comment").value = document.getElementById("wikicomment").value;
		commentdialog.hide();
		var f = document.forms['listmanage'];
		f.submit();
	};
	var handleCancel = function() {
		this.cancel();
	};


	commentdialog = new YAHOO.widget.Dialog("dialog1",
							{ fixedcenter: true,
							  visible : false,
							  draggable: true,
							  constraintoviewport : false,
							  close: false,
							  width : "400px",
							  underlay:"none",
							  buttons : [ { text:"OK", handler:handleSubmit, isDefault:true },
								      { text:"キャンセル", handler:handleCancel } ]
							});

	// Render the Dialog
	commentdialog.render();

}

function showDialog(){
	document.getElementById("comment").value = "";
	document.getElementById("dialogpanel").style.display = "block";
	commentdialog.show();
}

YAHOO.util.Event.onDOMReady(init);

</script>
<div class="yui-skin-sam" id="dialogpanel" style="position:absolute;display:none">
<center>
<div id="dialog1">
<div class="hd" style="text-align:left">コメントを入力して下さい。</div>
<div class="bd">
<textarea name="wikicomment" id="wikicomment" cols="44" rows="6"></textarea>
</div>
</div>
</center>
</div>

  </body>
</html>
