webmcp

diff demo-app/app/main/medium/_action/update.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/_action/update.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,51 @@
     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 +else
     1.9 +  medium = Medium:new()
    1.10 +end
    1.11 +
    1.12 +if param.get("delete", atom.boolean) then
    1.13 +  local name = medium.name
    1.14 +  medium:destroy()
    1.15 +  slot.put_into("notice", _("Medium '#{name}' deleted", {name = name}))
    1.16 +  return
    1.17 +end
    1.18 +
    1.19 +param.update(medium, "media_type_id", "name", "copyprotected")
    1.20 +
    1.21 +medium:save()
    1.22 +
    1.23 +param.update_relationship{
    1.24 +  param_name        = "genres",
    1.25 +  id                = medium.id,
    1.26 +  connecting_model  = Classification,
    1.27 +  own_reference     = "medium_id",
    1.28 +  foreign_reference = "genre_id"
    1.29 +}
    1.30 +
    1.31 +for index, prefix in param.iterate("tracks") do
    1.32 +  local id = param.get(prefix .. "id", atom.integer)
    1.33 +  local track
    1.34 +  if id then
    1.35 +    track = Track:by_id(id)
    1.36 +  elseif #param.get(prefix .. "name") > 0 then
    1.37 +    track = Track:new()
    1.38 +    track.medium_id = medium.id
    1.39 +  else
    1.40 +    break
    1.41 +  end
    1.42 +  track.position    = param.get(prefix .. "position", atom.integer)
    1.43 +  track.name        = param.get(prefix .. "name")
    1.44 +  track.description = param.get(prefix .. "description")
    1.45 +  track.duration    = param.get(prefix .. "duration")
    1.46 +  track:save()
    1.47 +end
    1.48 +
    1.49 +
    1.50 +if id then
    1.51 +  slot.put_into("notice", _("Medium '#{name}' updated", {name = medium.name}))
    1.52 +else
    1.53 +  slot.put_into("notice", _("Medium '#{name}' created", {name = medium.name}))
    1.54 +end

Impressum / About Us