| rev | 
   line source | 
| 
bsw@525
 | 
     1 local voting_right_unit_id
 | 
| 
bsw@529
 | 
     2 local current_trustee_id
 | 
| 
bsw@529
 | 
     3 local current_trustee_name
 | 
| 
bsw@525
 | 
     4 
 | 
| 
bsw@1045
 | 
     5 local head_text
 | 
| 
bsw@1045
 | 
     6 
 | 
| 
bsw@525
 | 
     7 local unit = Unit:by_id(param.get("unit_id", atom.integer))
 | 
| 
bsw@1045
 | 
     8 local area = Area:by_id(param.get("area_id", atom.integer))
 | 
| 
bsw@1045
 | 
     9 local issue = Issue:by_id(param.get("issue_id", atom.integer))
 | 
| 
bsw@1045
 | 
    10 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
 | 
| 
bsw@1045
 | 
    11 
 | 
| 
bsw@1045
 | 
    12 if initiative then
 | 
| 
bsw@1045
 | 
    13   issue = initiative.issue
 | 
| 
bsw@1045
 | 
    14 end
 | 
| 
bsw@1045
 | 
    15 
 | 
| 
bsw@525
 | 
    16 if unit then
 | 
| 
bsw@529
 | 
    17   unit:load_delegation_info_once_for_member_id(app.session.member_id)
 | 
| 
bsw@525
 | 
    18   voting_right_unit_id = unit.id
 | 
| 
bsw@529
 | 
    19   if unit.delegation_info.own_delegation_scope == 'unit' then
 | 
| 
bsw@529
 | 
    20     current_trustee_id = unit.delegation_info.first_trustee_id
 | 
| 
bsw@529
 | 
    21     current_trustee_name = unit.delegation_info.first_trustee_name
 | 
| 
bsw@529
 | 
    22   end
 | 
| 
bsw@1045
 | 
    23   execute.view { module = "unit", view = "_head", params = { unit = unit } }
 | 
| 
bsw@1045
 | 
    24   head_text = _"Set unit delegation"
 | 
| 
bsw@525
 | 
    25 end
 | 
| 
bsw@525
 | 
    26 
 | 
| 
bsw@525
 | 
    27 if area then
 | 
| 
bsw@529
 | 
    28   area:load_delegation_info_once_for_member_id(app.session.member_id)
 | 
| 
bsw@525
 | 
    29   voting_right_unit_id = area.unit_id
 | 
| 
bsw@563
 | 
    30   if area.delegation_info.own_delegation_scope == 'area' then
 | 
| 
bsw@563
 | 
    31     current_trustee_id = area.delegation_info.first_trustee_id
 | 
| 
bsw@563
 | 
    32     current_trustee_name = area.delegation_info.first_trustee_name
 | 
| 
bsw@563
 | 
    33   end
 | 
| 
bsw@1045
 | 
    34   execute.view { module = "area", view = "_head", params = { area = area } }
 | 
| 
bsw@1045
 | 
    35   head_text = _"Set area delegation"
 | 
| 
bsw@525
 | 
    36 end
 | 
| 
bsw@525
 | 
    37 
 | 
| 
bsw@525
 | 
    38 if issue then
 | 
| 
bsw@551
 | 
    39   issue:load("member_info", { member_id = app.session.member_id })
 | 
| 
bsw@525
 | 
    40   voting_right_unit_id = issue.area.unit_id
 | 
| 
bsw@563
 | 
    41   if issue.member_info.own_delegation_scope == 'issue' then
 | 
| 
bsw@563
 | 
    42     current_trustee_id = issue.member_info.first_trustee_id
 | 
| 
bsw@563
 | 
    43     current_trustee_name = issue.member_info.first_trustee_name
 | 
| 
bsw@563
 | 
    44   end
 | 
| 
bsw@1045
 | 
    45   execute.view { module = "issue", view = "_head", params = { issue = issue } }
 | 
| 
bsw@1045
 | 
    46   head_text = _"Set issue delegation"
 | 
