liquid_feedback_frontend
view app/main/delegation/_show_box.lua @ 125:eb6509288d67
don't show second fractions on time_left
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Mon Oct 04 14:37:13 2010 +0200 (2010-10-04) | 
| parents | bf885faf3452 | 
| children | 02aacb3dffe0 | 
 line source
     1 function change_delegation(scope, area_id, issue, delegation, initiative_id)
     2   local image
     3   local text
     4   if scope == "global" and delegation then
     5     image = { static = "icons/16/table_go.png" }
     6     text = _"Change global delegation"
     7   elseif scope == "global" and not delegation then
     8     image = { static = "icons/16/table_go.png" }
     9     text = _"Set global 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         },
    40       }
    41       if delegation then
    42         ui.link{
    43           image  = { static = "icons/16/delete.png" },
    44           text   = _"Revoke",
    45           module = "delegation",
    46           action = "update",
    47           params = { issue_id = delegation.issue_id, area_id = delegation.area_id, delete = true },
    48           routing = {
    49             default = {
    50               mode = "redirect",
    51               module = request.get_module(),
    52               view = request.get_view(),
    53               id = param.get_id_cgi(),
    54               params = param.get_all_cgi()
    55             }
    56           }
    57         }
    58       end
    59     end
    60   }
    61 end
    63 local delegation
    64 local area_id
    65 local issue_id
    66 local initiative_id
    68 local scope = "global"
    70 if param.get("initiative_id", atom.integer) then
    71   initiative_id = param.get("initiative_id", atom.integer)
    72   issue_id = Initiative:by_id(initiative_id).issue_id
    73   scope = "issue"
    74 end
    76 if param.get("issue_id", atom.integer) then
    77   issue_id = param.get("issue_id", atom.integer)
    78   scope = "issue"
    79 end
    81 if param.get("area_id", atom.integer) then
    82   area_id = param.get("area_id", atom.integer)
    83   scope = "area"
    84 end
    88 local delegation
    89 local issue
    91 if issue_id then
    92   issue = Issue:by_id(issue_id)
    93   delegation = Delegation:by_pk(app.session.member.id, nil, issue_id)
    94   if not delegation then
    95     delegation = Delegation:by_pk(app.session.member.id, issue.area_id)
    96   end
    97 elseif area_id then
    98   delegation = Delegation:by_pk(app.session.member.id, area_id)
    99 end
   101 if not delegation then
   102   delegation = Delegation:by_pk(app.session.member.id)
   103 end
   106 slot.select("actions", function()
   108   if delegation then
   109     ui.container{
   110       attr = { class = "delegation vote_info"},
   111       content = function()
   112         ui.container{
   113           attr = {
   114             title = _"Click for details",
   115             class = "head head_active",
   116             style = "cursor: pointer;",
   117             onclick = "document.getElementById('delegation_content').style.display = 'block';"
   118           },
   119           content = function()
   120             ui.image{
   121               static = "icons/16/error.png"
   122             }
   123             if delegation.issue_id then
   124               slot.put(_"Issue delegation active")
   125             elseif delegation.area_id then
   126               slot.put(_"Area wide delegation active")
   127             else
   128               slot.put(_"Global delegation active")
   129             end
   130             ui.image{
   131               static = "icons/16/dropdown.png"
   132             }
   133           end
   134         }
   135         ui.container{
   136           attr = { class = "content", id = "delegation_content" },
   137           content = function()
   138             ui.container{
   139               attr = {
   140                 class = "close",
   141                 style = "cursor: pointer;",
   142                 onclick = "document.getElementById('delegation_content').style.display = 'none';"
   143               },
   144               content = function()
   145                 ui.image{ static = "icons/16/cross.png" }
   146               end
   147             }
   149             local delegation_chain = Member:new_selector()
   150               :add_field("delegation_chain.*")
   151               :join("delegation_chain(" .. tostring(app.session.member.id) .. ", " .. tostring(area_id or "NULL") .. ", " .. tostring(issue_id or "NULL") .. ")", "delegation_chain", "member.id = delegation_chain.member_id")
   152               :add_order_by("index")
   153               :exec()
   155             if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
   156               change_delegation(scope, area_id, issue, delegation, initiative_id)
   157             end
   159             for i, record in ipairs(delegation_chain) do
   160               local style
   161               local overridden = record.overridden
   162               if record.scope_in then
   163                 ui.container{
   164                   attr = { class = "delegation_info" },
   165                   content = function()
   166                     if not overridden then
   167                       ui.image{
   168                         attr = { class = "delegation_arrow" },
   169                         static = "delegation_arrow_vertical.jpg"
   170                       }
   171                     else
   172                       ui.image{
   173                         attr = { class = "delegation_arrow delegation_arrow_overridden" },
   174                         static = "delegation_arrow_vertical.jpg"
   175                       }
   176                     end
   177                     ui.container{
   178                       attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   179                       content = function()
   180                         if record.scope_in == "global" then
   181                           slot.put(_"Global delegation")
   182                         elseif record.scope_in == "area" then
   183                           slot.put(_"Area delegation")
   184                         elseif record.scope_in == "issue" then
   185                           slot.put(_"Issue delegation")
   186                         end
   187                       end
   188                     }
   189                   end
   190                 }
   191               end
   192               ui.container{
   193                 attr = { class = overridden and "delegation_overridden" or "" },
   194                 content = function()
   195                   execute.view{
   196                     module = "member",
   197                     view = "_show_thumb",
   198                     params = { member = record }
   199                   }
   200                 end
   201               }
   202               if record.participation and not record.overridden then
   203                 ui.container{
   204                   attr = { class = "delegation_participation" },
   205                   content = function()
   206                     slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   207                   end
   208                 }
   209               end
   210               slot.put("<br style='clear: left'/>")
   211             end
   212           end
   213         }
   214       end
   215     }
   216   else
   217     change_delegation(scope, area_id, issue, nil, initiative_id)
   218   end
   219 end)
