webmcp

view demo-app/app/main/medium/show.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children
line source
1 local medium
2 local id = param.get_id()
3 if id then
4 medium = Medium:by_id(id)
5 end
7 if medium then
8 slot.put_into("title", encode.html(_"Medium"))
9 else
10 slot.put_into("title", encode.html(_"New medium"))
11 end
13 slot.select("actions", function()
14 ui.link{
15 content = _"Back",
16 module = "medium"
17 }
18 if medium and app.session.user.write_priv then
19 ui.link{
20 content = _"Delete",
21 form_attr = {
22 onsubmit = "return confirm(" .. encode.json(_'Are you sure?') .. ");"
23 },
24 module = "medium",
25 action = "update",
26 id = medium.id,
27 params = { delete = true },
28 routing = {
29 default = {
30 mode = "redirect",
31 module = "medium",
32 view = "index"
33 }
34 }
35 }
36 end
37 end)
39 slot.select("main", function()
40 ui.form{
41 attr = { class = "vertical" },
42 record = medium,
43 readonly = not app.session.user.write_priv,
44 module = "medium",
45 action = "update",
46 id = id,
47 routing = {
48 default = {
49 mode = "redirect",
50 module = "medium",
51 view = "index"
52 }
53 },
54 content = function()
55 if id then
56 ui.field.integer{ label = _"Id", name = "id", readonly = true }
57 end
58 ui.field.select{
59 label = _"Media type",
60 name = "media_type_id",
61 foreign_records = MediaType:new_selector():exec(),
62 foreign_id = "id",
63 foreign_name = "name"
64 }
65 ui.field.text{ label = _"Name", name = "name" }
66 ui.field.boolean{ label = _"Copy protected", name = "copyprotected" }
68 ui.multiselect{
69 name = "genres[]",
70 label = _"Genres",
71 style = "select",
72 attr = { size = 5 },
73 foreign_records = Genre:new_selector():exec(),
74 connecting_records = medium and medium.classifications or {},
75 own_id = "id",
76 own_reference = "medium_id",
77 foreign_reference = "genre_id",
78 foreign_id = "id",
79 foreign_name = "name",
80 }
81 local tracks = medium and medium.tracks or {}
82 for i = 1, 5 do
83 tracks[#tracks+1] = Track:new()
84 end
85 ui.list{
86 label = _"Tracks",
87 prefix = "tracks",
88 records = tracks,
89 columns = {
90 {
91 label = _"Pos",
92 name = "position",
93 },
94 {
95 label = _"Name",
96 name = "name",
97 },
98 {
99 label = _"Description",
100 name = "description",
101 },
102 {
103 label = _"Duration",
104 name = "duration",
105 },
106 {
107 content = function()
108 ui.field.hidden{ name = "id" }
109 end
110 }
111 }
112 }
114 ui.submit{ text = _"Save" }
115 end
116 }
117 end)

Impressum / About Us