webmcp

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/demo-app/app/main/medium/show.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +local medium
     1.5 +local id = param.get_id()
     1.6 +if id then
     1.7 +  medium = Medium:by_id(id)
     1.8 +end
     1.9 +
    1.10 +if medium then
    1.11 +  slot.put_into("title", encode.html(_"Medium"))
    1.12 +else
    1.13 +  slot.put_into("title", encode.html(_"New medium"))
    1.14 +end
    1.15 +
    1.16 +slot.select("actions", function()
    1.17 +  ui.link{
    1.18 +    content = _"Back",
    1.19 +    module = "medium"
    1.20 +  }
    1.21 +  if medium and app.session.user.write_priv then
    1.22 +    ui.link{
    1.23 +      content = _"Delete",
    1.24 +      form_attr = {
    1.25 +        onsubmit = "return confirm(" .. encode.json(_'Are you sure?') .. ");"
    1.26 +      },
    1.27 +      module  = "medium",
    1.28 +      action  = "update",
    1.29 +      id      = medium.id,
    1.30 +      params = { delete = true },
    1.31 +      routing = {
    1.32 +        default = {
    1.33 +          mode = "redirect",
    1.34 +          module = "medium",
    1.35 +          view = "index"
    1.36 +        }
    1.37 +      }
    1.38 +    }
    1.39 +  end
    1.40 +end)
    1.41 +
    1.42 +slot.select("main", function()
    1.43 +  ui.form{
    1.44 +    attr = { class = "vertical" },
    1.45 +    record = medium,
    1.46 +    readonly = not app.session.user.write_priv,
    1.47 +    module = "medium",
    1.48 +    action = "update",
    1.49 +    id = id,
    1.50 +    routing = {
    1.51 +      default = {
    1.52 +        mode = "redirect",
    1.53 +        module = "medium",
    1.54 +        view = "index"
    1.55 +      }
    1.56 +    },
    1.57 +    content = function()
    1.58 +      if id then
    1.59 +        ui.field.integer{ label = _"Id", name = "id", readonly = true }
    1.60 +      end
    1.61 +      ui.field.select{
    1.62 +        label = _"Media type",
    1.63 +        name  = "media_type_id",
    1.64 +        foreign_records = MediaType:new_selector():exec(),
    1.65 +        foreign_id = "id",
    1.66 +        foreign_name = "name"
    1.67 +      }
    1.68 +      ui.field.text{    label = _"Name",           name = "name"           }
    1.69 +      ui.field.boolean{ label = _"Copy protected", name = "copyprotected"  }
    1.70 +
    1.71 +      ui.multiselect{
    1.72 +        name               = "genres[]",
    1.73 +        label              = _"Genres",
    1.74 +        style              = "select",
    1.75 +        attr = { size = 5 },
    1.76 +        foreign_records    = Genre:new_selector():exec(),
    1.77 +        connecting_records = medium and medium.classifications or {},
    1.78 +        own_id             = "id",
    1.79 +        own_reference      = "medium_id",
    1.80 +        foreign_reference  = "genre_id",
    1.81 +        foreign_id         = "id",
    1.82 +        foreign_name       = "name",
    1.83 +      }
    1.84 +      local tracks = medium and medium.tracks or {}
    1.85 +      for i = 1, 5 do
    1.86 +        tracks[#tracks+1] = Track:new()
    1.87 +      end
    1.88 +      ui.list{
    1.89 +        label = _"Tracks",
    1.90 +        prefix = "tracks",
    1.91 +        records = tracks,
    1.92 +        columns = {
    1.93 +          {
    1.94 +            label = _"Pos",
    1.95 +            name = "position",
    1.96 +          },
    1.97 +          {
    1.98 +            label = _"Name",
    1.99 +            name = "name",
   1.100 +          },
   1.101 +          {
   1.102 +            label = _"Description",
   1.103 +            name = "description",
   1.104 +          },
   1.105 +          {
   1.106 +            label = _"Duration",
   1.107 +            name = "duration",
   1.108 +          },
   1.109 +          {
   1.110 +            content = function()
   1.111 +              ui.field.hidden{ name = "id" }
   1.112 +            end
   1.113 +          }
   1.114 +        }
   1.115 +      }
   1.116 +
   1.117 +      ui.submit{ text = _"Save" }
   1.118 +    end
   1.119 +  }
   1.120 +end)

Impressum / About Us