| 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@1478
 | 
   139               module = issue and "issue" or initiative and "initiative" or "index",
 | 
| 
bsw@1478
 | 
   140               view = issue and "show" or initiative and "show" or "index",
 | 
| 
bsw@1478
 | 
   141               id = initiative and initiative.id or issue and issue.id,
 | 
| 
bsw@1478
 | 
   142               params = { area = area and area.id, unit = unit and unit.id or area and area.unit_id }
 | 
| 
bsw@1478
 | 
   143               
 | 
| 
bsw/jbe@1309
 | 
   144             }
 | 
| 
bsw/jbe@1309
 | 
   145           },
 | 
| 
bsw/jbe@1309
 | 
   146           content = function()
 | 
| 
bsw/jbe@1309
 | 
   147             local records
 | 
| 
bsw/jbe@1309
 | 
   148             if issue then
 | 
| 
bsw/jbe@1309
 | 
   149               local delegate_name = ""
 | 
| 
bsw/jbe@1309
 | 
   150               local scope = _"no delegation set"
 | 
| 
bsw/jbe@1309
 | 
   151               local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
 | 
| 
bsw/jbe@1309
 | 
   152               if area_delegation then
 | 
| 
bsw/jbe@1309
 | 
   153                 delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
 | 
| 
bsw/jbe@1309
 | 
   154                 scope = _"area"
 | 
| 
bsw/jbe@1309
 | 
   155               else
 | 
| 
bsw/jbe@1309
 | 
   156                 local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
 | 
| 
bsw/jbe@1309
 | 
   157                 if unit_delegation then
 | 
| 
bsw/jbe@1309
 | 
   158                   delegate_name = unit_delegation.trustee.name
 | 
| 
bsw/jbe@1309
 | 
   159                   scope = config.single_unit_id and _"global" or _"unit"
 | 
| 
bsw/jbe@1309
 | 
   160                 end
 | 
| 
bsw/jbe@1309
 | 
   161               end
 | 
| 
bsw/jbe@1309
 | 
   162               local text_apply
 | 
| 
bsw/jbe@1309
 | 
   163               local text_abandon
 | 
| 
bsw/jbe@1309
 | 
   164               if config.single_unit_id then
 | 
| 
bsw/jbe@1309
 | 
   165                 text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   166                 text_abandon = _"Abandon unit and area delegations for this issue"
 | 
| 
bsw/jbe@1309
 | 
   167               else
 | 
| 
bsw/jbe@1309
 | 
   168                 text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   169                 text_abandon = _"Abandon unit and area delegations for this issue"
 | 
| 
bsw/jbe@1309
 | 
   170               end
 | 
| 
bsw/jbe@1309
 | 
   171               
 | 
| 
bsw/jbe@1309
 | 
   172               records = {
 | 
| 
bsw/jbe@1309
 | 
   173                 { id = -1, name = text_apply },
 | 
| 
bsw/jbe@1309
 | 
   174                 { id = 0,  name = text_abandon }
 | 
| 
bsw/jbe@1309
 | 
   175               }
 | 
| 
bsw/jbe@1309
 | 
   176             elseif area then
 | 
| 
bsw/jbe@1309
 | 
   177               local delegate_name = ""
 | 
| 
bsw/jbe@1309
 | 
   178               local scope = _"no delegation set"
 | 
| 
bsw/jbe@1309
 | 
   179               local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
 | 
| 
bsw/jbe@1309
 | 
   180               if unit_delegation then
 | 
| 
bsw/jbe@1309
 | 
   181                 delegate_name = unit_delegation.trustee.name
 | 
| 
bsw/jbe@1309
 | 
   182                 scope = config.single_unit_id and _"global" or _"unit"
 | 
| 
bsw/jbe@1309
 | 
   183               end
 | 
| 
bsw/jbe@1309
 | 
   184               local text_apply
 | 
| 
bsw/jbe@1309
 | 
   185               local text_abandon
 | 
| 
bsw/jbe@1309
 | 
   186               if config.single_unit_id then
 | 
| 
bsw/jbe@1309
 | 
   187                 text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   188                 text_abandon = _"Abandon global delegation for this area"
 | 
| 
bsw/jbe@1309
 | 
   189               else
 | 
| 
bsw/jbe@1309
 | 
   190                 text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
 | 
| 
bsw/jbe@1309
 | 
   191                 text_abandon = _"Abandon unit delegation for this area"
 | 
