liquid_feedback_frontend
view app/main/delegation/show.lua @ 1256:0455f101565c
Fix syntax error
| author | bsw | 
|---|---|
| date | Sun Apr 17 16:48:07 2016 +0200 (2016-04-17) | 
| parents | 904f6807f7fa | 
| children | 32cc544d5a5b | 
 line source
     1 local voting_right_unit_id
     2 local current_trustee_id
     3 local current_trustee_name
     5 local head_text
     7 local unit = Unit:by_id(param.get("unit_id", atom.integer))
     8 local area = Area:by_id(param.get("area_id", atom.integer))
     9 local issue = Issue:by_id(param.get("issue_id", atom.integer))
    10 local initiative = Initiative:by_id(param.get("initiative_id", atom.integer))
    12 if initiative then
    13   issue = initiative.issue
    14 end
    16 if unit then
    17   unit:load_delegation_info_once_for_member_id(app.session.member_id)
    18   voting_right_unit_id = unit.id
    19   if unit.delegation_info.own_delegation_scope == 'unit' then
    20     current_trustee_id = unit.delegation_info.first_trustee_id
    21     current_trustee_name = unit.delegation_info.first_trustee_name
    22   end
    23   execute.view { module = "unit", view = "_head", params = { unit = unit } }
    24   head_text = _"Set unit delegation"
    25 end
    27 if area then
    28   area:load_delegation_info_once_for_member_id(app.session.member_id)
    29   voting_right_unit_id = area.unit_id
    30   if area.delegation_info.own_delegation_scope == 'area' then
    31     current_trustee_id = area.delegation_info.first_trustee_id
    32     current_trustee_name = area.delegation_info.first_trustee_name
    33   end
    34   execute.view { module = "area", view = "_head", params = { area = area } }
    35   head_text = _"Set area delegation"
    36 end
    38 if issue then
    39   issue:load("member_info", { member_id = app.session.member_id })
    40   voting_right_unit_id = issue.area.unit_id
    41   if issue.member_info.own_delegation_scope == 'issue' then
    42     current_trustee_id = issue.member_info.first_trustee_id
    43     current_trustee_name = issue.member_info.first_trustee_name
    44   end
    45   execute.view { module = "issue", view = "_head", params = { issue = issue } }
    46   head_text = _"Set issue delegation"
    47 end
    49 local delegation
    50 local unit_id
    51 local area_id
    52 local issue_id
    53 local initiative_id
    55 local scope = "unit"
    57 local inline = param.get("inline", atom.boolean)
    60 unit_id = param.get("unit_id", atom.integer)
    62 if param.get("initiative_id", atom.integer) then
    63   initiative_id = initiative.id
    64   issue_id = initiative.issue_id
    65   scope = "issue"
    66 end
    68 if param.get("issue_id", atom.integer) then
    69   issue_id = param.get("issue_id", atom.integer)
    70   scope = "issue"
    71 end
    73 if param.get("area_id", atom.integer) then
    74   area_id = param.get("area_id", atom.integer)
    75   scope = "area"
    76 end
    80 local delegation
    81 local issue
    83 if issue_id then
    84   issue = Issue:by_id(issue_id)
    85   delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id)
    86   if not delegation then
    87     delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id)
    88   end
    89   if not delegation then
    90     delegation = Delegation:by_pk(app.session.member.id, issue.area.unit_id)
    91   end
    92 elseif area_id then
    93   delegation = Delegation:by_pk(app.session.member.id, nil, area_id)
    94   if not delegation then
    95     local area = Area:by_id(area_id)
    96     delegation = Delegation:by_pk(app.session.member.id, area.unit_id)
    97   end
    98 end
   100 if not delegation then
   101   delegation = Delegation:by_pk(app.session.member.id, unit_id)
   102 end
   104 local contact_members = Member:build_selector{
   105   is_contact_of_member_id = app.session.member_id,
   106   voting_right_for_unit_id = voting_right_unit_id,
   107   active = true,
   108   order = "name"
   109 }:exec()
   111 local preview_trustee_id = param.get("preview_trustee_id", atom.integer)
   113 ui.script{ static = "js/update_delegation_info.js" }
   116 ui.section( function () 
   118   ui.sectionHead( function ()
   119     ui.heading{ level = 1, content = head_text }
   120   end )
   122   ui.sectionRow( function ()
   124   ui.form{
   125     attr = { class = "wide section", id = "delegationForm" },
   126     module = "delegation",
   127     action = "update",
   128     params = {
   129       unit_id = unit and unit.id or nil,
   130       area_id = area and area.id or nil,
   131       issue_id = issue and issue.id or nil,
   132       initiative_id = initiative_id
   133     },
   134     routing = {
   135       default = {
   136         mode = "redirect",
   137         module = area and "area" or initiative and "initiative" or issue and "issue" or "unit",
   138         view = "show",
   139         id = area and area.id or initiative and initiative.id or issue and issue.id or unit.id,
   140       }
   141     },
   142     content = function()
   143       local records
   144       if issue then
   145         local delegate_name = ""
   146         local scope = _"no delegation set"
   147         local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id)
   148         if area_delegation then
   149           delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned"
   150           scope = _"area"
   151         else
   152           local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
   153           if unit_delegation then
   154             delegate_name = unit_delegation.trustee.name
   155             scope = config.single_unit_id and _"global" or _"unit"
   156           end
   157         end
   158         local text_apply
   159         local text_abandon
   160         if config.single_unit_id then
   161           text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   162           text_abandon = _"Abandon unit and area delegations for this issue"
   163         else
   164           text_apply = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   165           text_abandon = _"Abandon unit and area delegations for this issue"
   166         end
   168         records = {
   169           { id = -1, name = text_apply },
   170           { id = 0,  name = text_abandon }
   171         }
   172       elseif area then
   173         local delegate_name = ""
   174         local scope = _"no delegation set"
   175         local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
   176         if unit_delegation then
   177           delegate_name = unit_delegation.trustee.name
   178           scope = config.single_unit_id and _"global" or _"unit"
   179         end
   180         local text_apply
   181         local text_abandon
   182         if config.single_unit_id then
   183           text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   184           text_abandon = _"Abandon global delegation for this area"
   185         else
   186           text_apply = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
   187           text_abandon = _"Abandon unit delegation for this area"
   188         end
   189         records = {
   190           {
   191             id = -1,
   192             name = text_apply
   193           },
   194           {
   195             id = 0,
   196             name = text_abandon
   197           }
   198         }
   200       else
   201         records = {
   202           {
   203             id = -1,
   204             name = _"No delegation"
   205           }
   206         }
   208       end
   209       -- add current trustee
   210       if current_trustee_id then
   211         records[#records+1] = {id="_", name= "--- " .. _"Current delegatee" .. " ---"}
   212         records[#records+1] = { id = current_trustee_id, name = current_trustee_name }
   213       end
   214       -- add initiative authors
   215       if initiative then
   216         records[#records+1] = {id="_", name= "--- " .. _"Initiators" .. " ---"}
   217         for i,record in ipairs(initiative.initiators) do
   218           records[#records+1] = record.member
   219         end
   220       end
   221       -- add saved members
   222       if #contact_members > 0 then
   223         records[#records+1] = {id="_", name= "--- " .. _"Saved contacts" .. " ---"}
   224         for i, record in ipairs(contact_members) do
   225           records[#records+1] = record
   226         end
   227       end
   229       local disabled_records = {}
   230       disabled_records["_"] = true
   231       disabled_records[app.session.member_id] = true
   233       local value = current_trustee_id
   234       if preview_trustee_id then
   235         value = preview_trustee_id
   236       end
   237       if preview_trustee_id == nil and delegation and not delegation.trustee_id then
   238         value = 0
   239       end
   241       ui.heading{ level = 2, content = _"Choose your delegatee" }
   243       ui.field.select{
   244         attr = { onchange = "updateDelegationInfo();" },
   245         name = "trustee_id",
   246         foreign_records = records,
   247         foreign_id = "id",
   248         foreign_name = "name",
   249         disabled_records = disabled_records,
   250         value = value
   251       }
   253       ui.container{ content = _"You can choose only members which you have been saved as contact before." }
   255       ui.field.hidden{ name = "preview" }
   257       slot.put("<br />")
   258       ui.tag { tag = "input", content = "", attr = { 
   259         type = "submit",
   260         value = _"Save",
   261         class = "btn btn-default",
   262       } }
   264       slot.put("<br /><br /><br />")
   265       if initiative then
   266         ui.link{
   267           module = "initiative",
   268           view = "show",
   269           id = initiative.id,
   270           content = function()
   271               slot.put(_"Cancel")
   272           end,
   273         }
   274       elseif issue then
   275         ui.link{
   276           module = "issue",
   277           view = "show",
   278           id = issue.id,
   279           content = function()
   280               slot.put(_"Cancel")
   281           end,
   282         }
   283       elseif area then
   284         ui.link{
   285           module = "area",
   286           view = "show",
   287           id = area.id,
   288           content = function()
   289               slot.put(_"Cancel")
   290           end,
   291         }
   292       else
   293         ui.link{
   294           module = "index",
   295           view = "index",
   296           content = function()
   297               slot.put(_"Cancel")
   298           end,
   299         }
   300       end
   302     end
   303   }
   305 end ) end )
   306 -- ------------------------
   308 ui.sidebar( "tab-members", function () 
   310 ui.sidebarHead( function ()
   311   ui.heading { level = 1, content = _"Preview of delegation" }
   312 end )
   314 local preview_inherit = false
   315 local tmp_preview_trustee_id = preview_trustee_id
   316 if preview_trustee_id == -1 then
   317   preview_inherit = true
   318   tmp_preview_trustee_id = nil
   319 end
   320 local delegation_chain = Member:new_selector()
   321   :add_field("delegation_chain.*")
   322   :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")
   323   :add_order_by("index")
   324   :exec()
   326 for i, record in ipairs(delegation_chain) do
   327   local style
   328   local overridden = (not issue or issue.state ~= 'voting') and record.overridden
   329   ui.sidebarSection( function ()
   330     if record.scope_in then
   331       if not overridden then
   332         local text = _"delegated to"
   333         ui.image{
   334           attr = { class = "delegation_arrow", alt = text, title = text },
   335           static = "delegation_arrow_24_vertical.png"
   336         }
   337       else
   338         local text = _"delegated to"
   339         ui.image{
   340           attr = { class = "delegation_arrow delegation_arrow_overridden", alt = text, title = text  },
   341           static = "delegation_arrow_24_vertical.png"
   342         }
   343       end
   344       ui.tag{
   345         attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") },
   346         content = function()
   347           if record.scope_in == "unit" then
   348             slot.put(config.single_object_mode and _"Global delegation" or _"Unit delegation")
   349           elseif record.scope_in == "area" then
   350             slot.put(_"Area delegation")
   351           elseif record.scope_in == "issue" then
   352             slot.put(_"Issue delegation")
   353           end
   354         end
   355       }
   356     end
   357     ui.container{
   358       attr = { class = overridden and "delegation_overridden" or "" },
   359       content = function()
   360         execute.view{
   361           module = "member",
   362           view = "_show_thumb",
   363           params = { member = record }
   364         }
   365       end
   366     }
   367     if issue and issue.state ~= 'voting' and record.participation and not record.overridden then
   368       ui.container{
   369         attr = { class = "delegation_participation" },
   370         content = function()
   371           if i == #delegation_chain then
   372           ui.tag{ content = _"This member is currently participating in this issue." }
   373           else
   374           ui.tag{ content = _"This member is participating, the remaining delegation chain is suspended during discussing." }
   375           end
   376         end
   377       }
   378     end
   379     slot.put("<br style='clear: left'/>")
   380   end )
   381 end
   383 if preview_trustee_id == 0 or not preview_trustee_id == null and delegation and not delegation.trustee_id then
   384   ui.image{
   385     static = "icons/16/table_go_crossed.png"
   386   }
   387   if issue_id then
   388     slot.put(_"Delegation turned off for issue")
   389   elseif area_id then
   390     slot.put(_"Delegation turned off for area")
   391   end
   392 end
   395 end )
