liquid_feedback_frontend

annotate app/main/delegation/new.lua @ 306:a88f3ecb4606

Fixed redirect after setting unit delegation
author bsw
date Sun Feb 26 17:12:51 2012 +0100 (2012-02-26)
parents c4dd225578d4
children f8481330f4c2
rev   line source
bsw@297 1 local voting_right_unit_id
bsw@297 2
bsw@248 3 local unit = Unit:by_id(param.get("unit_id", atom.integer))
bsw@248 4 if unit then
bsw@297 5 voting_right_unit_id = unit.id
bsw@264 6 slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation"))
bsw@248 7 util.help("delegation.new.unit")
bsw@248 8 end
bsw@248 9
bsw/jbe@0 10 local area = Area:by_id(param.get("area_id", atom.integer))
bsw/jbe@0 11 if area then
bsw@297 12 voting_right_unit_id = area.unit_id
bsw/jbe@0 13 slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
bsw/jbe@4 14 util.help("delegation.new.area")
bsw/jbe@0 15 end
bsw/jbe@0 16
bsw/jbe@0 17 local issue = Issue:by_id(param.get("issue_id", atom.integer))
bsw/jbe@0 18 if issue then
bsw@297 19 voting_right_unit_id = issue.area.unit_id
bsw/jbe@0 20 slot.put_into("title", encode.html(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name)))
bsw/jbe@4 21 util.help("delegation.new.issue")
bsw/jbe@0 22 end
bsw/jbe@0 23
poelzi@111 24 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
poelzi@111 25
bsw/jbe@4 26 slot.select("actions", function()
bsw/jbe@4 27 if issue then
bsw/jbe@4 28 ui.link{
bsw/jbe@4 29 module = "issue",
bsw/jbe@4 30 view = "show",
bsw/jbe@4 31 id = issue.id,
bsw/jbe@4 32 content = function()
bsw/jbe@4 33 ui.image{ static = "icons/16/cancel.png" }
bsw/jbe@4 34 slot.put(_"Cancel")
bsw/jbe@4 35 end,
bsw/jbe@4 36 }
bsw/jbe@4 37 elseif area then
bsw/jbe@4 38 ui.link{
bsw/jbe@4 39 module = "area",
bsw/jbe@4 40 view = "show",
bsw/jbe@4 41 id = area.id,
bsw/jbe@4 42 content = function()
bsw/jbe@4 43 ui.image{ static = "icons/16/cancel.png" }
bsw/jbe@4 44 slot.put(_"Cancel")
bsw/jbe@4 45 end,
bsw/jbe@4 46 }
bsw/jbe@4 47 else
bsw/jbe@4 48 ui.link{
bsw/jbe@4 49 module = "index",
bsw/jbe@4 50 view = "index",
bsw/jbe@4 51 content = function()
bsw/jbe@4 52 ui.image{ static = "icons/16/cancel.png" }
bsw/jbe@4 53 slot.put(_"Cancel")
bsw/jbe@4 54 end,
bsw/jbe@4 55 }
bsw/jbe@4 56 end
bsw/jbe@4 57 end)
bsw/jbe@4 58
bsw/jbe@4 59
bsw@199 60 local contact_members = Member:build_selector{
bsw@199 61 is_contact_of_member_id = app.session.member_id,
bsw@297 62 voting_right_for_unit_id = voting_right_unit_id,
bsw@199 63 order = "name"
bsw@199 64 }:exec()
bsw/jbe@0 65
bsw/jbe@0 66 ui.form{
bsw/jbe@0 67 attr = { class = "vertical" },
bsw/jbe@0 68 module = "delegation",
bsw/jbe@0 69 action = "update",
bsw/jbe@0 70 params = {
bsw@248 71 unit_id = unit and unit.id or nil,
bsw/jbe@0 72 area_id = area and area.id or nil,
bsw/jbe@0 73 issue_id = issue and issue.id or nil,
bsw/jbe@0 74 },
bsw/jbe@0 75 routing = {
bsw/jbe@0 76 default = {
bsw/jbe@0 77 mode = "redirect",
bsw@306 78 module = area and "area" or issue and "issue" or "unit",
bsw@306 79 view = "show",
bsw@306 80 id = area and area.id or issue and issue.id or unit.id
bsw/jbe@0 81 }
bsw/jbe@0 82 },
bsw/jbe@0 83 content = function()
bsw@180 84 local records
bsw@180 85
bsw@180 86 if issue then
bsw@183 87 local delegate_name = ""
bsw@183 88 local scope = "no delegation set"
bsw@248 89 local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
bsw@183 90 if area_delegation then
bsw@187 91 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
bsw@183 92 scope = _"area"
bsw@183 93 else
bsw@248 94 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
bsw@248 95 if unit_delegation then
bsw@248 96 delegate_name = unit_delegation.trustee.name
bsw@264 97 scope = config.single_unit_id and _"global" or _"unit"
bsw@248 98 end
bsw@183 99 end
bsw@264 100 local text_apply
bsw@264 101 local text_abandon
bsw@264 102 if config.single_unit_id then
bsw@264 103 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@264 104 text_abandon = _"Abandon unit and area delegations for this issue"
bsw@264 105 else
bsw@264 106 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@264 107 text_abandon = _"Abandon unit and area delegations for this issue"
bsw@264 108 end
bsw@180 109 records = {
bsw@264 110 { id = -1, name = text_apply },
bsw@293 111 { id = 0, name = text_abandon }
bsw/jbe@4 112 }
bsw@180 113 elseif area then
bsw@183 114 local delegate_name = ""
bsw@183 115 local scope = "no delegation set"
bsw@248 116 local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
bsw@248 117 if unit_delegation then
bsw@248 118 delegate_name = unit_delegation.trustee.name
bsw@264 119 scope = config.single_unit_id and _"global" or _"unit"
bsw@264 120 end
bsw@264 121 local text_apply
bsw@264 122 local text_abandon
bsw@264 123 if config.single_unit_id then
bsw@264 124 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@264 125 text_abandon = _"Abandon global delegation for this area"
bsw@264 126 else
bsw@264 127 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
bsw@264 128 text_abandon = _"Abandon unit delegation for this area"
bsw@183 129 end
bsw@180 130 records = {
bsw@180 131 {
bsw@180 132 id = -1,
bsw@264 133 name = text_apply
bsw@180 134 },
bsw@180 135 {
bsw@180 136 id = 0,
bsw@264 137 name = text_abandon
bsw@180 138 }
bsw@180 139 }
bsw@180 140
bsw@180 141 else
bsw@180 142 records = {
bsw@180 143 {
bsw@180 144 id = -1,
bsw@180 145 name = _"No delegation"
bsw@180 146 }
bsw@180 147 }
bsw@180 148
bsw@180 149 end
bsw@183 150 -- add saved members
bsw@183 151 records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
bsw/jbe@4 152 for i, record in ipairs(contact_members) do
bsw/jbe@4 153 records[#records+1] = record
bsw/jbe@4 154 end
poelzi@111 155 -- add initiative authors
poelzi@111 156 if initiative then
bsw@183 157 records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
poelzi@111 158 for i,record in ipairs(initiative.initiators) do
poelzi@111 159 records[#records+1] = record.member
poelzi@111 160 end
poelzi@111 161 end
bsw/jbe@4 162
bsw@183 163 disabled_records = {}
bsw@183 164 disabled_records["_"] = true
bsw@183 165
bsw/jbe@0 166 ui.field.select{
bsw/jbe@0 167 label = _"Trustee",
bsw/jbe@0 168 name = "trustee_id",
bsw/jbe@4 169 foreign_records = records,
bsw/jbe@0 170 foreign_id = "id",
bsw/jbe@4 171 foreign_name = "name",
poelzi@111 172 disabled_records = disabled_records
bsw/jbe@0 173 }
poelzi@111 174
bsw/jbe@0 175 ui.submit{ text = _"Save" }
bsw/jbe@0 176 end
bsw/jbe@4 177 }

Impressum / About Us