| 
bsw/jbe@1309
 | 
   192               end
 | 
| 
bsw/jbe@1309
 | 
   193               records = {
 | 
| 
bsw/jbe@1309
 | 
   194                 {
 | 
| 
bsw/jbe@1309
 | 
   195                   id = -1,
 | 
| 
bsw/jbe@1309
 | 
   196                   name = text_apply
 | 
| 
bsw/jbe@1309
 | 
   197                 },
 | 
| 
bsw/jbe@1309
 | 
   198                 {
 | 
| 
bsw/jbe@1309
 | 
   199                   id = 0,
 | 
| 
bsw/jbe@1309
 | 
   200                   name = text_abandon
 | 
| 
bsw/jbe@1309
 | 
   201                 }
 | 
| 
bsw/jbe@1309
 | 
   202               }
 | 
| 
bsw/jbe@1309
 | 
   203 
 | 
| 
bsw/jbe@1309
 | 
   204             else
 | 
| 
bsw/jbe@1309
 | 
   205               records = {
 | 
| 
bsw/jbe@1309
 | 
   206                 {
 | 
| 
bsw/jbe@1309
 | 
   207                   id = -1,
 | 
| 
bsw/jbe@1309
 | 
   208                   name = _"No delegation"
 | 
| 
bsw/jbe@1309
 | 
   209                 }
 | 
| 
bsw/jbe@1309
 | 
   210               }
 | 
| 
bsw@525
 | 
   211 
 | 
| 
bsw/jbe@1309
 | 
   212             end
 | 
| 
bsw/jbe@1309
 | 
   213             -- add current trustee
 | 
