| rev | 
   line source | 
| 
bsw@525
 | 
     1 local voting_right_unit_id
 | 
| 
bsw@525
 | 
     2 
 | 
| 
bsw@525
 | 
     3 local unit = Unit:by_id(param.get("unit_id", atom.integer))
 | 
| 
bsw@525
 | 
     4 if unit then
 | 
| 
bsw@525
 | 
     5   voting_right_unit_id = unit.id
 | 
| 
bsw@525
 | 
     6   slot.put_into("title", encode.html(config.single_unit_id and _"Set global delegation" or _"Set unit delegation"))
 | 
| 
bsw@525
 | 
     7   util.help("delegation.new.unit")
 | 
| 
bsw@525
 | 
     8 end
 | 
| 
bsw@525
 | 
     9 
 | 
| 
bsw@525
 | 
    10 local area = Area:by_id(param.get("area_id", atom.integer))
 | 
| 
bsw@525
 | 
    11 if area then
 | 
| 
bsw@525
 | 
    12   voting_right_unit_id = area.unit_id
 | 
| 
bsw@525
 | 
    13   slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name)))
 | 
| 
bsw@525
 | 
    14   util.help("delegation.new.area")
 | 
| 
bsw@525
 | 
    15 end
 | 
| 
bsw@525
 | 
    16 
 | 
| 
bsw@525
 | 
    17 local issue = Issue:by_id(param.get("issue_id", atom.integer))
 | 
| 
bsw@525
 | 
    18 if issue then
 | 
| 
bsw@525
 | 
    19   voting_right_unit_id = issue.area.unit_id
 | 
| 
bsw@525
 | 
    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@525
 | 
    21   util.help("delegation.new.issue")
 | 
| 
bsw@525
 | 
    22 end
 | 
| 
bsw@525
 | 
    23 
 | 
| 
bsw@525
 | 
    24 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
 | 
| 
bsw@525
 | 
    25 
 | 
| 
bsw@525
 | 
    26 slot.select("actions", function()
 | 
| 
bsw@525
 | 
    27   if issue then
 | 
| 
bsw@525
 | 
    28     ui.link{
 | 
| 
bsw@525
 | 
    29       module = "issue",
 | 
| 
bsw@525
 | 
    30       view = "show",
 | 
| 
bsw@525
 | 
    31       id = issue.id,
 | 
| 
bsw@525
 | 
    32       content = function()
 | 
| 
bsw@525
 | 
    33           ui.image{ static = "icons/16/cancel.png" }
 | 
| 
bsw@525
 | 
    34           slot.put(_"Cancel")
 | 
| 
bsw@525
 | 
    35       end,
 | 
| 
bsw@525
 | 
    36     }
 | 
| 
bsw@525
 | 
    37   elseif area then
 | 
| 
bsw@525
 | 
    38     ui.link{
 | 
| 
bsw@525
 | 
    39       module = "area",
 | 
| 
bsw@525
 | 
    40       view = "show",
 | 
| 
bsw@525
 | 
    41       id = area.id,
 | 
| 
bsw@525
 | 
    42       content = function()
 | 
| 
bsw@525
 | 
    43           ui.image{ static = "icons/16/cancel.png" }
 | 
| 
bsw@525
 | 
    44           slot.put(_"Cancel")
 | 
| 
bsw@525
 | 
    45       end,
 | 
| 
bsw@525
 | 
    46     }
 | 
| 
bsw@525
 | 
    47   else
 | 
| 
bsw@525
 | 
    48     ui.link{
 | 
| 
bsw@525
 | 
    49       module = "index",
 | 
| 
bsw@525
 | 
    50       view = "index",
 | 
| 
bsw@525
 | 
    51       content = function()
 | 
| 
bsw@525
 | 
    52           ui.image{ static = "icons/16/cancel.png" }
 | 
| 
bsw@525
 | 
    53           slot.put(_"Cancel")
 | 
| 
bsw@525
 | 
    54       end,
 | 
| 
bsw@525
 | 
    55     }
 | 
| 
bsw@525
 | 
    56   end
 | 
| 
bsw@525
 | 
    57 end)
 | 
| 
bsw@525
 | 
    58 
 | 
| 
bsw@525
 | 
    59 
 | 
