#if($form_action=="new")
#set($isNewAction=true)
#set ($list_names = ["-"])
#foreach ($l in $sorter.sort($packagelists.fetchAll(),"name"))
#set($dummy=$list_names.add($l.name))
#end
#else
#set($isNewAction=false)
#end
<div id="dialog-form-${form_action}" title="${form_title}">
	<p class="validateTips">All form fields are required.</p>
	<form id="form-${form_action}" method="post" accept-charset="iso-8859-2" action="$root/$module/${form_action}-action.vm">
	<fieldset>
		<input type="hidden" name="key" id="key"/>
#if($params.profile)
		<input type="hidden" name="profile" id="profile" value="$params.profile"/>
#end
		#inputbox("name","Name",$isNewAction)
		#inputbox("description","Beschreibung",true)
		<br>
		#checkbox("autoUpdate","Automatische Aktualisierung",false)
		<br>
		#checkbox("approvalRequired","Freigabe erforderlich",false)
		<br>
		#checkbox("atomic","Nur Komplett-Update",false)
		<br>
		<label for="origin">Vorgänger</label>
		#dropdown( "origin", $list_names,"") 
		<br>
		#inputbox("priority","Priorität",true)
		<br>
		#checkbox("approved","Freigegeben",false)
		<br>
#if(!$isNewAction)
		<div id="container">
		<div class="leftcol">
		<label for="members">Repositories:</label>
		<select class="selectboxleft" name="members" id="members" size="10">
			<option>dummy</option>
		</select>
		</div>
		<div class="centercol">
		<img id="addmember" class="ui-icon ui-icon-circle-arrow-w"/>
		<img id="removemember" class="ui-icon ui-icon-circle-arrow-e"/>
		</div>
		<div class="rightcol">
		<select class="selectboxright" name="nonmembers" id="nonmembers" size="10">
		<option>dummy</option>
		</select>
		</div>
		</div>
		<br>
#end
	</fieldset>
	</form>
</div>
<script type="text/javascript">
#if($isNewAction)
function form_${form_action}_load(o) {
				$("input#name").val('');
				$("input#description").val('');
				$("input#autoUpdate").prop('checked',false);
				$("input#priority").val(0);
				$("input#approvalRequired").prop('checked',false);
				$("input#atomic").prop('checked',false);
				$("input#approved").prop('checked',false);
				$("select#origin").val("");
}
#else
#[[
function form_update_selects(o) {
	var el = $("select#members");
	el.empty(); // remove old options
	$.each(o.repositories, function(key,value) {
		el.append($("<option></option>")
		.attr("value", value).text(value));
	});

	el=$('select#nonmembers');
	el.empty();
]]#
	var l=[ #foreach($p in $sorter.sort($repositories.fetchAll(),"name"))"$p.name",#end ];
#[[
	$.each(l,function(key,value) {
		if($.inArray(value,o.repositories)!=-1) {
			el.append($('<option disabled></option>')
			.attr("value", value).text(value));
		} else {
			el.append($('<option></option>')
			.attr("value", value).text(value));
		}
	});
}
]]#
function form_${form_action}_load(o) {
				$('#addmember').unbind('click');
				$('#addmember').click(function() {
					var m=$('#nonmembers').val();
					o.repositories.push(m);
					form_update_selects(o);
					$('#nonmembers').val([]);
					$.post('$root/$module/addrepo-action.vm?key='+o.name+'&repo='+m)
						.error(post_error_handler);	
				});
				$('#removemember').unbind('click');
				$('#removemember').click(function() {
					var m=$('#members').val();
					o.repositories.splice($.inArray(m,o.repositories),1);
					form_update_selects(o);
					$('#members').val([]);
					$.post('$root/$module/delrepo-action.vm?key='+o.name+'&repo='+m)
						.error(post_error_handler);	
				});
				$("input#key").val(o.name);
				$("input#name").val(o.name);
				$("input#description").val(o.description);
				$("input#autoUpdate").prop('checked',o.autoUpdate);
				$("input#priority").val(o.priority);
				$("input#approvalRequired").prop('checked',o.approvalRequired);
				$("input#atomic").prop('checked',o.atomic);
				$("input#approved").prop('checked',o.approved);
				if(o.origin!="") {
					$("select#origin").val(o.origin);
				}
				else {
					$("select#origin").val("-");
				}
				form_update_selects(o);
}
#end
function form_${form_action}_validate() {
	var valid;
        var name = $("input#name").filter(":visible");
        var priority = $("input#priority").filter(":visible");

	valid = checkIdentifier(name);
	valid = checkInteger(priority) && valid;
        return valid;
}
</script>
