summaryrefslogtreecommitdiffstats
path: root/provisioning-listrequests-html.lsp
blob: 2bb93388a53238913d5a750e4604072e896d02ed (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
93
94
95
96
<% 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) %>

<% local header_level = htmlviewfunctions.displaysectionstart(cfe({label="Requests"}), page_info) %>
<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>
<% local mac = cfe({ type="hidden", value="" }) %>
<% local redir = cfe({ type="hidden", value="searchdevices" }) %>
<% for k,v in ipairs( view.value ) do %>
	<tr>
		<td>
		<% mac.value = v.mac %>
		<% if viewlibrary.check_permission("deleterequest") then %>
			<% htmlviewfunctions.displayitem(cfe({type="form", value={mac=mac}, label="", option="Delete", action="deleterequest", class="deleterequest" }), page_info, -1) %>
		<% end %>
		<% if v.device_id then %>
			<% if viewlibrary.check_permission("searchdevices") then %>
				<% htmlviewfunctions.displayitem(cfe({type="form", value={id=cfe({type="hidden", value="device_id"}), value=cfe({type="hidden", value=v.device_id}), redir=redir}, label="", option="Search", action="searchdevices" }), page_info, -1) %>
			<% end %>
		<% else %>
			<% if viewlibrary.check_permission("createdevicefromrequest") then %>
				<% htmlviewfunctions.displayitem(cfe({type="form", value={mac=mac}, label="", option="Create", action="createdevicefromrequest" }), page_info, -1) %>
			<% end %>
		<% end %>
		</td>
		<td>
		<span class="hide">
		<% 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>
<% htmlviewfunctions.displaysectionend(header_level) %>