liquid_feedback_frontend

diff app/main/vote/list.lua @ 879:ea3d3757ddc3

Added support for voting comments
author bsw
date Mon Aug 20 01:00:09 2012 +0200 (2012-08-20)
parents c4144daf6906
children fe39c1fb541b
line diff
     1.1 --- a/app/main/vote/list.lua	Sat Aug 18 23:22:20 2012 +0200
     1.2 +++ b/app/main/vote/list.lua	Mon Aug 20 01:00:09 2012 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  local member_id = param.get("member_id", atom.integer)
     1.5  local member
     1.6  
     1.7 -local readonly = false
     1.8 +local preview = param.get("preview") or param.get("preview2") == "1" and true or false
     1.9  
    1.10  if member_id then
    1.11    if not issue.closed then
    1.12 @@ -15,15 +15,21 @@
    1.13  
    1.14  if issue.closed then
    1.15    if not member then
    1.16 -    slot.put_into("error", _"This issue is already closed.")
    1.17 -  end
    1.18 -  if not member then
    1.19      member = app.session.member
    1.20    end
    1.21    readonly = true
    1.22  end
    1.23  
    1.24 +local submit_button_text = _"Finish voting"
    1.25 +
    1.26 +if issue.closed then
    1.27 +  submit_button_text = _"Update voting comment"
    1.28 +end
    1.29 +
    1.30 +local direct_voter
    1.31 +
    1.32  if member then
    1.33 +  direct_voter = DirectVoter:by_pk(issue.id, member.id)
    1.34    local str = _("Ballot of '#{member_name}' for issue ##{issue_id}",
    1.35                    {member_name = string.format('<a href="%s">%s</a>',
    1.36                                            encode.url{
    1.37 @@ -44,6 +50,9 @@
    1.38    ui.title(str)
    1.39  else
    1.40    member = app.session.member
    1.41 +
    1.42 +  direct_voter = DirectVoter:by_pk(issue.id, member.id)
    1.43 +
    1.44    ui.title(_"Voting")
    1.45  
    1.46    ui.actions(function()
    1.47 @@ -53,28 +62,31 @@
    1.48        view = "show",
    1.49        id = issue.id
    1.50      }
    1.51 -    slot.put(" &middot; ")
    1.52 -    ui.link{
    1.53 -      text = _"Discard voting",
    1.54 -      module = "vote",
    1.55 -      action = "update",
    1.56 -      params = {
    1.57 -        issue_id = issue.id,
    1.58 -        discard = true
    1.59 -      },
    1.60 -      routing = {
    1.61 -        default = {
    1.62 -          mode = "redirect",
    1.63 -          module = "issue",
    1.64 -          view = "show",
    1.65 -          id = issue.id
    1.66 +    if direct_voter then
    1.67 +      slot.put(" &middot; ")
    1.68 +      ui.link{
    1.69 +        text = _"Discard voting",
    1.70 +        module = "vote",
    1.71 +        action = "update",
    1.72 +        params = {
    1.73 +          issue_id = issue.id,
    1.74 +          discard = true
    1.75 +        },
    1.76 +        routing = {
    1.77 +          default = {
    1.78 +            mode = "redirect",
    1.79 +            module = "issue",
    1.80 +            view = "show",
    1.81 +            id = issue.id
    1.82 +          }
    1.83          }
    1.84        }
    1.85 -    }
    1.86 +    end
    1.87    end)
    1.88  end
    1.89  
    1.90  
    1.91 +
    1.92  local tempvoting_string = param.get("scoring")
    1.93  
    1.94  local tempvotings = {}
    1.95 @@ -167,6 +179,7 @@
    1.96  }
    1.97  
    1.98  ui.form{
    1.99 +  record = direct_voter,
   1.100    attr = {
   1.101      id = "voting_form",
   1.102      class = readonly and "voting_form_readonly" or "voting_form_active"
   1.103 @@ -174,16 +187,8 @@
   1.104    module = "vote",
   1.105    action = "update",
   1.106    params = { issue_id = issue.id },
   1.107 -  routing = {
   1.108 -    default = {
   1.109 -      mode = "redirect",
   1.110 -      module = "issue",
   1.111 -      view = "show",
   1.112 -      id = issue.id
   1.113 -    }
   1.114 -  },
   1.115    content = function()
   1.116 -    if not readonly then
   1.117 +    if not readonly or preview then
   1.118        local scoring = param.get("scoring")
   1.119        if not scoring then
   1.120          for i, initiative in ipairs(initiatives) do
   1.121 @@ -210,8 +215,8 @@
   1.122          tag = "input",
   1.123          attr = {
   1.124            type = "submit",
   1.125 -          class = "voting_done",
   1.126 -          value = _"Finish voting"
   1.127 +          class = "voting_done1",
   1.128 +          value = submit_button_text
   1.129          }
   1.130        }
   1.131      end
   1.132 @@ -423,15 +428,62 @@
   1.133          end
   1.134        end
   1.135      }
   1.136 -    if not readonly then
   1.137 -      ui.tag{
   1.138 -        tag = "input",
   1.139 -        attr = {
   1.140 -          type = "submit",
   1.141 -          class = "voting_done",
   1.142 -          value = _"Finish voting"
   1.143 +    if app.session.member_id and preview then
   1.144 +      local formatting_engine = param.get("formatting_engine")
   1.145 +      local comment = param.get("comment")
   1.146 +      local rendered_comment = format.wiki_text(comment, formatting_engine)
   1.147 +      slot.put(rendered_comment)
   1.148 +    end
   1.149 +    if (readonly or direct_voter.comment) and not preview then
   1.150 +      ui.heading{ level = "2", content = _("Voting comment (last updated: #{timestamp})", { timestamp = format.timestamp(direct_voter.comment_changed) }) }
   1.151 +      if direct_voter.comment then
   1.152 +        local rendered_comment = direct_voter:get_content('html')
   1.153 +        ui.container{ attr = { class = "member_statement" }, content = function()
   1.154 +          slot.put(rendered_comment)
   1.155 +        end }
   1.156 +        slot.put("<br />")
   1.157 +      end
   1.158 +    end
   1.159 +    if app.session.member_id and app.session.member_id == member.id then
   1.160 +      if not readonly or direct_voter then
   1.161 +        ui.field.hidden{ name = "update_comment", value = param.get("update_comment") or issue.closed and "1" }
   1.162 +        ui.field.select{
   1.163 +          label = _"Wiki engine for statement",
   1.164 +          name = "formatting_engine",
   1.165 +          foreign_records = {
   1.166 +            { id = "rocketwiki", name = "RocketWiki" },
   1.167 +            { id = "compat", name = _"Traditional wiki syntax" }
   1.168 +          },
   1.169 +          attr = {id = "formatting_engine"},
   1.170 +          foreign_id = "id",
   1.171 +          foreign_name = "name",
   1.172 +          value = param.get("formatting_engine") or direct_voter and direct_voter.formatting_engine
   1.173          }
   1.174 -      }
   1.175 +        ui.field.text{
   1.176 +          label = _"Voting comment (optional)",
   1.177 +          name = "comment",
   1.178 +          multiline = true,
   1.179 +          value = param.get("comment") or direct_voter and direct_voter.comment,
   1.180 +          attr = { style = "height: 20ex;" },
   1.181 +        }
   1.182 +        ui.field.hidden{ name = "preview2", attr = { id = "preview2" }, value = "0" }
   1.183 +        ui.submit{
   1.184 +          name = "preview",
   1.185 +          value = _"Preview voting comment",
   1.186 +          attr = { class = "preview" }
   1.187 +        }
   1.188 +      end
   1.189 +      if not readonly or preview or direct_voter then
   1.190 +        slot.put(" ")
   1.191 +        ui.tag{
   1.192 +          tag = "input",
   1.193 +          attr = {
   1.194 +            type = "submit",
   1.195 +            class = "voting_done2",
   1.196 +            value = submit_button_text
   1.197 +          }
   1.198 +        }
   1.199 +      end
   1.200      end
   1.201    end
   1.202  }

Impressum / About Us