liquid_feedback_frontend
view app/main/delegation/_show_box.lua @ 251:cb2380e08bb5
Show currently active delegation in delegation boxes
| author | Ingo Bormuth <mail@ibormuth.de> | 
|---|---|
| date | Fri Dec 30 03:59:04 2011 +0100 (2011-12-30) | 
| parents | e3613831cd1e | 
| children | 1b8d51e21614 | 
 line source
     1 function change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
     2   local image
     3   local text
     4   if scope == "unit" and delegation and delegation.unit_id then
     5     image = { static = "icons/16/table_go.png" }
     6     text = _"Change unit delegation"
     7   elseif scope == "unit" and not (delegation and delegation.unit_id) then
     8     image = { static = "icons/16/table_go.png" }
     9     text = _"Set unit delegation"
    10   elseif scope == "area" and delegation and delegation.area_id then
    11     image = { static = "icons/16/table_go.png" }
    12     text = _"Change area delegation"
    13   elseif scope == "area" and not (delegation and delegation.area_id) then
    14     image = { static = "icons/16/table_go.png" }
    15     text = _"Set area delegation"
    16   elseif scope == "issue" then
    17     if delegation and delegation.issue_id then
    18       image = { static = "icons/16/table_go.png" }
    19       text = _"Change issue delegation"
    20     elseif issue.state ~= "finished" and issue.state ~= "cancelled" then
    21       image = { static = "icons/16/table_go.png" }
    22       text = _"Set issue delegation"
    23     end
    24   end
    25   ui.container{
    26     attr = {
    27       class = "change_delegation",
    28     },
    29     content = function()
    30       ui.link{
    31         image  = image,
    32         text   = text,
    33         module = "delegation",
    34         view = "new",
    35         params = {
    36           issue_id = issue and issue.id or nil,
    37           initiative_id = initiative_id or nil,
    38           area_id = area_id,
    39           unit_id = unit_id
    40         },
    41       }
    42       if delegation then
    43         ui.link{
    44           image  = { static = "icons/16/delete.png" },
    45           text   = _"Revoke",
    46           module = "delegation",
    47           action = "update",
    48           params = { issue_id = delegation.issue_id, area_id = delegation.area_id, unit_id = delegation.unit_id, delete = true },
    49           routing = {
    50             default = {
    51               mode = "redirect",
    52               module = request.get_module(),
    53               view = request.get_view(),
    54               id = param.get_id_cgi(),
    55               params = param.get_all_cgi()
    56             }
    57           }
    58         }
    59       end
    60     end
    61   }
    62 end
    64 local delegation
    65 local unit_id
    66 local area_id
    67 local issue_id
    68 local initiative_id
    70 local scope = "unit"
    72 unit_id = param.get("unit_id", atom.integer)
    74 if param.get("initiative_id", atom.integer) then
    75   initiative_id = param.get("initiative_id", atom.integer)
    76   issue_id = Initiative:by_id(initiative_id).issue_id
    77   scope = "issue"
    78 end
    80 if param.get("issue_id", atom.integer) then
    81   issue_id = param.get("issue_id", atom.integer)
    82   scope = "issue"
    83 end
    85 if param.get("area_id", atom.integer) then
    86   area_id = param.get("area_id", atom.integer)
    87   scope = "area"
    88 end
    92 local delegation
    93 local issue
    95 if issue_id then
    96   issue = Issue:by_id(issue_id)
    97   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
    98   if not delegation then
    99     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   100   end
   101 elseif area_id then
   102   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   103 end
   105 if not delegation then
   106   delegation = Delegation:by_pk(app.session.member.id, unit_id)
   107 end
   110 slot.select("actions", function()
   112   if delegation then
   113     ui.container{
   114       attr = { class = "delegation vote_info"},
   115       content = function()
   116         ui.container{
   117           attr = {
   118             title = _"Click for details",
   119             class = "head head_active",
   120             style = "cursor: pointer;",
   121             onclick = "document.getElementById('delegation_content').style.display = 'block';"
   122           },
   123           content = function()
   124             if delegation.trustee_id then
   125               ui.image{
   126                 static = "icons/16/table_go.png"
   127               }
   128               local member = Member:new_selector()
   129                 :reset_fields()
   130                 :add_field("name", "delegation_name")
   131                 :add_where({ "id = ?", delegation.trustee_id })
   132                 :single_object_mode()
   133                 :exec()
   134               if delegation.issue_id then
   135                 slot.put( _("Issue delegated to '#{name}'", { name = member.delegation_name }) )
   136               elseif delegation.area_id then
   137                 slot.put( _("Area delegated to '#{name}'", { name = member.delegation_name }) )
   138               else
   139                 slot.put( _("Unit delegated to '#{name}'", { name = member.delegation_name }) )
   140               end
   142             else
   143               ui.image{
   144                 static = "icons/16/table_go_crossed.png"
   145               }
   146               if delegation.issue_id then
   147                 slot.put(_"Delegation turned off for issue")
   148               elseif delegation.area_id then
   149                 slot.put(_"Delegation turned off for area")
   150               end
   151             end
   152             ui.image{
   153               static = "icons/16/dropdown.png"
   154             }
   155           end
   156         }
   157         ui.container{
   158           attr = { class = "content", id = "delegation_content" },
   159           content = function()
   160             ui.container{
   161               attr = {
   162                 class = "close",
   163                 style = "cursor: pointer;",
   164                 onclick = "document.getElementById('delegation_content').style.display = 'none';"
   165               },
   166               content = function()
   167                 ui.image{ static = "icons/16/cross.png" }
   168               end
   169             }
   171             local delegation_chain = Member:new_selector()
   172               :add_field("delegation_chain.*")
   173               :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")
   174               :add_order_by("index")
   175               :exec()
   177             if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
   178               change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
   179             end
   181             for i, record in ipairs(delegation_chain) do
   182               local style
   183               local overridden = record.overridden
   184               if record.scope_in then
   185                 ui.container{
   186                   attr = { class = "delegation_info" },
   187                   content = function()
   188                     if not overridden then
   189                       ui.image{
   190                         attr = { class = "delegation_arrow" },
   191                         static = "delegation_arrow_vertical.jpg"
   192                       }
   193                     else
   194                       ui.image{
   195                         attr = { class = "delegation_arrow delegation_arrow_overridden" },
   196                         static = "delegation_arrow_vertical.jpg"
   197                       }
   198                     end
   199                     ui.container{
   200                       attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   201                       content = function()
   202                         if record.scope_in == "unit" then
   203                           slot.put(_"Unit delegation")
   204                         elseif record.scope_in == "area" then
   205                           slot.put(_"Area delegation")
   206                         elseif record.scope_in == "issue" then
   207                           slot.put(_"Issue delegation")
   208                         end
   209                       end
   210                     }
   211                   end
   212                 }
   213               end
   214               ui.container{
   215                 attr = { class = overridden and "delegation_overridden" or "" },
   216                 content = function()
   217                   execute.view{
   218                     module = "member",
   219                     view = "_show_thumb",
   220                     params = { member = record }
   221                   }
   222                 end
   223               }
   224               if record.participation and not record.overridden then
   225                 ui.container{
   226                   attr = { class = "delegation_participation" },
   227                   content = function()
   228                     slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   229                   end
   230                 }
   231               end
   232               slot.put("<br style='clear: left'/>")
   233             end
   234           end
   235         }
   236       end
   237     }
   238   else
   239     change_delegation(scope, unit_id, area_id, issue, nil, initiative_id)
   240   end
   241 end)