| 
bsw@1045
 | 
    47 end
 | 
| 
bsw@1045
 | 
    48 
 | 
| 
bsw@575
 | 
    49 local delegation
 | 
| 
bsw@575
 | 
    50 local unit_id
 | 
| 
bsw@575
 | 
    51 local area_id
 | 
| 
bsw@575
 | 
    52 local issue_id
 | 
| 
bsw@575
 | 
    53 local initiative_id
 | 
| 
bsw@575
 | 
    54 
 | 
| 
bsw@575
 | 
    55 local scope = "unit"
 | 
| 
bsw@575
 | 
    56 
 | 
| 
bsw@1045
 | 
    57 local inline = param.get("inline", atom.boolean)
 | 
| 
bsw@1045
 | 
    58 
 | 
| 
bsw@1045
 | 
    59 
 | 
| 
bsw@575
 | 
    60 unit_id = param.get("unit_id", atom.integer)
 | 
| 
bsw@575
 | 
    61 
 | 
| 
bsw@575
 | 
    62 if param.get("initiative_id", atom.integer) then
 | 
| 
bsw@1045
 | 
    63   initiative_id = initiative.id
 | 
| 
bsw@575
 | 
    64   issue_id = initiative.issue_id
 | 
| 
bsw@575
 | 
    65   scope = "issue"
 | 
| 
bsw@575
 | 
    66 end
 | 
| 
bsw@575
 | 
    67 
 | 
| 
bsw@575
 | 
    68 if param.get("issue_id", atom.integer) then
 | 
| 
bsw@575
 | 
    69   issue_id = param.get("issue_id", atom.integer)
 | 
| 
bsw@575
 | 
    70   scope = "issue"
 | 
| 
bsw@575
 | 
    71 end
 | 
| 
bsw@575
 | 
    72 
 | 
| 
bsw@575
 | 
    73 if param.get("area_id", atom.integer) then
 | 
| 
bsw@575
 | 
    74   area_id = param.get("area_id", atom.integer)
 | 
| 
bsw@575
 | 
    75   scope = "area"
 | 
| 
bsw@575
 | 
    76 end
 | 
| 
bsw@575
 | 
    77 
 | 
| 
bsw@575
 | 
    78 
 | 
| 
bsw@575
 | 
    79 
 | 
| 
bsw@575
 | 
    80 local delegation
 | 
| 
bsw@575
 | 
    81 local issue
 | 
| 
bsw@575
 | 
    82 
 | 
| 
bsw@575
 | 
    83 if issue_id then
 | 
| 
bsw@575
 | 
    84   issue = Issue:by_id(issue_id)
 | 
| 
bsw@575
 | 
    85   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
 | 
| 
bsw@575
 | 
    86   if not delegation then
 | 
| 
bsw@575
 | 
    87     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
 | 
| 
bsw@575
 | 
    88   end
 | 
| 
bsw@575
 | 
    89   if not delegation then
 | 
| 
bsw@575
 | 
    90     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
 | 
| 
bsw@575
 | 
    91   end
 | 
| 
bsw@575
 | 
    92 elseif area_id then
 | 
| 
bsw@575
 | 
    93   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
 | 
| 
bsw@575
 | 
    94   if not delegation then
 | 
| 
bsw@575
 | 
    95     local area = Area:by_id(area_id)
 | 
| 
bsw@575
 | 
    96     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
 | 
| 
bsw@575
 | 
    97   end
 | 
| 
bsw@575
 | 
    98 end
 | 
| 
bsw@575
 | 
    99 
 | 
| 
bsw@575
 | 
   100 if not delegation then
 | 
| 
bsw@575
 | 
   101   delegation = Delegation:by_pk(app.session.member.id, unit_id)
 | 
| 
bsw@575
 | 
   102 end
 | 
| 
bsw@525
 | 
   103 
 | 