| 
bsw@525
 | 
    60 local contact_members = Member:build_selector{
 | 
| 
bsw@525
 | 
    61   is_contact_of_member_id = app.session.member_id,
 | 
| 
bsw@525
 | 
    62   voting_right_for_unit_id = voting_right_unit_id,
 | 
| 
bsw@525
 | 
    63   order = "name"
 | 
| 
bsw@525
 | 
    64 }:exec()
 | 
| 
bsw@525
 | 
    65 
 | 
| 
bsw@525
 | 
    66 ui.form{
 | 
| 
bsw@525
 | 
    67   attr = { class = "vertical" },
 | 
| 
bsw@525
 | 
    68   module = "delegation",
 | 
| 
bsw@525
 | 
    69   action = "update",
 | 
| 
bsw@525
 | 
    70   params = {
 | 
| 
bsw@525
 | 
    71     unit_id = unit and unit.id or nil,
 | 
| 
bsw@525
 | 
    72     area_id = area and area.id or nil,
 | 
| 
bsw@525
 | 
    73     issue_id = issue and issue.id or nil,
 | 
| 
bsw@525
 | 
    74   },
 | 
| 
bsw@525
 | 
    75   routing = {
 | 
| 
bsw@525
 | 
    76     default = {
 | 
| 
bsw@525
 | 
    77       mode = "redirect",
 | 
| 
bsw@525
 | 
    78       module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
 | 
| 
bsw@525
 | 
    79       view = "show",
 | 
| 
bsw@525
 | 
    80       id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id
 | 
| 
bsw@525
 | 
    81     }
 | 
| 
bsw@525
 | 
    82   },
 | 
| 
bsw@525
 | 
    83   content = function()
 | 
| 
bsw@525
 | 
    84     local records
 | 
| 
bsw@525
 | 
    85 
 | 
| 
bsw@525
 | 
    86     if issue then
 | 
| 
bsw@525
 | 
    87       local delegate_name = ""
 | 
| 
bsw@525
 | 
    88       local scope = "no delegation set"
 | 
| 
bsw@525
 | 
    89       local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
 | 
| 
bsw@525
 | 
    90       if area_delegation then
 | 
| 
bsw@525
 | 
    91         delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
 | 
| 
bsw@525
 | 
    92         scope = _"area"
 | 
| 
bsw@525
 | 
    93       else
 | 
| 
bsw@525
 | 
    94         local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
 | 
| 
bsw@525
 | 
    95         if unit_delegation then
 | 
| 
bsw@525
 | 
    96           delegate_name = unit_delegation.trustee.name
 | 
| 
bsw@525
 | 
    97           scope = config.single_unit_id and _"global" or _"unit"
 | 
| 
bsw@525
 | 
    98         end
 | 
| 
bsw@525
 | 
    99       end
 | 
| 
bsw@525
 | 
   100       local text_apply
 | 
| 
bsw@525
 | 
   101       local text_abandon
 | 
| 
bsw@525
 | 
   102       if config.single_unit_id then
 | 
| 
bsw@525
 | 
   103         text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw@525
 | 
   104         text_abandon = _"Abandon unit and area delegations for this issue"
 | 
| 
bsw@525
 | 
   105       else
 | 
| 
bsw@525
 | 
   106         text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw@525
 | 
   107         text_abandon = _"Abandon unit and area delegations for this issue"
 | 
| 
bsw@525
 | 
   108       end
 | 
| 
bsw@525
 | 
   109       records = {
 | 
| 
bsw@525
 | 
   110         { id = -1, name = text_apply },
 | 
| 
bsw@525
 | 
   111         { id = 0,  name = text_abandon }
 | 
| 
bsw@525
 | 
   112       }
 | 
| 
bsw@525
 | 
   113     elseif area then
 | 
| 
bsw@525
 | 
   114       local delegate_name = ""
 | 
| 
bsw@525
 | 
   115       local scope = "no delegation set"
 | 
| 
bsw@525
 | 
   116       local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
 | 
| 
bsw@525
 | 
   117       if unit_delegation then
 | 
| 
bsw@525
 | 
   118         delegate_name = unit_delegation.trustee.name
 | 
| 
bsw@525
 | 
   119         scope = config.single_unit_id and _"global" or _"unit"
 | 
| 
bsw@525
 | 
   120       end
 | 
| 
bsw@525
 | 
   121       local text_apply
 | 
| 
bsw@525
 | 
   122       local text_abandon
 | 
| 
bsw@525
 | 
   123       if config.single_unit_id then
 | 
| 
bsw@525
 | 
   124         text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw@525
 | 
   125         text_abandon = _"Abandon global delegation for this area"
 | 
| 
bsw@525
 | 
   126       else
 | 
| 
bsw@525
 | 
   127         text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw@525
 | 
   128         text_abandon = _"Abandon unit delegation for this area"
 | 
| 
bsw@525
 | 
   129       end
 | 
| 
bsw@525
 | 
   130       records = {
 | 
| 
bsw@525
 | 
   131         {
 | 
| 
bsw@525
 | 
   132           id = -1,
 | 
| 
bsw@525
 | 
   133           name = text_apply
 | 
| 
bsw@525
 | 
   134         },
 | 
| 
bsw@525
 | 
   135         {
 | 
| 
bsw@525
 | 
   136           id = 0,
 | 
| 
bsw@525
 | 
   137           name = text_abandon
 | 
| 
bsw@525
 | 
   138         }
 | 
| 
bsw@525
 | 
   139       }
 | 
| 
bsw@525
 | 
   140 
 | 
| 
bsw@525
 | 
   141     else
 | 
| 
bsw@525
 | 
   142       records = {
 | 
| 
bsw@525
 | 
   143         {
 | 
| 
bsw@525
 | 
   144           id = -1,
 | 
| 
bsw@525
 | 
   145           name = _"No delegation"
 | 
| 
bsw@525
 | 
   146         }
 | 
| 
bsw@525
 | 
   147       }
 | 
| 
bsw@525
 | 
   148 
 | 
| 
bsw@525
 | 
   149     end
 | 
| 
bsw@525
 | 
   150     -- add saved members
 | 
| 
bsw@525
 | 
   151     records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
 | 
| 
bsw@525
 | 
   152     for i, record in ipairs(contact_members) do
 | 
| 
bsw@525
 | 
   153       records[#records+1] = record
 | 
| 
bsw@525
 | 
   154     end
 | 
| 
bsw@525
 | 
   155     -- add initiative authors
 | 
| 
bsw@525
 | 
   156     if initiative then
 | 
| 
bsw@525
 | 
   157       records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
 | 
| 
bsw@525
 | 
   158       for i,record in ipairs(initiative.initiators) do
 | 
| 
bsw@525
 | 
   159         records[#records+1] = record.member
 | 
| 
bsw@525
 | 
   160       end
 | 
| 
bsw@525
 | 
   161     end
 | 
| 
bsw@525
 | 
   162 
 | 
| 
bsw@525
 | 
   163     disabled_records = {}
 | 
| 
bsw@525
 | 
   164     disabled_records["_"] = true
 | 
| 
bsw@525
 | 
   165     disabled_records[app.session.member_id] = true
 | 
| 
bsw@525
 | 
   166 
 | 
| 
bsw@525
 | 
   167     ui.field.select{
 | 
| 
bsw@525
 | 
   168       label = _"Trustee",
 | 
| 
bsw@525
 | 
   169       name = "trustee_id",
 | 
| 
bsw@525
 | 
   170       foreign_records = records,
 | 
| 
bsw@525
 | 
   171       foreign_id = "id",
 | 
| 
bsw@525
 | 
   172       foreign_name = "name",
 | 
| 
bsw@525
 | 
   173       disabled_records = disabled_records
 | 
| 
bsw@525
 | 
   174     }
 | 
| 
bsw@525
 | 
   175 
 | 
| 
bsw@525
 | 
   176     ui.submit{ text = _"Save" }
 | 
| 
bsw@525
 | 
   177   end
 | 
| 
bsw@525
 | 
   178 }
 | 
| 
bsw@525
 | 
   179 
 | 
| 
bsw@525
 | 
   180 
 | 
| 
bsw@525
 | 
   181 
 | 
| 
bsw@525
 | 
   182 -- ------------------------
 | 
| 
bsw@525
 | 
   183 
 | 
| 
bsw@525
 | 
   184 
 | 
| 
bsw@525
 | 
   185 
 | 
| 
bsw@525
 | 
   186 
 | 
| 
bsw@525
 | 
   187 local delegation
 | 
| 
bsw@525
 | 
   188 local unit_id
 | 
| 
bsw@525
 | 
   189 local area_id
 | 
| 
bsw@525
 | 
   190 local issue_id
 | 
| 
bsw@525
 | 
   191 local initiative_id
 | 
| 
bsw@525
 | 
   192 
 | 
| 
bsw@525
 | 
   193 local scope = "unit"
 | 
| 
bsw@525
 | 
   194 
 | 
| 
bsw@525
 | 
   195 unit_id = param.get("unit_id", atom.integer)
 | 
| 
bsw@525
 | 
   196 
 | 
| 
bsw@525
 | 
   197 local inline = param.get("inline", atom.boolean)
 | 
| 
bsw@525
 | 
   198 
 | 
| 
bsw@525
 | 
   199 if param.get("initiative_id", atom.integer) then
 | 
| 
bsw@525
 | 
   200   initiative_id = param.get("initiative_id", atom.integer)
 | 
| 
bsw@525
 | 
   201   issue_id = Initiative:by_id(initiative_id).issue_id
 | 
| 
bsw@525
 | 
   202   scope = "issue"
 | 
| 
bsw@525
 | 
   203 end
 | 
| 
bsw@525
 | 
   204 
 | 
| 
bsw@525
 | 
   205 if param.get("issue_id", atom.integer) then
 | 
| 
bsw@525
 | 
   206   issue_id = param.get("issue_id", atom.integer)
 | 
| 
bsw@525
 | 
   207   scope = "issue"
 | 
| 
bsw@525
 | 
   208 end
 | 
| 
bsw@525
 | 
   209 
 | 
| 
bsw@525
 | 
   210 if param.get("area_id", atom.integer) then
 | 
| 
bsw@525
 | 
   211   area_id = param.get("area_id", atom.integer)
 | 
| 
bsw@525
 | 
   212   scope = "area"
 | 
| 
bsw@525
 | 
   213 end
 | 
| 
bsw@525
 | 
   214 
 | 
| 
bsw@525
 | 
   215 
 | 
| 
bsw@525
 | 
   216 
 | 
| 
bsw@525
 | 
   217 local delegation
 | 
| 
bsw@525
 | 
   218 local issue
 | 
| 
bsw@525
 | 
   219 
 | 
| 
bsw@525
 | 
   220 if issue_id then
 | 
| 
bsw@525
 | 
   221   issue = Issue:by_id(issue_id)
 | 
| 
bsw@525
 | 
   222   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
 | 
| 
bsw@525
 | 
   223   if not delegation then
 | 
| 
bsw@525
 | 
   224     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
 | 
| 
bsw@525
 | 
   225   end
 | 
| 
bsw@525
 | 
   226   if not delegation then
 | 
| 
bsw@525
 | 
   227     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
 | 
| 
bsw@525
 | 
   228   end
 | 
| 
bsw@525
 | 
   229 elseif area_id then
 | 
| 
bsw@525
 | 
   230   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
 | 
| 
bsw@525
 | 
   231   if not delegation then
 | 
| 
bsw@525
 | 
   232     local area = Area:by_id(area_id)
 | 
| 
bsw@525
 | 
   233     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
 | 
| 
bsw@525
 | 
   234   end
 | 
| 
bsw@525
 | 
   235 end
 | 
| 
bsw@525
 | 
   236 
 | 
| 
bsw@525
 | 
   237 if not delegation then
 | 
| 
bsw@525
 | 
   238   delegation = Delegation:by_pk(app.session.member.id, unit_id)
 | 
| 
bsw@525
 | 
   239 end
 | 
| 
bsw@525
 | 
   240 
 | 
| 
bsw@525
 | 
   241 local slot_name = "actions"
 | 
| 
bsw@525
 | 
   242 
 | 
| 
bsw@525
 | 
   243 if inline then
 | 
| 
bsw@525
 | 
   244   slot_name = "default"
 | 
| 
bsw@525
 | 
   245 end
 | 
| 
bsw@525
 | 
   246 
 | 
| 
bsw@525
 | 
   247 if delegation then
 | 
| 
bsw@525
 | 
   248 
 | 
| 
bsw@525
 | 
   249   if not delegation.trustee_id then
 | 
| 
bsw@525
 | 
   250     ui.image{
 | 
| 
bsw@525
 | 
   251       static = "icons/16/table_go_crossed.png"
 | 
| 
bsw@525
 | 
   252     }
 | 
| 
bsw@525
 | 
   253     if delegation.issue_id then
 | 
| 
bsw@525
 | 
   254       slot.put(_"Delegation turned off for issue")
 | 
| 
bsw@525
 | 
   255     elseif delegation.area_id then
 | 
| 
bsw@525
 | 
   256       slot.put(_"Delegation turned off for area")
 | 
| 
bsw@525
 | 
   257     end
 | 
| 
bsw@525
 | 
   258   end
 | 
| 
bsw@525
 | 
   259 
 | 
| 
bsw@525
 | 
   260   local delegation_chain = Member:new_selector()
 | 
| 
bsw@525
 | 
   261     :add_field("delegation_chain.*")
 | 
| 
bsw@525
 | 
   262     :join("delegation_chain(" .. tostring(app.session.member.id) .. ", " .. tostring(unit_id or "NULL") .. ", " .. tostring(area_id or "NULL") .. ", " .. tostring(issue_id or "NULL") .. ")", "delegation_chain", "member.id = delegation_chain.member_id")
 | 
| 
bsw@525
 | 
   263     :add_order_by("index")
 | 
| 
bsw@525
 | 
   264     :exec()
 | 
| 
bsw@525
 | 
   265 
 | 
| 
bsw@525
 | 
   266   for i, record in ipairs(delegation_chain) do
 | 
| 
bsw@525
 | 
   267     local style
 | 
| 
bsw@525
 | 
   268     local overridden = (not issue or issue.state ~= 'voting') and record.overridden
 | 
| 
bsw@525
 | 
   269     if record.scope_in then
 | 
| 
bsw@525
 | 
   270       if not overridden then
 | 
| 
bsw@525
 | 
   271         ui.image{
 | 
| 
bsw@525
 | 
   272           attr = { class = "delegation_arrow" },
 | 
| 
bsw@525
 | 
   273           static = "delegation_arrow_24_vertical.png"
 | 
| 
bsw@525
 | 
   274         }
 | 
| 
bsw@525
 | 
   275       else
 | 
| 
bsw@525
 | 
   276         ui.image{
 | 
| 
bsw@525
 | 
   277           attr = { class = "delegation_arrow delegation_arrow_overridden" },
 | 
| 
bsw@525
 | 
   278           static = "delegation_arrow_24_vertical.png"
 | 
| 
bsw@525
 | 
   279         }
 | 
| 
bsw@525
 | 
   280       end
 | 
| 
bsw@525
 | 
   281       ui.tag{
 | 
| 
bsw@525
 | 
   282         attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
 | 
| 
bsw@525
 | 
   283         content = function()
 | 
| 
bsw@525
 | 
   284           if record.scope_in == "unit" then
 | 
| 
bsw@525
 | 
   285             slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
 | 
| 
bsw@525
 | 
   286           elseif record.scope_in == "area" then
 | 
| 
bsw@525
 | 
   287             slot.put(_"Area delegation")
 | 
| 
bsw@525
 | 
   288           elseif record.scope_in == "issue" then
 | 
| 
bsw@525
 | 
   289             slot.put(_"Issue delegation")
 | 
| 
bsw@525
 | 
   290           end
 | 
| 
bsw@525
 | 
   291         end
 | 
| 
bsw@525
 | 
   292       }
 | 
| 
bsw@525
 | 
   293     end
 | 
| 
bsw@525
 | 
   294     ui.container{
 | 
| 
bsw@525
 | 
   295       attr = { class = overridden and "delegation_overridden" or "" },
 | 
| 
bsw@525
 | 
   296       content = function()
 | 
| 
bsw@525
 | 
   297         execute.view{
 | 
| 
bsw@525
 | 
   298           module = "member",
 | 
| 
bsw@525
 | 
   299           view = "_show_thumb",
 | 
| 
bsw@525
 | 
   300           params = { member = record }
 | 
| 
bsw@525
 | 
   301         }
 | 
| 
bsw@525
 | 
   302       end
 | 
| 
bsw@525
 | 
   303     }
 | 
| 
bsw@525
 | 
   304     if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
 | 
| 
bsw@525
 | 
   305       ui.container{
 | 
| 
bsw@525
 | 
   306         attr = { class = "delegation_participation" },
 | 
| 
bsw@525
 | 
   307         content = function()
 | 
| 
bsw@525
 | 
   308           slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
 | 
| 
bsw@525
 | 
   309         end
 | 
| 
bsw@525
 | 
   310       }
 | 
| 
bsw@525
 | 
   311     end
 | 
| 
bsw@525
 | 
   312     slot.put("<br style='clear: left'/>")
 | 
| 
bsw@525
 | 
   313   end
 | 
| 
bsw@525
 | 
   314 end |