liquid_feedback_frontend

diff model/event.lua @ 405:2f121e50d15c

Translation of event messages completed
author bsw
date Thu Mar 08 15:09:03 2012 +0100 (2012-03-08)
parents 475465da327b
children b297b85dc569
line diff
     1.1 --- a/model/event.lua	Thu Mar 08 14:36:04 2012 +0100
     1.2 +++ b/model/event.lua	Thu Mar 08 15:09:03 2012 +0100
     1.3 @@ -9,6 +9,34 @@
     1.4    ref           = 'issue',
     1.5  }
     1.6  
     1.7 +function Event.object_get:event_name()
     1.8 +  return ({
     1.9 +    issue_state_changed = _"Issue reached next phase",
    1.10 +    initiative_created_in_new_issue = _"New issue",
    1.11 +    initiative_created_in_existing_issue = _"New initiative in existing issue",
    1.12 +    initiative_revoked = _"Initiative revoked",
    1.13 +    new_draft_created = _"New initiative draft",
    1.14 +    suggestion_created = _"New suggestion"
    1.15 +  })[self.event]
    1.16 +end
    1.17 +  
    1.18 +function Event.object_get:state_name()
    1.19 +  return ({
    1.20 +    admission = _"New",
    1.21 +    discussion = _"Discussion",
    1.22 +    verification = _"Frozen",
    1.23 +    voting = _"Voting",
    1.24 +    canceled_revoked_before_accepted = _"Cancelled (before accepted due to revocation)",
    1.25 +    canceled_issue_not_accepted = _"Cancelled (issue not accepted)",
    1.26 +    canceled_after_revocation_during_discussion = _"Cancelled (during discussion due to revocation)",
    1.27 +    canceled_after_revocation_during_verification = _"Cancelled (during verification due to revocation)",
    1.28 +    calculation = _"Calculation",
    1.29 +    canceled_no_initiative_admitted = _"Cancelled (no initiative admitted)",
    1.30 +    finished_without_winner = _"Finished (without winner)",
    1.31 +    finished_with_winner = "Finished (with winner)"
    1.32 +  })[self.state]
    1.33 +end
    1.34 +  
    1.35  function Event.object:send_notification() 
    1.36  
    1.37    local members_to_notify = Member:new_selector()
    1.38 @@ -21,62 +49,71 @@
    1.39  
    1.40    local url
    1.41  
    1.42 -  local body = ""
    1.43 +  for i, member in ipairs(members_to_notify) do
    1.44 +    local subject
    1.45 +    local body = ""
    1.46 +    
    1.47 +    locale.do_with(
    1.48 +      { lang = member.lang or config.default_lang or 'en' },
    1.49 +      function()
    1.50 +        subject = config.mail_subject_prefix .. _("##{id} #{event}", { id = self.issue_id, event = self.event })
    1.51 +        body = body .. _("[event mail]      Unit: #{name}", { name = self.issue.area.unit.name }) .. "\n"
    1.52 +        body = body .. _("[event mail]      Area: #{name}", { name = self.issue.area.name }) .. "\n"
    1.53 +        body = body .. _("[event mail]     Issue: ##{id}", { id = self.issue_id }) .. "\n\n"
    1.54 +        body = body .. _("[event mail]    Policy: #{policy}", { policy = self.issue.policy.name }) .. "\n\n"
    1.55 +        body = body .. _("[event mail]     Event: #{event}", { event = self.event_name }) .. "\n\n"
    1.56 +        body = body .. _("[event mail]     Phase: #{phase}", { phase = self.state_name }) .. "\n\n"
    1.57 +
    1.58 +        if self.initiative_id then
    1.59 +          url = request.get_absolute_baseurl() .. "initiative/show/" .. self.initiative_id .. ".html"
    1.60 +        elseif self.suggestion_id then
    1.61 +          url = request.get_absolute_baseurl() .. "suggestion/show/" .. self.suggestion_id .. ".html"
    1.62 +        else
    1.63 +          url = request.get_absolute_baseurl() .. "issue/show/" .. self.issue_id .. ".html"
    1.64 +        end
    1.65 +        
    1.66 +        body = body .. _("[event mail]       URL: #{url}", { url = url }) .. "\n\n"
    1.67 +        
    1.68 +        if self.initiative_id then
    1.69 +          local initiative = Initiative:by_id(self.initiative_id)
    1.70 +          body = body .. _("i#{id}: #{name}", { id = initiative.id, name = initiative.name }) .. "\n\n"
    1.71 +        else
    1.72 +          local initiative_count = Initiative:new_selector()
    1.73 +            :add_where{ "initiative.issue_id = ?", self.issue_id }
    1.74 +            :count()
    1.75 +          local initiatives = Initiative:new_selector()
    1.76 +            :add_where{ "initiative.issue_id = ?", self.issue_id }
    1.77 +            :add_order_by("initiative.supporter_count DESC")
    1.78 +            :limit(3)
    1.79 +            :exec()
    1.80 +          for i, initiative in ipairs(initiatives) do
    1.81 +            body = body .. _("i#{id}: #{name}", { id = initiative.id, name = initiative.name }) .. "\n"
    1.82 +          end
    1.83 +          if initiative_count - 3 > 0 then
    1.84 +            body = body .. _("and #{count} more initiatives", { count = initiative_count }) .. "\n"
    1.85 +          end
    1.86 +          body = body .. "\n"
    1.87 +        end
    1.88 +        
    1.89 +        if self.suggestion_id then
    1.90 +          local suggestion = Suggestion:by_id(self.suggestion_id)
    1.91 +          body = body .. _("#{name}\n\n", { name = suggestion.name })
    1.92 +        end
    1.93    
    1.94 -  body = body .. _("[event mail]      Unit: #{name}", { name = self.issue.area.unit.name }) .. "\n"
    1.95 -  body = body .. _("[event mail]      Area: #{name}", { name = self.issue.area.name }) .. "\n"
    1.96 -  body = body .. _("[event mail]     Issue: ##{id}", { id = self.issue_id }) .. "\n"
    1.97 -  body = body .. _("[event mail]    Policy: #{policy}", { phase = self.issue.policy.name }) .. "\n"
    1.98 -  body = body .. _("[event mail]     Phase: #{phase}", { phase = self.state }) .. "\n\n"
    1.99 -  body = body .. _("[event mail]     Event: #{event}", { event = self.event }) .. "\n\n"
   1.100 -
   1.101 -  if self.initiative_id then
   1.102 -    url = request.get_absolute_baseurl() .. "initiative/show/" .. self.initiative_id .. ".html"
   1.103 -  elseif self.suggestion_id then
   1.104 -    url = request.get_absolute_baseurl() .. "suggestion/show/" .. self.suggestion_id .. ".html"
   1.105 -  else
   1.106 -    url = request.get_absolute_baseurl() .. "issue/show/" .. self.issue_id .. ".html"
   1.107 +        local success = net.send_mail{
   1.108 +          envelope_from = config.mail_envelope_from,
   1.109 +          from          = config.mail_from,
   1.110 +          reply_to      = config.mail_reply_to,
   1.111 +          to            = member.notify_email,
   1.112 +          subject       = ,
   1.113 +          content_type  = "text/plain; charset=UTF-8",
   1.114 +          content       = body
   1.115 +        }
   1.116 +    
   1.117 +      end
   1.118 +    )
   1.119    end
   1.120    
   1.121 -  body = body .. _("[event mail]       URL: #{url}", { url = url }) .. "\n\n"
   1.122 -  
   1.123 -  if self.initiative_id then
   1.124 -    local initiative = Initiative:by_id(self.initiative_id)
   1.125 -    body = body .. _("i#{id}: #{name}", { id = initiative.id, name = initiative.name }) .. "\n\n"
   1.126 -  else
   1.127 -    local initiative_count = Initiative:new_selector()
   1.128 -      :add_where{ "initiative.issue_id = ?", self.issue_id }
   1.129 -      :count()
   1.130 -    local initiatives = Initiative:new_selector()
   1.131 -      :add_where{ "initiative.issue_id = ?", self.issue_id }
   1.132 -      :add_order_by("initiative.supporter_count DESC")
   1.133 -      :limit(3)
   1.134 -      :exec()
   1.135 -    for i, initiative in ipairs(initiatives) do
   1.136 -      body = body .. _("i#{id}: #{name}", { id = initiative.id, name = initiative.name }) .. "\n"
   1.137 -    end
   1.138 -    if initiative_count - 3 > 0 then
   1.139 -      body = body .. _("and #{count} more initiatives", { count = initiative_count }) .. "\n"
   1.140 -    end
   1.141 -    body = body .. "\n"
   1.142 -  end
   1.143 -  
   1.144 -  if self.suggestion_id then
   1.145 -    local suggestion = Suggestion:by_id(self.suggestion_id)
   1.146 -    body = body .. _("#{name}\n\n", { name = suggestion.name })
   1.147 -  end
   1.148 -  
   1.149 -  for i, member in ipairs(members_to_notify) do
   1.150 -    local success = net.send_mail{
   1.151 -      envelope_from = config.mail_envelope_from,
   1.152 -      from          = config.mail_from,
   1.153 -      reply_to      = config.mail_reply_to,
   1.154 -      to            = member.notify_email,
   1.155 -      subject       = config.mail_subject_prefix .. _("##{id} #{event}", { id = self.issue_id, event = self.event }),      content_type  = "text/plain; charset=UTF-8",
   1.156 -      content       = body
   1.157 -    }
   1.158 -  end
   1.159 -
   1.160  end
   1.161  
   1.162  function Event:send_next_notification()

Impressum / About Us