summaryrefslogtreecommitdiffstats
path: root/provisioning-listrequests-html.lsp
blob: a53e24f965ec821474efba1ff6b8069c336839e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<% local view, 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">
	if (typeof $.tablesorter == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"><\/script>');
	}
</script>

<script type="text/javascript">
<% -- Since we're including a submission of searchdevices, we need to overcome the automatic redirect
	if session.searchdevicesresult then
		-- Use JavaScript to redirect to the searchdevices page
%>
		window.location.assign("<%= html.html_escape(page_info.script..page_info.prefix..page_info.controller) %>/searchdevices");
<%
	end
	
	-- Since we're including a submission of createdevicefromrequest, we need to overcome the automatic redirect
	if session.createdevicefromrequestresult and not session.createdevicefromrequestresult.errtxt then
		local tmp = session.createdevicefromrequestresult
		session.createdevicefromrequestresult = nil
		-- Use JavaScript to redirect to the edit page
%>
		window.location.assign("<%= html.html_escape(page_info.script..page_info.prefix..page_info.controller) %>/<% if viewlibrary.check_permission("editdevice") then io.write("editdevice") elseif viewlibrary.check_permission("overridedeviceparams") then io.write("overridedeviceparams") else io.write("editdeviceparams") end %>?device_id=<%= tmp.value.device_id.value %>&redir=<%= html.html_escape(page_info.orig_action) %>");
<%
	elseif session.createdevicefromrequestresult then
		-- Use JavaScript to redirect to the createdevicefromrequest page
%>
		window.location.assign("<%= html.html_escape(page_info.script..page_info.prefix..page_info.controller) %>/createdevicefromrequest");
<%
	end
%>

        $(document).ready(function() {
		$("#list").tablesorter({headers: {1:{sorter:'digit'}, 3:{sorter:'ipAddress'}}, widgets: ['zebra']});
		$(".deleterequest").click(function(){ return confirm("Are you sure you want to delete this request?")});
        });
</script>

<% htmlviewfunctions.displaycommandresults({"deleterequest", "editdevice"}, session) %>

<h1>Requests</h1>
<table id="list" class="tablesorter"><thead>
	<tr>
		<th>Action</th>
		<th>Timestamp</th>
		<th>MAC Address</th>
		<th>IP Address</th>
		<th>User Agent</th>
	</tr>		
</thead><tbody>
<% for k,v in ipairs( view.value ) do %>
	<tr>
		<td>
		<% if viewlibrary.check_permission("deleterequest") then %>
			<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/deleterequest?submit=true&mac="..v.mac, label="Delete ", class="deleterequest"} %>
		<% end %>
		<% if v.device_id then %>
			<% if viewlibrary.check_permission("searchdevices") then %>
				<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/searchdevices?submit=true&id=device_id&value="..v.device_id.."&redir=searchdevices", label="Search "} %>
			<% end %>
		<% else %>
			<% if viewlibrary.check_permission("createdevicefromrequest") then %>
				<%= html.link{value=page_info.script..page_info.prefix..page_info.controller.."/createdevicefromrequest?submit=true&mac="..v.mac, label="Create "} %>
			<% end %>
		<% end %>
		</td>
		<td>
		<span style="display:none">
		<% local date = {}
		date.year, date.month, date.day, date.hour, date.min, date.sec, remainder = string.match(v.date, "(%d+)%-(%d+)%-(%d+) (%d+):(%d+):(%d+)")
		local rem = string.match(v.date, "%.%d+$")
		io.write((os.time(date) - 1318000000)..(rem or "")) %>
		</span>
		<%= html.html_escape(v.date) %>
		</td>
		<td><%= html.html_escape(v.mac) %></td>
		<td><%= html.html_escape(v.ip) %></td>
		<td><%= html.html_escape(v.agent) %></td>
	</tr>
<% end %>
</tbody>
</table>