liquid_feedback_frontend
view app/main/issue/_show_head.lua @ 265:d37dce888225
More unit support
| author | bsw | 
|---|---|
| date | Tue Feb 07 18:40:08 2012 +0100 (2012-02-07) | 
| parents | 6725c13b6ce0 | 
| children | aab7b0c5543f | 
 line source
     1 local issue = param.get("issue", "table")
     2 local initiative = param.get("initiative", "table")
     4 local direct_voter
     6 if app.session.member_id then
     7   direct_voter = DirectVoter:by_pk(issue.id, app.session.member.id)
     8 end
    10 if config.feature_rss_enabled then
    11   util.html_rss_head{ title = _"Initiatives in this issue (last created first)", module = "initiative", view = "list_rss", params = { issue_id = issue.id } }
    12   util.html_rss_head{ title = _"Initiatives in this issue (last updated first)", module = "initiative", view = "list_rss", params = { issue_id = issue.id, order = "last_updated" } }
    13 end
    15 slot.select("path", function()
    16 end)
    18 slot.select("title", function()
    19   if not config.single_unit_id then
    20     ui.link{
    21       content = issue.area.unit.name,
    22       module = "area",
    23       view = "list",
    24       params = { unit_id = issue.area.unit_id }
    25     }
    26     slot.put(" · ")
    27   end
    28   ui.link{
    29     content = issue.area.name,
    30     module = "area",
    31     view = "show",
    32     id = issue.area.id
    33   }
    34   slot.put(" · ")
    35   ui.link{
    36     content = _("Issue ##{id}", { id = issue.id }),
    37     module = "issue",
    38     view = "show",
    39     id = issue.id
    40   }
    41   slot.put(" · ")
    42   ui.tag{
    43     tag = "span",
    44     content = issue.state_name,
    45   }
    46 end)
    49 slot.select("content_navigation", function()
    51   if app.session.member_id then
    52     local records
    53     local this = 0
    54     local issues_selector = Issue:new_selector()
    56     -- FIXME: !DRY
    57     local issue_filter_map = {
    58       new = "new.png",
    59       accepted = "comments.png",
    60       half_frozen = "lock.png",
    61       frozen ="email_open.png",
    62       finished = "tick.png",
    63       cancelled = "cross.png",
    64     }
    67     local mk_link = function(index, text, icon, module)
    68        content = function()
    69           if index > 0 then
    70             slot.put(text)
    71             ui.image{ static = "icons/16/"..icon }
    72           else
    73             ui.image{ static = "icons/16/"..icon }
    74             slot.put(text)
    75           end
    76       end
    77       if records[this+index] then
    78         ui.link{
    79           content = content,
    80           module = module,
    81           view = "show",
    82           id = records[this+index].id,
    83         }
    84       else
    85         ui.container{
    86           content = content,
    87         }
    88       end
    89     end
    91     issues_selector
    92        :add_where{"issue.area_id = ?", issue.area.id}
    94     local filters = execute.load_chunk{module="issue", chunk="_filters.lua", params = {filter = "frozen"}}
    96     local state = issue.state
    98     -- FIXME: fix filter names to reflect issue.state values
    99     if state == "voting" then
   100       state = "frozen"
   101     elseif state == "frozen" then
   102       state = "half_frozen"
   103     end
   105     filter = filters:get_filter("filter", state)
   106     if filter then
   107       filter.selector_modifier(issues_selector)
   109       -- add subfilter to voting pager, so only not voted entries will be shown
   110       -- as this seems the most usefull exception
   111       if filter.name == "frozen" then
   112         filter_voting_name = "not_voted"
   113         local vfilter = filters:get_filter("filter_voting", "not_voted")
   114         if vfilter then
   115           vfilter.selector_modifier(issues_selector)
   116         end
   117       end
   118     end
   120     records = issues_selector:exec()
   122     for i,cissue in ipairs(records) do
   123       if cissue.id == issue.id then
   124         this = i
   125         break
   126       end
   127     end
   129     mk_link(-1, _("Previous issue"), "resultset_previous.png", "issue")
   130     if issue.area then
   131       ui.link{
   132         content = function()
   133           if issue_filter_map[state] then
   134             ui.image{ static = "icons/16/"..issue_filter_map[state] }
   135           end
   136           slot.put(issue.area.name)
   137         end,
   138         module = "area",
   139         view = "show",
   140         id = issue.area.id,
   141         params = {
   142           filter = filter and filter.name or nil,
   143           filter_voting = filter_voting_name,
   144           tab = "issues"
   145         }
   146       }
   147     end
   148     mk_link(1, _("Next issue"), "resultset_next.png", "issue")
   150     -- show pager for initiatives if available
   151     if initiative then
   152       ui.container{ content = function() end, attr = {class = "content_navigation_seperator"}}
   154       records = issue:get_reference_selector("initiatives"):exec()
   155       for i,cissue in ipairs(records) do
   156         if cissue.id == initiative.id then
   157           this = i
   158           break
   159         end
   160       end
   161       mk_link(-1, _("Previous initiative"), "resultset_previous.png", "initiative")
   162       mk_link(1, _("Next initiative"), "resultset_next.png", "initiative")
   163     end
   164   end
   165 end
   167 )
   169 slot.select("actions", function()
   171   if app.session.member_id then
   173     if issue.state == 'voting' then
   174       local text
   175       if not direct_voter then
   176         text = _"Vote now"
   177       else
   178         text = _"Change vote"
   179       end
   180       ui.link{
   181         content = function()
   182           ui.image{ static = "icons/16/email_open.png" }
   183           slot.put(text)
   184         end,
   185         module = "vote",
   186         view = "list",
   187         params = { issue_id = issue.id }
   188       }
   189     end
   191     execute.view{
   192       module = "interest",
   193       view = "_show_box",
   194       params = { issue = issue }
   195     }
   197     if not issue.closed then
   198       execute.view{
   199         module = "delegation",
   200         view = "_show_box",
   201         params = { issue_id = issue.id,
   202                    initiative_id = initiative and initiative.id or nil}
   203       }
   204     end
   206   end
   208   if config.issue_discussion_url_func then
   209     local url = config.issue_discussion_url_func(issue)
   210     ui.link{
   211       attr = { target = "_blank" },
   212       external = url,
   213       content = function()
   214         ui.image{ static = "icons/16/comments.png" }
   215         slot.put(_"Discussion on issue")
   216       end,
   217     }
   218   end
   219 end)
   222 execute.view{
   223   module = "issue",
   224   view = "_show_box",
   225   params = { issue = issue }
   226 }
   228 --  ui.twitter("http://example.com/t" .. tostring(issue.id))
   230 if config.public_access_issue_head and not app.session.member_id then
   231   config.public_access_issue_head(issue)
   232 end
   234 if app.session.member_id and issue.state == 'voting' and not direct_voter then
   235   ui.container{
   236     attr = { class = "voting_active_info" },
   237     content = function()
   238       slot.put(_"Voting for this issue is currently running!")
   239       slot.put(" ")
   240       if app.session.member_id then
   241         ui.link{
   242           content = function()
   243             slot.put(_"Vote now")
   244           end,
   245           module = "vote",
   246           view = "list",
   247           params = { issue_id = issue.id }
   248         }
   249       end
   250     end
   251   }
   252   slot.put("<br />")
   253 end