| 
bsw/jbe@1309
 | 
   214             if current_trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   215               records[#records+1] = {id="_", name= "--- " .. _"Current delegatee" .. " ---"}
 | 
| 
bsw/jbe@1309
 | 
   216               records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
 | 
| 
bsw/jbe@1309
 | 
   217             end
 | 
| 
bsw/jbe@1309
 | 
   218             -- add initiative authors
 | 
| 
bsw/jbe@1309
 | 
   219             if initiative then
 | 
| 
bsw/jbe@1309
 | 
   220               records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
 | 
| 
bsw/jbe@1309
 | 
   221               for i,record in ipairs(initiative.initiators) do
 | 
| 
bsw/jbe@1309
 | 
   222                 records[#records+1] = record.member
 | 
| 
bsw/jbe@1309
 | 
   223               end
 | 
| 
bsw/jbe@1309
 | 
   224             end
 | 
| 
bsw/jbe@1309
 | 
   225             -- add saved members
 | 
| 
bsw/jbe@1309
 | 
   226             if #contact_members > 0 then
 | 
| 
bsw/jbe@1309
 | 
   227               records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
 | 
| 
bsw/jbe@1309
 | 
   228               for i, record in ipairs(contact_members) do
 | 
| 
bsw/jbe@1309
 | 
   229                 records[#records+1] = record
 | 
| 
bsw/jbe@1309
 | 
   230               end
 | 
| 
bsw/jbe@1309
 | 
   231             end
 | 
| 
bsw/jbe@1309
 | 
   232 
 | 
| 
bsw/jbe@1309
 | 
   233             local disabled_records = {}
 | 
| 
bsw/jbe@1309
 | 
   234             disabled_records["_"] = true
 | 
| 
bsw/jbe@1309
 | 
   235             disabled_records[app.session.member_id] = true
 | 
| 
bsw/jbe@1309
 | 
   236 
 | 
| 
bsw/jbe@1309
 | 
   237             local value = current_trustee_id
 | 
| 
bsw/jbe@1309
 | 
   238             if preview_trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   239               value = preview_trustee_id
 | 
| 
bsw/jbe@1309
 | 
   240             end
 | 
| 
bsw/jbe@1309
 | 
   241             if preview_trustee_id == nil and delegation and not delegation.trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   242               value = 0
 | 
| 
bsw/jbe@1309
 | 
   243             end
 | 
| 
bsw/jbe@1309
 | 
   244 
 | 
| 
bsw/jbe@1309
 | 
   245             ui.tag{ content = _"Choose your delegatee" }
 | 
| 
bsw/jbe@1309
 | 
   246             
 | 
| 
bsw/jbe@1309
 | 
   247             ui.field.select{
 | 
| 
bsw/jbe@1309
 | 
   248               attr = { onchange = "updateDelegationInfo();" },
 | 
| 
bsw/jbe@1309
 | 
   249               name = "trustee_id",
 | 
| 
bsw/jbe@1309
 | 
   250               foreign_records = records,
 | 
| 
bsw/jbe@1309
 | 
   251               foreign_id = "id",
 | 
| 
bsw/jbe@1309
 | 
   252               foreign_name = "name",
 | 
| 
bsw/jbe@1309
 | 
   253               disabled_records = disabled_records,
 | 
| 
bsw/jbe@1309
 | 
   254               value = value
 | 
| 
bsw/jbe@1309
 | 
   255             }
 | 
| 
bsw/jbe@1309
 | 
   256             slot.put("<br />")
 | 
| 
bsw/jbe@1309
 | 
   257 
 | 
| 
bsw/jbe@1309
 | 
   258             ui.container{ content = _"You can choose only members which you have been saved as contact before." }
 | 
| 
bsw/jbe@1309
 | 
   259 
 | 
| 
bsw/jbe@1309
 | 
   260             ui.field.hidden{ name = "preview" }
 | 
| 
bsw/jbe@1309
 | 
   261             
 | 
| 
bsw/jbe@1309
 | 
   262             slot.put("<br />")
 | 
| 
bsw/jbe@1309
 | 
   263             ui.tag { tag = "input", content = "", attr = { 
 | 
| 
bsw/jbe@1309
 | 
   264               type = "submit",
 | 
| 
bsw/jbe@1309
 | 
   265               value = _"Save",
 | 
| 
bsw/jbe@1309
 | 
   266               class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
 | 
| 
bsw/jbe@1309
 | 
   267             } }
 | 
| 
bsw/jbe@1309
 | 
   268               
 | 
| 
bsw/jbe@1309
 | 
   269             slot.put("   ")
 | 
| 
bsw/jbe@1309
 | 
   270             if initiative then
 | 
| 
bsw/jbe@1309
 | 
   271               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   272                 module = "initiative",
 | 
| 
bsw/jbe@1309
 | 
   273                 view = "show",
 | 
| 
bsw/jbe@1309
 | 
   274                 id = initiative.id,
 | 
| 
bsw/jbe@1309
 | 
   275                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   276                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   277                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   278                 end,
 | 
| 
bsw/jbe@1309
 | 
   279               }
 | 
| 
bsw/jbe@1309
 | 
   280             elseif issue then
 | 
| 
bsw/jbe@1309
 | 
   281               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   282                 module = "issue",
 | 
| 
bsw/jbe@1309
 | 
   283                 view = "show",
 | 
| 
bsw/jbe@1309
 | 
   284                 id = issue.id,
 | 
| 
bsw/jbe@1309
 | 
   285                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   286                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   287                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   288                 end,
 | 
| 
bsw/jbe@1309
 | 
   289               }
 | 
| 
bsw/jbe@1309
 | 
   290             elseif area then
 | 
| 
bsw/jbe@1309
 | 
   291               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   292                 module = "index",
 | 
| 
bsw/jbe@1309
 | 
   293                 view = "index",
 | 
| 
bsw/jbe@1309
 | 
   294                 params = { unit = area.unit_id, area = area.id },
 | 
| 
bsw/jbe@1309
 | 
   295                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   296                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   297                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   298                 end,
 | 
| 
bsw/jbe@1309
 | 
   299               }
 | 
| 
bsw/jbe@1309
 | 
   300             else
 | 
| 
bsw/jbe@1309
 | 
   301               ui.link{
 | 
| 
bsw/jbe@1309
 | 
   302                 module = "index",
 | 
| 
bsw/jbe@1309
 | 
   303                 view = "index",
 | 
| 
bsw/jbe@1309
 | 
   304                 attr = { class = "mdl-button mdl-js-button mdl-button--underlined" },
 | 
| 
bsw/jbe@1309
 | 
   305                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   306                     slot.put(_"Cancel")
 | 
| 
bsw/jbe@1309
 | 
   307                 end,
 | 
| 
bsw/jbe@1309
 | 
   308               }
 | 
| 
bsw/jbe@1309
 | 
   309             end
 | 
| 
bsw/jbe@1309
 | 
   310 
 | 
| 
bsw@1045
 | 
   311           end
 | 
| 
bsw@1045
 | 
   312         }
 | 
| 
bsw@1045
 | 
   313 
 | 
