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

<script type="text/javascript">
	if (typeof jQuery == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
	}
</script>

<script type="text/javascript">
	$(function(){
		$("input[name='value']").focus();
		$('input').keydown(function(e){
			if (e.keyCode == 13) {
				$(this).parents('form').find('input.submit').click();
				return false;
			}
		});
	});
</script>

<% htmlviewfunctions.displaycommandresults({"deletedevice", "editdevice", "editdeviceparams", "overridedeviceparams"}, session) %>

<%
local id = cfe({type="hidden", value="device.mac"})
local comparison = cfe({type="hidden", value="~*"})
local value = cfe({label="MAC Address"})
local form = cfe({type="form", label="Search by MAC Address", value={id=id, comparison=comparison, value=value}, action="searchdevices", option="Search"})

if session.searchdevicesresult then
	local data = session.searchdevicesresult
	session.searchdevicesresult = nil

	if data.value and data.value.result then
		form.value.result = data.value.result
	end
end

local func = haserl.loadfile(page_info.viewfile:gsub("searchbymac", "searchdevices"))
func(form, viewlibrary, page_info, session)
%>
