annotate app/main/index/document.lua @ 401:08ba83dd47c0
Add support for files only available to logged in members
author |
bsw |
date |
Wed Mar 07 19:07:20 2012 +0100 (2012-03-07) |
parents |
|
children |
a42bc1f0ed45 |
rev |
line source |
bsw@401
|
1 if not config.document_dir then
|
bsw@401
|
2 error("feature not enabled")
|
bsw@401
|
3 end
|
bsw@401
|
4
|
bsw@401
|
5 slot.put_into("title", _"Download documents")
|
bsw@401
|
6
|
bsw@401
|
7 slot.select("actions", function()
|
bsw@401
|
8 ui.link{
|
bsw@401
|
9 content = function()
|
bsw@401
|
10 ui.image{ static = "icons/16/cancel.png" }
|
bsw@401
|
11 slot.put(_"Cancel")
|
bsw@401
|
12 end,
|
bsw@401
|
13 module = "index",
|
bsw@401
|
14 view = "index"
|
bsw@401
|
15 }
|
bsw@401
|
16 end)
|
bsw@401
|
17
|
bsw@401
|
18 util.help("index.document", _"Download documents")
|
bsw@401
|
19
|
bsw@401
|
20 local file_list = os.listdir(config.document_dir)
|
bsw@401
|
21
|
bsw@401
|
22 local tmp = {}
|
bsw@401
|
23 for i, filename in ipairs(file_list) do
|
bsw@401
|
24 if not filename:find("^%.") then
|
bsw@401
|
25 tmp[#tmp+1] = filename
|
bsw@401
|
26 end
|
bsw@401
|
27 end
|
bsw@401
|
28
|
bsw@401
|
29 local file_list = tmp
|
bsw@401
|
30
|
bsw@401
|
31 table.sort(file_list, function(a, b) return a > b end)
|
bsw@401
|
32
|
bsw@401
|
33 ui.list{
|
bsw@401
|
34 records = file_list,
|
bsw@401
|
35 columns = {
|
bsw@401
|
36 {
|
bsw@401
|
37 content = function(filename)
|
bsw@401
|
38 slot.put(encode.html(filename))
|
bsw@401
|
39 end
|
bsw@401
|
40 },
|
bsw@401
|
41 {
|
bsw@401
|
42 content = function(filename)
|
bsw@401
|
43 ui.link{
|
bsw@401
|
44 content = _"Download",
|
bsw@401
|
45 module = "index",
|
bsw@401
|
46 view = "document_file",
|
bsw@401
|
47 params = { filename = filename }
|
bsw@401
|
48 }
|
bsw@401
|
49 end
|
bsw@401
|
50 }
|
bsw@401
|
51 }
|
bsw@401
|
52 } |