| 
bsw/jbe@1309
 | 
   314       end }
 | 
| 
bsw/jbe@1309
 | 
   315     end }
 | 
| 
bsw/jbe@1309
 | 
   316   end }
 | 
| 
bsw/jbe@1309
 | 
   317   -- ------------------------
 | 
| 
bsw@1045
 | 
   318 
 | 
| 
bsw/jbe@1309
 | 
   319   ui.container{ attr = { class = "mdl-cell mdl-cell--12-col mdl-cell--4-col-desktop" }, content = function() 
 | 
| 
bsw/jbe@1309
 | 
   320     ui.container{ attr = { class = "mdl-card mdl-shadow--2dp mdl-card__fullwidth" }, content = function()
 | 
| 
bsw@1045
 | 
   321 
 | 
| 
bsw/jbe@1309
 | 
   322       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   323         ui.container{
 | 
| 
bsw/jbe@1309
 | 
   324           attr = { class = "mdl-card__title-text" },
 | 
| 
bsw/jbe@1309
 | 
   325           content = _"Preview of delegation"
 | 
| 
bsw@1045
 | 
   326         }
 | 
| 
bsw/jbe@1309
 | 
   327       end }
 | 
| 
bsw@525
 | 
   328 
 | 
| 
bsw/jbe@1309
 | 
   329       ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
 | 
| 
bsw/jbe@1309
 | 
   330         local preview_inherit = false
 | 
| 
bsw/jbe@1309
 | 
   331         local tmp_preview_trustee_id = preview_trustee_id
 | 
| 
bsw/jbe@1309
 | 
   332         if preview_trustee_id == -1 then
 | 
| 
bsw/jbe@1309
 | 
   333           preview_inherit = true
 | 
| 
bsw/jbe@1309
 | 
   334           tmp_preview_trustee_id = nil
 | 
| 
bsw/jbe@1309
 | 
   335         end
 | 
| 
bsw/jbe@1309
 | 
   336         local delegation_chain = Member:new_selector()
 | 
| 
bsw/jbe@1309
 | 
   337           :add_field("delegation_chain.*")
 | 
| 
bsw/jbe@1309
 | 
   338           :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
 | 
   339           :add_order_by("index")
 | 
| 
bsw/jbe@1309
 | 
   340           :exec()
 | 
| 
bsw@525
 | 
   341 
 | 
| 
bsw/jbe@1309
 | 
   342         for i, record in ipairs(delegation_chain) do
 | 
| 
bsw/jbe@1309
 | 
   343           local style
 | 
| 
bsw/jbe@1309
 | 
   344           local overridden = (not issue or issue.state ~= 'voting') and record.overridden
 | 
| 
bsw/jbe@1309
 | 
   345           ui.sidebarSection( function ()
 | 
| 
bsw/jbe@1309
 | 
   346             if record.scope_in then
 | 
| 
bsw/jbe@1309
 | 
   347               if not overridden then
 | 
| 
bsw/jbe@1309
 | 
   348                 local text = _"delegated to"
 | 
| 
bsw/jbe@1309
 | 
   349                 ui.image{
 | 
| 
bsw/jbe@1309
 | 
   350                   attr = { class = "delegation_arrow", alt = text, title = text },
 | 
| 
bsw/jbe@1309
 | 
   351                   static = "delegation_arrow_24_vertical.png"
 | 
| 
bsw/jbe@1309
 | 
   352                 }
 | 
| 
bsw/jbe@1309
 | 
   353               else
 | 
| 
bsw/jbe@1309
 | 
   354                 local text = _"delegated to"
 | 
| 
bsw/jbe@1309
 | 
   355                 ui.image{
 | 
| 
bsw/jbe@1309
 | 
   356                   attr = { class = "delegation_arrow delegation_arrow_overridden", alt = text, title = text  },
 | 
| 
bsw/jbe@1309
 | 
   357                   static = "delegation_arrow_24_vertical.png"
 | 
| 
bsw/jbe@1309
 | 
   358                 }
 | 
| 
bsw/jbe@1309
 | 
   359               end
 | 
| 
bsw/jbe@1309
 | 
   360               ui.tag{
 | 
| 
bsw/jbe@1309
 | 
   361                 attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
 | 
| 
bsw/jbe@1309
 | 
   362                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   363                   if record.scope_in == "unit" then
 | 
| 
bsw/jbe@1309
 | 
   364                     slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
 | 
| 
bsw/jbe@1309
 | 
   365                   elseif record.scope_in == "area" then
 | 
| 
bsw/jbe@1309
 | 
   366                     slot.put(_"Area delegation")
 | 
| 
bsw/jbe@1309
 | 
   367                   elseif record.scope_in == "issue" then
 | 
| 
bsw/jbe@1309
 | 
   368                     slot.put(_"Issue delegation")
 | 
| 
bsw/jbe@1309
 | 
   369                   end
 | 
| 
bsw/jbe@1309
 | 
   370                 end
 | 
| 
bsw/jbe@1309
 | 
   371               }
 | 
| 
bsw/jbe@1309
 | 
   372             end
 | 
| 
bsw/jbe@1309
 | 
   373             ui.container{
 | 
| 
bsw/jbe@1309
 | 
   374               attr = { class = overridden and "delegation_overridden" or "" },
 | 
| 
bsw/jbe@1309
 | 
   375               content = function()
 | 
| 
bsw/jbe@1309
 | 
   376                 execute.view{
 | 
| 
bsw/jbe@1309
 | 
   377                   module = "member",
 | 
| 
bsw/jbe@1309
 | 
   378                   view = "_show_thumb",
 | 
| 
bsw/jbe@1309
 | 
   379                   params = { member = record }
 | 
| 
bsw/jbe@1309
 | 
   380                 }
 | 
| 
bsw/jbe@1309
 | 
   381               end
 | 
| 
bsw/jbe@1309
 | 
   382             }
 | 
| 
bsw/jbe@1309
 | 
   383             if issue and issue.state ~= 'voting' and record.participation and not record.overridden then
 | 
| 
bsw/jbe@1309
 | 
   384               ui.container{
 | 
| 
bsw/jbe@1309
 | 
   385                 attr = { class = "delegation_participation" },
 | 
| 
bsw/jbe@1309
 | 
   386                 content = function()
 | 
| 
bsw/jbe@1309
 | 
   387                   if i == #delegation_chain then
 | 
| 
bsw/jbe@1309
 | 
   388                   ui.tag{ content = _"This member is currently participating in this issue." }
 | 
| 
bsw/jbe@1309
 | 
   389                   else
 | 
| 
bsw/jbe@1309
 | 
   390                   ui.tag{ content = _"This member is participating, the remaining delegation chain is suspended during discussing." }
 | 
| 
bsw/jbe@1309
 | 
   391                   end
 | 
| 
bsw/jbe@1309
 | 
   392                 end
 | 
| 
bsw/jbe@1309
 | 
   393               }
 | 
| 
bsw/jbe@1309
 | 
   394             end
 | 
| 
bsw/jbe@1309
 | 
   395             slot.put("<br style='clear: left'/>")
 | 
| 
bsw/jbe@1309
 | 
   396           end )
 | 
| 
bsw/jbe@1309
 | 
   397         end
 | 
| 
bsw@525
 | 
   398 
 | 
| 
bsw/jbe@1309
 | 
   399         if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then
 | 
| 
bsw/jbe@1309
 | 
   400           ui.image{
 | 
| 
bsw/jbe@1309
 | 
   401             static = "icons/16/table_go_crossed.png"
 | 
| 
bsw/jbe@1309
 | 
   402           }
 | 
| 
bsw/jbe@1309
 | 
   403           if issue_id then
 | 
| 
bsw/jbe@1309
 | 
   404             slot.put(_"Delegation turned off for issue")
 | 
| 
bsw/jbe@1309
 | 
   405           elseif area_id then
 | 
| 
bsw/jbe@1309
 | 
   406             slot.put(_"Delegation turned off for area")
 | 
| 
bsw@1045
 | 
   407           end
 | 
| 
bsw@1045
 | 
   408         end
 | 
| 
bsw/jbe@1309
 | 
   409         
 | 
| 
bsw/jbe@1309
 | 
   410       end }
 | 
| 
bsw/jbe@1309
 | 
   411       
 | 
| 
bsw/jbe@1309
 | 
   412     end }
 | 
| 
bsw/jbe@1309
 | 
   413       
 | 
| 
bsw/jbe@1309
 | 
   414   end }
 | 
| 
bsw@525
 | 
   415 
 | 
| 
bsw@1045
 | 
   416 
 | 
| 
bsw/jbe@1309
 | 
   417 end }
 |