| 
bsw@529
 | 
   104 local contact_members = Member:build_selector{
 | 
| 
bsw@529
 | 
   105   is_contact_of_member_id = app.session.member_id,
 | 
| 
bsw@529
 | 
   106   voting_right_for_unit_id = voting_right_unit_id,
 | 
| 
bsw@529
 | 
   107   active = true,
 | 
| 
bsw@529
 | 
   108   order = "name"
 | 
| 
bsw@529
 | 
   109 }:exec()
 | 
| 
bsw@529
 | 
   110 
 | 
| 
bsw@529
 | 
   111 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
 | 
| 
bsw@529
 | 
   112 
 | 
| 
bsw@529
 | 
   113 ui.script{ static = "js/update_delegation_info.js" }
 | 
| 
bsw@529
 | 
   114 
 | 
| 
bsw@1045
 | 
   115 
 | 
| 
bsw/jbe@1309
 | 
   116 ui.container{ attr = { class = "mdl-grid" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   117   ui.container{ attr = { class = "mdl-cell mdl-cell--8-col" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   118     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   119       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   120         ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = head_text }
 | 
| 
bsw/jbe@1309
 | 
   121       end }
 | 
| 
bsw/jbe@1309
 | 
   122 
 | 
| 
bsw/jbe@1309
 | 
   123       ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   124 
 | 
| 
bsw/jbe@1309
 | 
   125 
 | 
| 
bsw/jbe@1309
 | 
   126         ui.form{
 | 
| 
bsw/jbe@1309
 | 
   127           attr = { class = "wide section", id = "delegationForm" },
 | 
| 
bsw/jbe@1309
 | 
   128           module = "delegation",
 | 
| 
bsw/jbe@1309
 | 
   129           action = "update",
 | 
| 
bsw/jbe@1309
 | 
   130           params = {
 | 
| 
bsw/jbe@1309
 | 
   131             unit_id = unit and unit.id or nil,
 | 
| 
bsw/jbe@1309
 | 
   132             area_id = area and area.id or nil,
 | 
| 
bsw/jbe@1309
 | 
   133             issue_id = issue and issue.id or nil,
 | 
| 
bsw/jbe@1309
 | 
   134             initiative_id = initiative_id
 | 
| 
bsw/jbe@1309
 | 
   135           },
 | 
| 
bsw/jbe@1309
 | 
   136           routing = {
 | 
| 
bsw/jbe@1309
 | 
   137             default = {
 | 
| 
bsw/jbe@1309
 | 
   138               mode = "redirect",
 | 
| 
bsw/jbe@1309
 | 
   139               module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
 | 
| 
bsw/jbe@1309
 | 
   140               view = "show",
 | 
| 
bsw/jbe@1309
 | 
   141               id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
 | 
| 
bsw/jbe@1309
 | 
   142             }
 | 
| 
bsw/jbe@1309
 | 
   143           },
 | 
| 
bsw/jbe@1309
 | 
   144           content = function()
 | 
| 
bsw/jbe@1309
 | 
   145             local records
 | 
| 
bsw/jbe@1309
 | 
   146             if issue then
 | 
| 
bsw/jbe@1309
 | 
   147               local delegate_name = ""
 | 
| 
bsw/jbe@1309
 | 
   148               local scope = _"no delegation set"
 | 
| 
bsw/jbe@1309
 | 
   149               local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
 | 
| 
bsw/jbe@1309
 | 
   150               if area_delegation then
 | 
| 
bsw/jbe@1309
 | 
   151                 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
 | 
| 
bsw/jbe@1309
 | 
   152                 scope = _"area"
 | 
| 
bsw/jbe@1309
 | 
   153               else
 | 
| 
bsw/jbe@1309
 | 
   154                 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
 | 
| 
bsw/jbe@1309
 | 
   155                 if unit_delegation then
 | 
| 
bsw/jbe@1309
 | 
   156                   delegate_name = unit_delegation.trustee.name
 | 
| 
bsw/jbe@1309
 | 
   157                   scope = config.single_unit_id and _"global" or _"unit"
 | 
| 
bsw/jbe@1309
 | 
   158                 end
 | 
| 
bsw/jbe@1309
 | 
   159               end
 | 
| 
bsw/jbe@1309
 | 
   160               local text_apply
 | 
| 
bsw/jbe@1309
 | 
   161               local text_abandon
 | 
| 
bsw/jbe@1309
 | 
   162               if config.single_unit_id then
 | 
| 
bsw/jbe@1309
 | 
   163                 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   164                 text_abandon = _"Abandon unit and area delegations for this issue"
 | 
| 
bsw/jbe@1309
 | 
   165               else
 | 
| 
bsw/jbe@1309
 | 
   166                 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   167                 text_abandon = _"Abandon unit and area delegations for this issue"
 | 
| 
bsw/jbe@1309
 | 
   168               end
 | 
| 
bsw/jbe@1309
 | 
   169               
 | 
| 
bsw/jbe@1309
 | 
   170               records = {
 | 
| 
bsw/jbe@1309
 | 
   171                 { id = -1, name = text_apply },
 | 
| 
bsw/jbe@1309
 | 
   172                 { id = 0,  name = text_abandon }
 | 
| 
bsw/jbe@1309
 | 
   173               }
 | 
| 
bsw/jbe@1309
 | 
   174             elseif area then
 | 
| 
bsw/jbe@1309
 | 
   175               local delegate_name = ""
 | 
| 
bsw/jbe@1309
 | 
   176               local scope = _"no delegation set"
 | 
| 
bsw/jbe@1309
 | 
   177               local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
 | 
| 
bsw/jbe@1309
 | 
   178               if unit_delegation then
 | 
| 
bsw/jbe@1309
 | 
   179                 delegate_name = unit_delegation.trustee.name
 | 
| 
bsw/jbe@1309
 | 
   180                 scope = config.single_unit_id and _"global" or _"unit"
 | 
| 
bsw/jbe@1309
 | 
   181               end
 | 
| 
bsw/jbe@1309
 | 
   182               local text_apply
 | 
| 
bsw/jbe@1309
 | 
   183               local text_abandon
 | 
| 
bsw/jbe@1309
 | 
   184               if config.single_unit_id then
 | 
| 
bsw/jbe@1309
 | 
   185                 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   186                 text_abandon = _"Abandon global delegation for this area"
 | 
| 
bsw/jbe@1309
 | 
   187               else
 | 
| 
bsw/jbe@1309
 | 
   188                 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   189                 text_abandon = _"Abandon unit delegation for this area"
 | 
| 
bsw/jbe@1309
 | 
   190               end
 | 
| 
bsw/jbe@1309
 | 
   191               records = {
 | 
| 
bsw/jbe@1309
 | 
   192                 {
 | 
| 
bsw/jbe@1309
 | 
   193                   id = -1,
 | 
| 
bsw/jbe@1309
 | 
   194                   name = text_apply
 | 
| 
bsw/jbe@1309
 | 
   195                 },
 | 
| 
bsw/jbe@1309
 | 
   196                 {
 | 
| 
bsw/jbe@1309
 | 
   197                   id = 0,
 | 
| 
bsw/jbe@1309
 | 
   198                   name = text_abandon
 | 
| 
bsw/jbe@1309
 | 
   199                 }
 | 
| 
bsw/jbe@1309
 | 
   200               }
 | 
| 
bsw/jbe@1309
 | 
   201 
 | 
| 
bsw/jbe@1309
 | 
   202             else
 | 
| 
bsw/jbe@1309
 | 
   203               records = {
 | 
| 
bsw/jbe@1309
 | 
   204                 {
 | 
| 
bsw/jbe@1309
 | 
   205                   id = -1,
 | 
| 
bsw/jbe@1309
 | 
   206                   name = _"No delegation"
 | 
| 
bsw/jbe@1309
 | 
   207                 }
 | 
| 
bsw/jbe@1309
 | 
   208               }
 | 
| 
bsw@525
 | 
   209 
 | 
| 
bsw/jbe@1309
 | 
   210             end
 | 
| 
bsw/jbe@1309
 | 
   211             -- add current trustee
 | 
| 
bsw/jbe@1309
 | 
   212             if current_trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   213               records[#records+1] = {id="_", name= "--- " .. _"Current delegatee" .. " ---"}
 | 
| 
bsw/jbe@1309
 | 
   214               records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
 | 
| 
bsw/jbe@1309
 | 
   215             end
 | 
| 
bsw/jbe@1309
 | 
   216             -- add initiative authors
 | 
| 
bsw/jbe@1309
 | 
   217             if initiative then
 | 
| 
bsw/jbe@1309
 | 
   218               records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
 | 
| 
bsw/jbe@1309
 | 
   219               for i,record in ipairs(initiative.initiators) do
 | 
| 
bsw/jbe@1309
 | 
   220                 records[#records+1] = record.member
 | 
| 
bsw/jbe@1309
 | 
   221               end
 | 
| 
bsw/jbe@1309
 | 
   222             end
 | 
| 
bsw/jbe@1309
 | 
   223             -- add saved members
 | 
| 
bsw/jbe@1309
 | 
   224             if #contact_members > 0 then
 | 
| 
bsw/jbe@1309
 | 
   225               records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
 | 
| 
bsw/jbe@1309
 | 
   226               for i, record in ipairs(contact_members) do
 | 
| 
bsw/jbe@1309
 | 
   227                 records[#records+1] = record
 | 
| 
bsw/jbe@1309
 | 
   228               end
 | 
| 
bsw/jbe@1309
 | 
   229             end
 | 
| 
bsw/jbe@1309
 | 
   230 
 | 
| 
bsw/jbe@1309
 | 
   231             local disabled_records = {}
 | 
| 
bsw/jbe@1309
 | 
   232             disabled_records["_"] = true
 | 
| 
bsw/jbe@1309
 | 
   233             disabled_records[app.session.member_id] = true
 | 
| 
bsw/jbe@1309
 | 
   234 
 | 
| 
bsw/jbe@1309
 | 
   235             local value = current_trustee_id
 | 
| 
bsw/jbe@1309
 | 
   236             if preview_trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   237               value = preview_trustee_id
 | 
| 
bsw/jbe@1309
 | 
   238             end
 | 
| 
bsw/jbe@1309
 | 
   239             if preview_trustee_id == nil and delegation and not delegation.trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   240               value = 0
 | 
| 
bsw/jbe@1309
 | 
   241             end
 | 
| 
bsw/jbe@1309
 | 
   242 
 | 
| 
bsw/jbe@1309
 | 
   243             ui.tag{ content = _"Choose your delegatee" }
 | 
| 
bsw/jbe@1309
 | 
   244             
 | 
| 
bsw/jbe@1309
 | 
   245             ui.field.select{
 | 
| 
bsw/jbe@1309
 | 
   246               attr = { onchange = "updateDelegationInfo();" },
 | 
| 
bsw/jbe@1309
 | 
   247               name = "trustee_id",
 | 
| 
bsw/jbe@1309
 | 
   248               foreign_records = records,
 | 
| 
bsw/jbe@1309
 | 
   249               foreign_id = "id",
 | 
| 
bsw/jbe@1309
 | 
   250               foreign_name = "name",
 | 
| 
bsw/jbe@1309
 | 
   251               disabled_records = disabled_records,
 | 
| 
bsw/jbe@1309
 | 
   252               value = value
 | 
| 
bsw/jbe@1309
 | 
   253             }
 | 
| 
bsw/jbe@1309
 | 
   254             slot.put("<br />")
 | 
| 
bsw/jbe@1309
 | 
   255 
 | 
| 
bsw/jbe@1309
 | 
   256             ui.container{ content = _"You can choose only members which you have been saved as contact before." }
 | 
| 
bsw/jbe@1309
 | 
   257 
 | 
| 
bsw/jbe@1309
 | 
   258             ui.field.hidden{ name = "preview" }
 | 
| 
bsw/jbe@1309
 | 
   259             
 | 
| 
bsw/jbe@1309
 | 
   260             slot.put("<br />")
 | 
| 
bsw/jbe@1309
 | 
   261             ui.tag { tag = "input", content = "", attr = { 
 | 
| 
bsw/jbe@1309
 | 
   262               type = "submit",
 | 
| 
bsw/jbe@1309
 | 
   263               value = _"Save",
 | 
| 
bsw/jbe@1309
 | 
   264               class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
 | 
| 
bsw/jbe@1309
 | 
   265             } }
 | 
| 
bsw/jbe@1309
 | 
   266               
 | 
| 
bsw/jbe@1309
 | 
   267             slot.put("   ")
 | 
| 
bsw/jbe@1309
 | 
   268             if initiative then
 | 
| 
bsw/jbe@1309
 | 
   269               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   270                 module = "initiative",
 | 
| 
bsw/jbe@1309
 | 
   271                 view = "show",
 | 
| 
bsw/jbe@1309
 | 
   272                 id = initiative.id,
 | 
| 
bsw/jbe@1309
 | 
   273                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   274                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   275                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   276                 end,
 | 
| 
bsw/jbe@1309
 | 
   277               }
 | 
| 
bsw/jbe@1309
 | 
   278             elseif issue then
 | 
| 
bsw/jbe@1309
 | 
   279               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   280                 module = "issue",
 | 
| 
bsw/jbe@1309
 | 
   281                 view = "show",
 | 
| 
bsw/jbe@1309
 | 
   282                 id = issue.id,
 | 
| 
bsw/jbe@1309
 | 
   283                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   284                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   285                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   286                 end,
 | 
| 
bsw/jbe@1309
 | 
   287               }
 | 
| 
bsw/jbe@1309
 | 
   288             elseif area then
 | 
| 
bsw/jbe@1309
 | 
   289               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   290                 module = "index",
 | 
| 
bsw/jbe@1309
 | 
   291                 view = "index",
 | 
| 
bsw/jbe@1309
 | 
   292                 params = { unit = area.unit_id, area = area.id },
 | 
| 
bsw/jbe@1309
 | 
   293                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   294                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   295                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   296                 end,
 | 
| 
bsw/jbe@1309
 | 
   297               }
 | 
| 
bsw/jbe@1309
 | 
   298             else
 | 
| 
bsw/jbe@1309
 | 
   299               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   300                 module = "index",
 | 
| 
bsw/jbe@1309
 | 
   301                 view = "index",
 | 
| 
bsw/jbe@1309
 | 
   302                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   303                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   304                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   305                 end,
 | 
| 
bsw/jbe@1309
 | 
   306               }
 | 
| 
bsw/jbe@1309
 | 
   307             end
 | 
| 
bsw/jbe@1309
 | 
   308 
 | 
| 
bsw@1045
 | 
   309           end
 | 
| 
bsw@1045
 | 
   310         }
 | 
| 
bsw@1045
 | 
   311 
 | 
| 
bsw/jbe@1309
 | 
   312       end }
 | 
