Commit e0c9a431 authored by Ted Trask's avatar Ted Trask

Change download(my)message to use proper cfe and new stream template

parent f2b741e6
......@@ -23,11 +23,14 @@ mymodule.listmymessages = function( self )
end
mymodule.downloadmessage = function( self )
return self.model.get_message(self.clientdata.message)
return self.handle_form(self, self.model.get_download_message, self.model.download_message, self.clientdata, "Download", "Download Message")
end
mymodule.downloadmymessage = function( self )
return self.model.get_message(self.clientdata.message, self.sessiondata.userinfo.userid)
self.clientdata.username = self.sessiondata.userinfo.userid
local retval = self.handle_form(self, self.model.get_download_message, self.model.download_message, self.clientdata, "Download", "Download Message")
retval.value.username.readonly = true
return retval
end
mymodule.deletemessage = function( self )
......
......@@ -275,11 +275,11 @@ end %>
<td>
<% message.value = v.uuid %>
<% if viewlibrary.check_permission("downloadmessage") then %>
<% 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) %>
<% htmlviewfunctions.displayitem(cfe({type="form", value={message=message, viewtype=viewtype}, label="", option="Download", action="downloadmessage"}), page_info, -1) %>
<% htmlviewfunctions.displayitem(cfe({type="form", value={message=message, viewtype=viewtype}, label="", option="Play", action="downloadmessage", class="playmessage"}), page_info, -1) %>
<% elseif viewlibrary.check_permission("downloadmymessage") then %>
<% 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) %>
<% htmlviewfunctions.displayitem(cfe({type="form", value={message=message, viewtype=viewtype}, label="", option="Download", action="downloadmymessage"}), page_info, -1) %>
<% htmlviewfunctions.displayitem(cfe({type="form", value={message=message, viewtype=viewtype}, label="", option="Play", action="downloadmymessage", class="playmessage"}), page_info, -1) %>
<% end %>
<% if callmenumber then %>
<% htmlviewfunctions.displayitem(cfe({type="form", value={message=message, extension=extension}, label="", option="CallMe", action="callbackmymessage"}), page_info, -1) %>
......
......@@ -456,27 +456,35 @@ mymodule.list_messages = function(username)
return cfe({ type="structure", value=retval, label="Messages", errtxt=errtxt })
end
mymodule.get_message = function(message, username)
local retval = cfe({ type="raw", label="error", option="audio/x-wav" })
mymodule.get_download_message = function(self, clientdata)
local result = {}
result.message = cfe({ label="Message" })
result.username = cfe({ label="User Name" })
return cfe({ type="group", value=result, label="Download Message" })
end
mymodule.download_message = function(self, downloadrequest)
local file = cfe({ type="raw", label="error", option="audio/x-wav" })
local res, err = pcall(function()
local connected = vmaildb.databaseconnect()
local sql = "SELECT username, file_path FROM voicemail_msgs"
sql = sql .. generatewhereclause(username, message)
sql = sql .. generatewhereclause(downloadrequest.value.username.value, downloadrequest.value.message.value)
local tmp = vmaildb.getselectresponse(sql)
if connected then databasedisconnect() end
if #tmp == 0 then
retval.errtxt = "Invalid message"
downloadrequest.errtxt = "Invalid message"
else
retval.label = posix.basename(tmp[1].file_path)
retval.value = fs.read_file(tmp[1].file_path)
file.label = posix.basename(tmp[1].file_path)
file.value = fs.read_file(tmp[1].file_path)
-- Mark the message as read
voicemail_read(tmp[1].username, config.domain, message)
voicemail_read(tmp[1].username, config.domain, downloadrequest.value.message.value)
end
downloadrequest.value.file = file
end)
if not res and err then
retval.errtxt = err
downloadrequest.errtxt = err
end
return retval
return downloadrequest
end
mymodule.get_delete_message = function(self, clientdata)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment