liquid_feedback_frontend
view app/main/delegation/_show_box.lua @ 273:7196685f9dd7
More optical enhancements, more repositioning
| author | bsw | 
|---|---|
| date | Wed Feb 08 18:49:22 2012 +0100 (2012-02-08) | 
| parents | 1b8d51e21614 | 
| children | bde068b37608 | 
 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 = config.single_unit_id and _"Change global delegation" or _"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 = config.single_unit_id and _"Set global delegation" or _"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 local inline = param.get("inline", atom.boolean)
    76 if param.get("initiative_id", atom.integer) then
    77   initiative_id = param.get("initiative_id", atom.integer)
    78   issue_id = Initiative:by_id(initiative_id).issue_id
    79   scope = "issue"
    80 end
    82 if param.get("issue_id", atom.integer) then
    83   issue_id = param.get("issue_id", atom.integer)
    84   scope = "issue"
    85 end
    87 if param.get("area_id", atom.integer) then
    88   area_id = param.get("area_id", atom.integer)
    89   scope = "area"
    90 end
    94 local delegation
    95 local issue
    97 if issue_id then
    98   issue = Issue:by_id(issue_id)
    99   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
   100   if not delegation then
   101     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
   102   end
   103   if not delegation then
   104     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
   105   end
   106 elseif area_id then
   107   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
   108   if not delegation then
   109     local area = Area:by_id(area_id)
   110     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
   111   end
   112 end
   114 if not delegation then
   115   delegation = Delegation:by_pk(app.session.member.id, unit_id)
   116 end
   118 local slot_name = "actions"
   120 if inline then
   121   slot_name = "default"
   122 end
   124 slot.select(slot_name, function()
   126   if delegation then
   127     ui.container{
   128       attr = { class = "delegation vote_info"},
   129       content = function()
   130         ui.container{
   131           attr = {
   132             title = _"Click for details",
   133             class = "head head_active",
   134             style = "cursor: pointer;",
   135             onclick = "document.getElementById('delegation_content').style.display = 'block';"
   136           },
   137           content = function()
   138             if delegation.trustee_id then
   139               ui.image{
   140                 static = "icons/16/table_go.png"
   141               }
   142               local member = Member:new_selector()
   143                 :reset_fields()
   144                 :add_field("name", "delegation_name")
   145                 :add_where({ "id = ?", delegation.trustee_id })
   146                 :single_object_mode()
   147                 :exec()
   148               if delegation.issue_id then
   149                 slot.put( _("Issue delegated to '#{name}'", { name = member.delegation_name }) )
   150               elseif delegation.area_id then
   151                 slot.put( _("Area delegated to '#{name}'", { name = member.delegation_name }) )
   152               else
   153                 if config.single_unit_id then
   154                   slot.put( _("Global delegation set to '#{name}'", { name = member.delegation_name }) )
   155                 else
   156                   slot.put( _("Unit delegated to '#{name}'", { name = member.delegation_name }) )
   157                 end
   158               end
   160             else
   161               ui.image{
   162                 static = "icons/16/table_go_crossed.png"
   163               }
   164               if delegation.issue_id then
   165                 slot.put(_"Delegation turned off for issue")
   166               elseif delegation.area_id then
   167                 slot.put(_"Delegation turned off for area")
   168               end
   169             end
   170             ui.image{
   171               static = "icons/16/dropdown.png"
   172             }
   173           end
   174         }
   175         ui.container{
   176           attr = { class = "content", id = "delegation_content" },
   177           content = function()
   178             ui.container{
   179               attr = {
   180                 class = "close",
   181                 style = "cursor: pointer;",
   182                 onclick = "document.getElementById('delegation_content').style.display = 'none';"
   183               },
   184               content = function()
   185                 ui.image{ static = "icons/16/cross.png" }
   186               end
   187             }
   189             local delegation_chain = Member:new_selector()
   190               :add_field("delegation_chain.*")
   191               :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")
   192               :add_order_by("index")
   193               :exec()
   195             if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then
   196               change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id)
   197             end
   199             for i, record in ipairs(delegation_chain) do
   200               local style
   201               local overridden = record.overridden
   202               if record.scope_in then
   203                 ui.container{
   204                   attr = { class = "delegation_info" },
   205                   content = function()
   206                     if not overridden then
   207                       ui.image{
   208                         attr = { class = "delegation_arrow" },
   209                         static = "delegation_arrow_vertical.jpg"
   210                       }
   211                     else
   212                       ui.image{
   213                         attr = { class = "delegation_arrow delegation_arrow_overridden" },
   214                         static = "delegation_arrow_vertical.jpg"
   215                       }
   216                     end
   217                     ui.container{
   218                       attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   219                       content = function()
   220                         if record.scope_in == "unit" then
   221                           slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   222                         elseif record.scope_in == "area" then
   223                           slot.put(_"Area delegation")
   224                         elseif record.scope_in == "issue" then
   225                           slot.put(_"Issue delegation")
   226                         end
   227                       end
   228                     }
   229                   end
   230                 }
   231               end
   232               ui.container{
   233                 attr = { class = overridden and "delegation_overridden" or "" },
   234                 content = function()
   235                   execute.view{
   236                     module = "member",
   237                     view = "_show_thumb",
   238                     params = { member = record }
   239                   }
   240                 end
   241               }
   242               if record.participation and not record.overridden then
   243                 ui.container{
   244                   attr = { class = "delegation_participation" },
   245                   content = function()
   246                     slot.put(_"This member is participating, the rest of delegation chain is suspended while discussing")
   247                   end
   248                 }
   249               end
   250               slot.put("<br style='clear: left'/>")
   251             end
   252           end
   253         }
   254       end
   255     }
   256   else
   257     change_delegation(scope, unit_id, area_id, issue, nil, initiative_id)
   258   end
   259 end)
