vmail-listmessages-html.lsp 11.6 KB
Newer Older
1
<% local view, viewlibrary, page_info, session = ... 
2
htmlviewfunctions = require("htmlviewfunctions")
3
html = require("acf.html")
4 5 6
%>

<% -- Pregenerate the list of users
7
local useroptions = {{value="", label=""}}
8 9
if viewlibrary.check_permission("listusers") and (viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage")) then
	local users = viewlibrary.dispatch_component("listusers", nil, true)
10 11 12 13 14
	for i,v in ipairs(users.value) do
		v.firstname = v.firstname or ""
		v.lastname = v.lastname or ""
		v.username = v.username or ""
	end
15
	table.sort(users.value, function(a,b) if a.firstname ~= b.firstname then return a.firstname < b.firstname elseif a.lastname ~= b.lastname then return a.lastname < b.lastname else return a.username < b.username end end)
16 17
	for i,u in ipairs(users.value) do
		if u.username ~= session.userinfo.userid then
18
			useroptions[#useroptions+1] = {value=u.firstname, label=u.firstname..' '..u.lastname..' ('..u.username..')'}
19 20
		end
	end
21 22 23
end
%>
<% -- Pregenerate the list of folders
24 25 26
local reversefolders = {}
local folderoptions = {{value="", label=""}}
local dontmove=false
27 28 29 30 31 32 33 34 35 36
if viewlibrary.check_permission("listfolders") then
	local folders = viewlibrary.dispatch_component("listfolders", nil, true)
	for i,u in ipairs(folders.value) do
		reversefolders[u.in_folder] = u.label
	end
	if (viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage")) then
		if #folders.value <= 1 then
			dontmove = true
		end
		for i,u in ipairs(folders.value) do
37
			folderoptions[#folderoptions+1] = {value=u.in_folder, label=u.label}
38 39
		end
	end
40 41
end
%>
42
<% -- Figure out the callback number
43
local callmenumber = nil
44 45 46 47 48 49 50
if viewlibrary.check_permission("editmyusersettings") and viewlibrary.check_permission("callbackmymessage") then
	local settings = viewlibrary.dispatch_component("editmyusersettings", nil, true)
	if settings and settings.value and settings.value.callmenumber then
		callmenumber = settings.value.callmenumber.value
	end
end
%>
51

52 53 54 55 56 57 58 59 60 61 62 63
<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>

64
<script type="text/javascript">
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
	<% -- Browser detect script from http://www.quirksmode.org/js/detect.html %>
	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.userAgent,
				subString: "iPhone",
				identity: "iPhone/iPod"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	};
	BrowserDetect.init();

182 183
	function PlayMessage() {
		$(".temporaryplayer").remove();
184
		if ( BrowserDetect.browser == "Safari" ) {
185
			$(this).parent().parent().after("<tr class='temporaryplayer'><td colspan='9'><object type='audio/x-wav' data='" + $(this).attr("href") + "' width='100%' height='25'><param name='src' value='" + $(this).attr("href") + "'> <param name='autoplay' value='true'> <param name='autoStart' value='1'> </object></td></tr>");
186
		} else {
187
			$(this).parent().parent().after("<tr class='temporaryplayer'><td colspan='9'><embed width='100%' height='25px' autostart='1' playcount='1' src='" + $(this).attr("href") + "' type='application/x-mplayer2'></embed></td></tr>");
188
		};
189 190 191 192 193 194 195 196 197 198
		return false;
	}
	function HandleMulti() {
		var messages = [];
		$(".multicheck:checked").each(function(){
			messages[messages.length] = this.value;
		});
		$(this).parent().find("[name='message']").attr("value", messages.join(","));
	}
        $(document).ready(function() {
Ted Trask's avatar
Ted Trask committed
199
                $("#list").tablesorter({headers: {0:{sorter: false}, 1:{sorter: false}}, widgets: ['zebra']});
200 201 202 203 204
		$("#list").bind("sortStart",function() {
			$(".temporaryplayer").remove();
		});
		$(".playmessage").click(PlayMessage);
<% if viewlibrary.check_permission("deletemessage") or viewlibrary.check_permission("deletemymessage") then %>
205
		$(".multidelete").click(HandleMulti);
206 207
<% end %>
<% if viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage") then %>
208
		$(".multiforward").click(HandleMulti);
209 210
<% end %>
<% if viewlibrary.check_permission("emailmessage") or viewlibrary.check_permission("emailmymessage") then %>
211
		$(".multiemail").click(HandleMulti);
212 213
<% end %>
<% if viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage") then %>
214
		$(".multimove").click(HandleMulti);
215 216 217 218
<% end %>
        });
</script>

219
<% htmlviewfunctions.displaycommandresults({"deletemessage", "deletemymessage", "forwardmessage", "forwardmymessage", "emailmessage", "emailmymessage", "movemessage", "movemymessage", "callbackmessage", "callbackmymessage"}, session) %>
220

221
<% local header_level = htmlviewfunctions.displaysectionstart(view, page_info) %>
222
<table><tr><td>
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
<% local message = cfe({type="hidden"}) %>
<% if viewlibrary.check_permission("deletemessage") or viewlibrary.check_permission("deletemymessage") then
	local form = cfe({type="form", value={message=message}, label="", option="Delete", action="deletemymessage", class="multidelete" })
	if viewlibrary.check_permission("deletemessage") then form.action = "deletemessage" end
	htmlviewfunctions.displayitem(form, page_info, -1)
end
if viewlibrary.check_permission("forwardmessage") or viewlibrary.check_permission("forwardmymessage") then
	local form = cfe({type="form", value={message=message}, label="", option="Forward", action="forwardmymessage", class="multiforward" })
	if viewlibrary.check_permission("forwardmessage") then form.action = "forwardmessage" end
	form.value.newuser = cfe({type="select", option=useroptions})
	htmlviewfunctions.displayitem(form, page_info, -1)
end
if viewlibrary.check_permission("emailmessage") or viewlibrary.check_permission("emailmymessage") then
	local form = cfe({type="form", value={message=message}, label="", option="E-mail", action="emailmymessage", class="multiemail" })
	if viewlibrary.check_permission("emailmessage") then form.action = "emailmessage" end
	form.value.address = cfe({})
	htmlviewfunctions.displayitem(form, page_info, -1)
end
if viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage") then
	if not dontmove then
		local form = cfe({type="form", value={message=message}, label="", option="Move", action="movemymessage", class="multimove" })
		if viewlibrary.check_permission("movemessage") then form.action = "movemessage" end
		form.value.newfolder = cfe({type="select", option=folderoptions})
		htmlviewfunctions.displayitem(form, page_info, -1)
	end
end %>
249
</td></tr></table>
250 251 252 253 254
<table><tr><td>
<small>select: </small>
<small><a href='' OnClick='$(".multicheck").attr("checked", "true"); return false;'>all</a></small>
<small><a href='' OnClick='$(".multicheck").removeAttr("checked"); return false;'>none</a></small>
</td></tr></table>
255

256 257 258 259 260 261 262 263 264 265 266 267 268
<table id="list" class="tablesorter"><thead>
	<tr>
		<th></th>
		<th>Action</th>
		<th>Date</th>
		<th>Time</th>
		<th>Caller ID</th>
		<th>Priority</th>
		<th>Orig Mailbox</th>
		<th>Folder</th>
		<th>Duration</th>
	</tr>		
</thead><tbody>
269 270 271
<% local message = cfe({ type="hidden" }) %>
<% local viewtype = cfe({ type="hidden", value="stream" }) %>
<% local extension = cfe({ type="hidden", value=callmenumber }) %>
272
<% for k,v in ipairs( view.value ) do %>
273 274 275
	<tr>
		<td><input type=checkbox class="multicheck" value="<%= html.html_escape(v.uuid) %>"></td>
		<td>
276
		<% message.value = v.uuid %>
277
		<% if viewlibrary.check_permission("downloadmessage") then %>
278 279
			<% htmlviewfunctions.displayitem(cfe({type="link", value={message=message, viewtype=viewtype}, label="", option="Download", action="downloadmessage"}), page_info, -1) %>
			<% htmlviewfunctions.displayitem(cfe({type="link", value={message=message, viewtype=viewtype}, label="", option="Play", action="downloadmessage", class="playmessage"}), page_info, -1) %>
280
		<% elseif viewlibrary.check_permission("downloadmymessage") then %>
281 282
			<% htmlviewfunctions.displayitem(cfe({type="link", value={message=message, viewtype=viewtype}, label="", option="Download", action="downloadmymessage"}), page_info, -1) %>
			<% htmlviewfunctions.displayitem(cfe({type="link", value={message=message, viewtype=viewtype}, label="", option="Play", action="downloadmymessage", class="playmessage"}), page_info, -1) %>
283
		<% end %>
284
		<% if callmenumber then %>
285
			<% htmlviewfunctions.displayitem(cfe({type="form", value={message=message, extension=extension}, label="", option="CallMe", action="callbackmymessage"}), page_info, -1) %>
286
		<% end %>
287 288 289 290 291 292 293 294 295
		</td>
                <td><%= html.html_escape(os.date("%x", v.created_epoch)) %></td>
                <td><%= html.html_escape(os.date("%X", v.created_epoch)) %></td>
                <td><%= html.html_escape(v.cid_number) %></td>
                <td><%= html.html_escape(v.read_flags) %></td>
                <td><%= html.html_escape(v.username) %></td>
                <td><%= html.html_escape(reversefolders[v.in_folder] or v.in_folder) %></td>
                <td><%= html.html_escape(v.message_len) %></td>
	</tr>
296
<% end %>
297 298
</tbody>
</table>
299 300 301 302 303 304 305

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