summaryrefslogtreecommitdiffstats
path: root/provisioning-listdevices-html.lsp
blob: c511d1e88375e06a943c9e2e5e4a4de8942923ec (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
97
98
99
100
101
102
103
104
105
<% 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 createdevice as a component, we break the automatic redirect
	if session.createdeviceresult and not session.createdeviceresult.errtxt then
		local tmp = session.createdeviceresult
		session.createdeviceresult = 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("overridedeviceparams") then io.write("overridedeviceparams") elseif viewlibrary.check_permission("editdeviceparams") then io.write("editdeviceparams") else io.write("editdevice") end %>?device_id=<%= tmp.value.device_id.value %>&redir=<%= html.html_escape(page_info.orig_action) %>");
<%
	end
%>

        $(document).ready(function() {
                $("#list").tablesorter({headers: {0:{sorter: false}}, widgets: ['zebra']});
		$(".deletedevice").click(function(){ return confirm("Are you sure you want to delete this device?")});
        });
</script>

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

<% -- Determine all of the groups
local tmp = {}
for k,v in ipairs( view.value ) do
	for g,c in pairs(v) do
		if not tmp[g] then tmp[g] = true end
	end
end
local display = {}
for n in pairs(tmp) do
	if n ~= "device_id" then
		display[#display+1] = n
	end
end
table.sort(display)
%>

<% local header_level = htmlviewfunctions.displaysectionstart(view, page_info) %>
<table id="list" class="tablesorter"><thead>
	<tr>
		<th>Action</th>
		<th>Device ID</th>
	<% for i,n in ipairs(display) do %>
		<th><%= string.gsub(n, "^.", string.upper) %>
	<% end %>
	</tr>		
</thead><tbody>
<% local device_id = cfe({ type="hidden", value="" }) %>
<% local redir = cfe({ type="hidden", value=page_info.orig_action }) %>
<% for k,v in ipairs( view.value ) do %>
	<tr>
		<td>
		<% device_id.value = v.device_id %>
		<% if viewlibrary.check_permission("editdevice") then %>
			<% htmlviewfunctions.displayitem(cfe({type="link", value={device_id=device_id, redir=redir}, label="", option="Edit", action="editdevice"}), page_info, -1) %>
		<% end %>
		<% if viewlibrary.check_permission("overridedeviceparams") then %>
			<% htmlviewfunctions.displayitem(cfe({type="link", value={device_id=device_id, redir=redir}, label="", option="Params", action="overridedeviceparams"}), page_info, -1) %>
		<% elseif viewlibrary.check_permission("editdeviceparams") then %>
			<% htmlviewfunctions.displayitem(cfe({type="link", value={device_id=device_id, redir=redir}, label="", option="Params", action="editdeviceparams"}), page_info, -1) %>
		<% end %>
		<% if viewlibrary.check_permission("getdevicevalues") then %>
			<% htmlviewfunctions.displayitem(cfe({type="form", value={value=device_id, id=cfe({type="hidden", value="device_id"}), viewtype=cfe({type="hidden", value="templated"})}, label="", option="View", action="getdevicevalues"}), page_info, -1) %>
		<% end %>
		<% if viewlibrary.check_permission("deletedevice") then %>
			<% htmlviewfunctions.displayitem(cfe({type="form", value={device_id=device_id}, label="", option="Delete", action="deletedevice", class="deletedevice"}), page_info, -1) %>
		<% end %>
		</td>
		<td><%= html.html_escape(v.device_id) %></td>
	<% for i,n in ipairs(display) do %>
		<td><%= html.html_escape(v[n]) %></td>
	<% end %>
	</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 devices found</p>
<% end %>
<% htmlviewfunctions.displaysectionend(header_level) %>

<% if page_info.action == "listdevices" and viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("createdevice") then
        viewlibrary.dispatch_component("createdevice")
end %>