| rev | 
   line source | 
| 
bsw@1248
 | 
     1 local id = param.get_id()
 | 
| 
bsw@1248
 | 
     2 
 | 
| 
bsw@1248
 | 
     3 local newsletter = {}
 | 
| 
bsw@1248
 | 
     4 
 | 
| 
bsw@1248
 | 
     5 if id then
 | 
| 
bsw@1248
 | 
     6   newsletter = Newsletter:by_id(id)
 | 
| 
bsw@1248
 | 
     7 end
 | 
| 
bsw@1248
 | 
     8 
 | 
| 
bsw@1248
 | 
     9 ui.titleAdmin(_"Newsletter")
 | 
| 
bsw@1248
 | 
    10 
 | 
| 
bsw@1248
 | 
    11 ui.form{
 | 
| 
bsw@1248
 | 
    12   attr = { class = "vertical section" },
 | 
| 
bsw@1248
 | 
    13   module = "admin",
 | 
| 
bsw@1248
 | 
    14   action = "newsletter_update",
 | 
| 
bsw@1248
 | 
    15   id = newsletter and newsletter.id,
 | 
| 
bsw@1248
 | 
    16   record = newsletter,
 | 
| 
bsw@1248
 | 
    17   routing = {
 | 
| 
bsw@1248
 | 
    18     default = {
 | 
| 
bsw@1248
 | 
    19       mode = "redirect",
 | 
| 
bsw@1248
 | 
    20       modules = "admin",
 | 
| 
bsw@1248
 | 
    21       view = "newsletter_list"
 | 
| 
bsw@1248
 | 
    22     }
 | 
| 
bsw@1248
 | 
    23   },
 | 
| 
bsw@1248
 | 
    24   content = function()
 | 
| 
bsw@1248
 | 
    25 
 | 
| 
bsw@1248
 | 
    26     ui.sectionHead( function()
 | 
| 
bsw@1248
 | 
    27       ui.heading { level = 1, content = newsletter and (newsletter.subject) or _"New newsletter" }
 | 
| 
bsw@1248
 | 
    28     end )
 | 
| 
bsw@1248
 | 
    29   
 | 
| 
bsw@1248
 | 
    30     ui.sectionRow( function()
 | 
| 
bsw@1248
 | 
    31       local units = { 
 | 
| 
bsw@1248
 | 
    32         { id = 0, name = _"All members" },
 | 
| 
bsw@1248
 | 
    33         { id = "_", name = _"" },
 | 
| 
bsw@1248
 | 
    34       }
 | 
| 
bsw@1248
 | 
    35       for i, unit in ipairs(Unit:get_flattened_tree()) do
 | 
| 
bsw@1248
 | 
    36         units[#units+1] = unit
 | 
| 
bsw@1248
 | 
    37       end
 | 
| 
bsw@1248
 | 
    38       ui.field.text{ label = _"Date", name = "published" }
 | 
| 
bsw@1248
 | 
    39       ui.field.select{
 | 
| 
bsw@1248
 | 
    40         label = "Recipient",
 | 
| 
bsw@1248
 | 
    41         name = "unit_id",
 | 
| 
bsw@1248
 | 
    42         foreign_records = units,
 | 
| 
bsw@1248
 | 
    43         foreign_id = "id",
 | 
| 
bsw@1248
 | 
    44         foreign_name = "name",
 | 
| 
bsw@1248
 | 
    45         disabled_records = { ["_"] = true },
 | 
| 
bsw@1248
 | 
    46         value = newsletter.unit_id
 | 
| 
bsw@1248
 | 
    47       }
 | 
| 
bsw@1248
 | 
    48       ui.field.boolean{  label = _"Override disable notifications?", name = "include_all_members" }
 | 
| 
bsw@1248
 | 
    49       slot.put("<br />")
 | 
| 
bsw@1248
 | 
    50       ui.field.text{     label = _"Subject", name = "subject" }
 | 
| 
bsw@1248
 | 
    51       ui.field.text{     label = _"Content", name = "content", multiline = true, attr = { rows = "20" } }
 | 
| 
bsw@1248
 | 
    52 
 | 
| 
bsw@1248
 | 
    53       ui.submit{         text  = _"create newsletter" }
 | 
| 
bsw@1248
 | 
    54       slot.put(" ")
 | 
| 
bsw@1248
 | 
    55       ui.link { module = "admin", view = "index", content = _"cancel" }
 | 
| 
bsw@1248
 | 
    56     end )
 | 
| 
bsw@1248
 | 
    57   end
 | 
| 
bsw@1248
 | 
    58 }
 | 
| 
bsw@1248
 | 
    59 
 |