| 
bsw/jbe@1309
 | 
   313     end }
 | 
| 
bsw/jbe@1309
 | 
   314   end }
 | 
| 
bsw/jbe@1309
 | 
   315   -- ------------------------
 | 
| 
bsw@1045
 | 
   316 
 | 
| 
bsw/jbe@1309
 | 
   317   ui.container{ attr = { class = "mdl-cell mdl-cell--12-col mdl-cell--4-col-desktop" }, content = function() 
 | 
| 
bsw/jbe@1309
 | 
   318     ui.container{ attr = { class = "mdl-card mdl-shadow--2dp mdl-card__fullwidth" }, content = function()
 | 
| 
bsw@1045
 | 
   319 
 | 
| 
bsw/jbe@1309
 | 
   320       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   321         ui.container{
 | 
| 
bsw/jbe@1309
 | 
   322           attr = { class = "mdl-card__title-text" },
 | 
| 
bsw/jbe@1309
 | 
   323           content = _"Preview of delegation"
 | 
| 
bsw@1045
 | 
   324         }
 | 
| 
bsw/jbe@1309
 | 
   325       end }
 | 
| 
bsw@525
 | 
   326 
 | 
| 
bsw/jbe@1309
 | 
   327       ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   328         local preview_inherit = false
 | 
| 
bsw/jbe@1309
 | 
   329         local tmp_preview_trustee_id = preview_trustee_id
 | 
| 
bsw/jbe@1309
 | 
   330         if preview_trustee_id == -1 then
 | 
| 
bsw/jbe@1309
 | 
   331           preview_inherit = true
 | 
| 
bsw/jbe@1309
 | 
   332           tmp_preview_trustee_id = nil
 | 
| 
bsw/jbe@1309
 | 
   333         end
 | 
| 
bsw/jbe@1309
 | 
   334         local delegation_chain = Member:new_selector()
 | 
| 
bsw/jbe@1309
 | 
   335           :add_field("delegation_chain.*")
 | 
| 
bsw/jbe@1309
 | 
   336           :join({ "delegation_chain(?,?,?,?,?,?)", app.session.member.id, unit_id, area_id, issue_id, tmp_preview_trustee_id, preview_inherit }, "delegation_chain", "member.id = delegation_chain.member_id")
 | 
| 
bsw/jbe@1309
 | 
   337           :add_order_by("index")
 | 
| 
bsw/jbe@1309
 | 
   338           :exec()
 | 
| 
bsw@525
 | 
   339 
 | 
| 
bsw/jbe@1309
 | 
   340         for i, record in ipairs(delegation_chain) do
 | 
| 
bsw/jbe@1309
 | 
   341           local style
 | 
| 
bsw/jbe@1309
 | 
   342           local overridden = (not issue or issue.state ~= 'voting') and record.overridden
 | 
| 
bsw/jbe@1309
 | 
   343           ui.sidebarSection( function ()
 | 
| 
bsw/jbe@1309
 | 
   344             if record.scope_in then
 | 
| 
bsw/jbe@1309
 | 
   345               if not overridden then
 | 
| 
bsw/jbe@1309
 | 
   346                 local text = _"delegated to"
 | 
| 
bsw/jbe@1309
 | 
   347                 ui.image{
 | 
| 
bsw/jbe@1309
 | 
   348                   attr = { class = "delegation_arrow", alt = text, title = text },
 | 
| 
bsw/jbe@1309
 | 
   349                   static = "delegation_arrow_24_vertical.png"
 | 
| 
bsw/jbe@1309
 | 
   350                 }
 | 
| 
bsw/jbe@1309
 | 
   351               else
 | 
| 
bsw/jbe@1309
 | 
   352                 local text = _"delegated to"
 | 
| 
bsw/jbe@1309
 | 
   353                 ui.image{
 | 
| 
bsw/jbe@1309
 | 
   354                   attr = { class = "delegation_arrow delegation_arrow_overridden", alt = text, title = text  },
 | 
| 
bsw/jbe@1309
 | 
   355                   static = "delegation_arrow_24_vertical.png"
 | 
| 
bsw/jbe@1309
 | 
   356                 }
 | 
| 
bsw/jbe@1309
 | 
   357               end
 | 
| 
bsw/jbe@1309
 | 
   358               ui.tag{
 | 
| 
bsw/jbe@1309
 | 
   359                 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
 | 
| 
bsw/jbe@1309
 | 
   360                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   361                   if record.scope_in == "unit" then
 | 
| 
bsw/jbe@1309
 | 
   362                     slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
 | 
| 
bsw/jbe@1309
 | 
   363                   elseif record.scope_in == "area" then
 | 
| 
bsw/jbe@1309
 | 
   364                     slot.put(_"Area delegation")
 | 
| 
bsw/jbe@1309
 | 
   365                   elseif record.scope_in == "issue" then
 | 
| 
bsw/jbe@1309
 | 
   366                     slot.put(_"Issue delegation")
 | 
| 
bsw/jbe@1309
 | 
   367                   end
 | 
| 
bsw/jbe@1309
 | 
   368                 end
 | 
| 
bsw/jbe@1309
 | 
   369               }
 | 
| 
bsw/jbe@1309
 | 
   370             end
 | 
| 
bsw/jbe@1309
 | 
   371             ui.container{
 | 
| 
bsw/jbe@1309
 | 
   372               attr = { class = overridden and "delegation_overridden" or "" },
 | 
| 
bsw/jbe@1309
 | 
   373               content = function()
 | 
| 
bsw/jbe@1309
 | 
   374                 execute.view{
 | 
| 
bsw/jbe@1309
 | 
   375                   module = "member",
 | 
| 
bsw/jbe@1309
 | 
   376                   view = "_show_thumb",
 | 
| 
bsw/jbe@1309
 | 
   377                   params = { member = record }
 | 
| 
bsw/jbe@1309
 | 
   378                 }
 | 
| 
bsw/jbe@1309
 | 
   379               end
 | 
| 
bsw/jbe@1309
 | 
   380             }
 | 
| 
bsw/jbe@1309
 | 
   381             if issue and issue.state ~= 'voting' and record.participation and not record.overridden then
 | 
| 
bsw/jbe@1309
 | 
   382               ui.container{
 | 
| 
bsw/jbe@1309
 | 
   383                 attr = { class = "delegation_participation" },
 | 
| 
bsw/jbe@1309
 | 
   384                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   385                   if i == #delegation_chain then
 | 
| 
bsw/jbe@1309
 | 
   386                   ui.tag{ content = _"This member is currently participating in this issue." }
 | 
| 
bsw/jbe@1309
 | 
   387                   else
 | 
| 
bsw/jbe@1309
 | 
   388                   ui.tag{ content = _"This member is participating, the remaining delegation chain is suspended during discussing." }
 | 
| 
bsw/jbe@1309
 | 
   389                   end
 | 
| 
bsw/jbe@1309
 | 
   390                 end
 | 
| 
bsw/jbe@1309
 | 
   391               }
 | 
| 
bsw/jbe@1309
 | 
   392             end
 | 
| 
bsw/jbe@1309
 | 
   393             slot.put("<br style='clear: left'/>")
 | 
| 
bsw/jbe@1309
 | 
   394           end )
 | 
| 
bsw/jbe@1309
 | 
   395         end
 | 
| 
bsw@525
 | 
   396 
 | 
| 
bsw/jbe@1309
 | 
   397         if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   398           ui.image{
 | 
| 
bsw/jbe@1309
 | 
   399             static = "icons/16/table_go_crossed.png"
 | 
| 
bsw/jbe@1309
 | 
   400           }
 | 
| 
bsw/jbe@1309
 | 
   401           if issue_id then
 | 
| 
bsw/jbe@1309
 | 
   402             slot.put(_"Delegation turned off for issue")
 | 
| 
bsw/jbe@1309
 | 
   403           elseif area_id then
 | 
| 
bsw/jbe@1309
 | 
   404             slot.put(_"Delegation turned off for area")
 | 
| 
bsw@1045
 | 
   405           end
 | 
| 
bsw@1045
 | 
   406         end
 | 
| 
bsw/jbe@1309
 | 
   407         
 | 
| 
bsw/jbe@1309
 | 
   408       end }
 | 
| 
bsw/jbe@1309
 | 
   409       
 | 
| 
bsw/jbe@1309
 | 
   410     end }
 | 
| 
bsw/jbe@1309
 | 
   411       
 | 
| 
bsw/jbe@1309
 | 
   412   end }
 | 
| 
bsw@525
 | 
   413 
 | 
| 
bsw@1045
 | 
   414 
 | 
| 
bsw/jbe@1309
 | 
   415 end }
 |