<% local view, viewlibrary, page_info, session = ... 
require("htmlviewfunctions")
html = require("acf.html")
%>

<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"></script>
<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"></script>
<script type="text/javascript">
        $(document).ready(function() {
                $("#list").tablesorter({headers: {0:{sorter: false}}});
		$(".deleteparam").click(function(){ return confirm("Are you sure you want to delete this parameter?")});
        });
</script>

<% htmlviewfunctions.displaycommandresults({"deleteparam", "editparam"}, session) %>
<% htmlviewfunctions.displaycommandresults({"createparam"}, session, true) %>

<h1>Parameters</h1>
<DL>
<TABLE id="list" class="tablesorter"><THEAD>
	<TR style="background:#eee;font-weight:bold;">
		<TH>Action</TH>
		<TH>Name</TH>
		<TH>Label</TH>
		<TH>Default</TH>
		<TH>Sequence</TH>
	</TR>		
</THEAD><TBODY>
<% for k,v in ipairs( view.value ) do %>
	<TR>
		<TD>
		<% if viewlibrary.check_permission("deleteparam") then %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deleteparam?submit=true&param_id="..v.param_id, label="Delete ", class="deleteparam"} %>
		<% end %>
		<% if viewlibrary.check_permission("editparam") then %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/editparam?param_id="..v.param_id.."&redir="..page_info.orig_action, label="Edit "} %>
		<% end %>
		</TD>
                <TD><%= html.html_escape(v.name) %></TD>
                <TD><%= html.html_escape(v.label) %></TD>
                <TD><%= html.html_escape(v.value) %></TD>
                <TD><%= html.html_escape(v.seq) %></TD>
	</TR>
<% end %>
</TBODY>
</TABLE>

<% if view.errtxt then %>
<p class="error"><%= html.html_escape(view.errtxt) %></p>
<% end %>
<% if #view.value == 0 then %>
<p>No parameters found</p>
<% end %>

<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createparam") then
        viewlibrary.dispatch_component("createparam")
end %>
</DL>
