liquid_feedback_frontend
view app/main/delegation/_show_box.lua @ 356:7ee7ec1b10fc
Fix link to area list in navigation (single unit mode)
| author | bsw | 
|---|---|
| date | Wed Feb 29 20:31:21 2012 +0100 (2012-02-29) | 
| parents | 56c13151d0b8 | 
| children | 
 line source
     1 function change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
     2   local check_unit_id
     3   if unit_id then
     4     check_unit_id = unit_id
     5   elseif area_id then
     6     local area = Area:by_id(area_id)
     7     check_unit_id = area.unit_id
     8   else
     9     local area = Area:by_id(issue.area_id)
    10     check_unit_id = area.unit_id
    11   end
    13   if not app.session.member:has_voting_right_for_unit_id(check_unit_id) then
    14     return
    15   end
    17   local image
    18   local text
    19   if scope == "unit" and delegation and delegation.unit_id then
    20     image = { static = "icons/16/table_go.png" }
    21     text = config.single_unit_id and _"Change global delegation" or _"Change unit delegation"
    22   elseif scope == "unit" and not (delegation and delegation.unit_id) then
    23     image = { static = "icons/16/table_go.png" }
    24     text = config.single_unit_id and _"Set global delegation" or _"Set unit delegation"
    25   elseif scope == "area" and delegation and delegation.area_id then
    26     image = { static = "icons/16/table_go.png" }
    27     text = _"Change area delegation"
    28   elseif scope == "area" and not (delegation and delegation.area_id) then
    29     image = { static = "icons/16/table_go.png" }
    30     text = _"Set area delegation"
    31   elseif scope == "issue" then
    32     if delegation and delegation.issue_id then
    33       image = { static = "icons/16/table_go.png" }
    34       text = _"Change issue delegation"
    35     elseif issue.state ~= "finished" and issue.state ~= "cancelled" then
    36       image = { static = "icons/16/table_go.png" }
    37       text = _"Set issue delegation"
    38     end
    39   end
    40   ui.container{
    41     attr = {
    42       class = "change_delegation",
    43     },
    44     content = function()
    45       ui.link{
    46         image  = image,
    47         text   = text,
    48         module = "delegation",
    49         view = "new",
    50         params = {
    51           issue_id = issue and issue.id or nil,
    52           initiative_id = initiative_id or nil,
    53           area_id = area_id,
    54           unit_id = unit_id
    55         },
    56       }
    57       if delegation then
    58         ui.link{
    59           image  = { static = "icons/16/delete.png" },
    60           text   = _"Revoke",
    61           module = "delegation",
    62           action = "update",
    63           params = { issue_id = delegation.issue_id, area_id = delegation.area_id, unit_id = delegation.unit_id, delete = true },
    64           routing = {
    65             default = {
    66               mode = "redirect",
    67               module = request.get_module(),
    68               view = request.get_view(),
    69               id = param.get_id_cgi(),
    70               params = param.get_all_cgi()
    71             }
    72           }
    73         }
    74       end
    75     end
    76   }
    77 end
    79 local delegation
    80 local unit_id
    81 local area_id
    82 local issue_id
    83 local initiative_id
    85 local scope = "unit"
    87 unit_id = param.get("unit_id", atom.integer)
    89 local inline = param.get("inline", atom.boolean)
    91 if param.get("initiative_id", atom.integer) then
    92   initiative_id = param.get("initiative_id", atom.integer)
    93   issue_id = Initiative:by_id(initiative_id).issue_id
    94   scope = "issue"
    95 end
    97 if param.get("issue_id", atom.integer) then
    98   issue_id = param.get("issue_id", atom.integer)
    99   scope = "issue"
   100 end
   102 if param.get("area_id", atom.integer) then
   103   area_id = param.get("area_id", atom.integer)
   104   scope = "area"
   105 end
   109 local delegation
   110 local issue
   112 if issue_id then
   113   issue = Issue:by_id(issue_id)
   114   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
   115   if not delegation then
   116     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   117   end
   118   if not delegation then
   119     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
   120   end
   121 elseif area_id then
   122   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   123   if not delegation then
   124     local area = Area:by_id(area_id)
   125     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
   126   end
   127 end
   129 if not delegation then
   130   delegation = Delegation:by_pk(app.session.member.id, unit_id)
   131 end
   133 local slot_name = "actions"
   135 if inline then
   136   slot_name = "default"
   137 end
   139 slot.select(slot_name, function()
   141   if delegation then
   142     ui.container{
   143       attr = { class = "delegation vote_info"},
   144       content = function()
   145         ui.container{
   146           attr = {
   147             title = _"Click for details",
   148             class = "head head_active",
   149             style = "cursor: pointer;",
   150             onclick = "document.getElementById('delegation_content').style.display = 'block';"
   151           },
   152           content = function()
   153             if delegation.trustee_id then
   154               ui.image{
   155                 static = "icons/16/table_go.png"
   156               }
   157               local member = Member:new_selector()
   158                 :reset_fields()
   159                 :add_field("name", "delegation_name")
   160                 :add_where({ "id = ?", delegation.trustee_id })
   161                 :single_object_mode()
   162                 :exec()
   163               if delegation.issue_id then
   164                 slot.put( _("Issue delegated to '#{name}'", { name = member.delegation_name }) )
   165               elseif delegation.area_id then
   166                 slot.put( _("Area delegated to '#{name}'", { name = member.delegation_name }) )
   167               else
   168                 if config.single_unit_id then
   169                   slot.put( _("Global delegation set to '#{name}'", { name = member.delegation_name }) )
   170                 else
   171                   slot.put( _("Unit delegated to '#{name}'", { name = member.delegation_name }) )
   172                 end
   173               end
   175             else
   176               ui.image{
   177                 static = "icons/16/table_go_crossed.png"
   178               }
   179               if delegation.issue_id then
   180                 slot.put(_"Delegation turned off for issue")
   181               elseif delegation.area_id then
   182                 slot.put(_"Delegation turned off for area")
   183               end
   184             end
   185             ui.image{
   186               static = "icons/16/dropdown.png"
   187             }
   188           end
   189         }
   190         ui.container{
   191           attr = { class = "content", id = "delegation_content" },
   192           content = function()
   193             ui.container{
   194               attr = {
   195                 class = "close",
   196                 style = "cursor: pointer;",
   197                 onclick = "document.getElementById('delegation_content').style.display = 'none';"
   198               },
   199               content = function()
   200                 ui.image{ static = "icons/16/cross.png" }
   201               end
   202             }
   204             local delegation_chain = Member:new_selector()
   205               :add_field("delegation_chain.*")
   206               :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")
   207               :add_order_by("index")
   208               :exec()
   210             if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
   211               change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
   212               slot.put("<br style='clear: left'/>")
   213             end
   215             for i, record in ipairs(delegation_chain) do
   216               local style
   217               local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   218               if record.scope_in then
   219                 ui.container{
   220                   attr = { class = "delegation_info" },
   221                   content = function()
   222                     if not overridden then
   223                       ui.image{
   224                         attr = { class = "delegation_arrow" },
   225                         static = "delegation_arrow_24_vertical.png"
   226                       }
   227                     else
   228                       ui.image{
   229                         attr = { class = "delegation_arrow delegation_arrow_overridden" },
   230                         static = "delegation_arrow_24_vertical.png"
   231                       }
   232                     end
   233                     ui.container{
   234                       attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   235                       content = function()
   236                         if record.scope_in == "unit" then
   237                           slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   238                         elseif record.scope_in == "area" then
   239                           slot.put(_"Area delegation")
   240                         elseif record.scope_in == "issue" then
   241                           slot.put(_"Issue delegation")
   242                         end
   243                       end
   244                     }
   245                   end
   246                 }
   247               end
   248               ui.container{
   249                 attr = { class = overridden and "delegation_overridden" or "" },
   250                 content = function()
   251                   execute.view{
   252                     module = "member",
   253                     view = "_show_thumb",
   254                     params = { member = record }
   255                   }
   256                 end
   257               }
   258               if (not issue or issue.state ~= 'voting') and record.participation and not record.overridden then
   259                 ui.container{
   260                   attr = { class = "delegation_participation" },
   261                   content = function()
   262                     slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   263                   end
   264                 }
   265               end
   266               slot.put("<br style='clear: left'/>")
   267             end
   268           end
   269         }
   270       end
   271     }
   272   else
   273     change_delegation(scope, unit_id, area_id, issue, nil, initiative_id)
   274   end
   275 end)
